Selfedp 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Name – Suhani Garg

Roll no – 102495021
Group - 2O12
ASSIGNMENT – 1
INPUT / OUTPUT INTERFACE DESIGN

Exercise 1 (A)
Using Tinker cad, hook up 5 LEDs to pins 2 through 6 (with resistors). Modify the code to
turn on each one in order and then extinguish them in order.

Hardware/Software Required
• Arduino Uno
• Breadboard
• LED and Resistors
• TinkerCad
• Jumper Wires

Circuit description
This circuit involves an Arduino controlling five LEDs connected to digital pins 2 through 6,
with an additional LED on pin 13 for signaling. Each LED is connected via a 220-ohm resistor
to limit current. In the `setup () ` function, all pins are set as OUTPUT. The `loop () ` function
turns on each LED (pins 2 to 6) one at a time, with a 400-millisecond delay for each. After
turning on each LED, pin 13 is also turned on for 400 milliseconds, then turned off before the
next LED is activated. This sequence ensures that pin 13 blinks on and off in sync with each
LED's activation and deactivation, creating a sequential lighting effect with a delay between each
action.
Code
int delaySpeed = 0;

void setup()
{
pinMode(2, OUTPUT);
pinMode(13, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
}

void loop()
{
delaySpeed = 400;
digitalWrite(2, HIGH);
delay(delaySpeed); // Wait for delaySpeed millisecond(s)
digitalWrite(2, LOW);
digitalWrite(13, HIGH);
delay(delaySpeed); // Wait for delaySpeed millisecond(s)
digitalWrite(13, LOW);
digitalWrite(3, HIGH);
delay(delaySpeed); // Wait for delaySpeed millisecond(s)
digitalWrite(3, LOW);
digitalWrite(13, HIGH);
delay(delaySpeed); // Wait for delaySpeed millisecond(s)
digitalWrite(13, LOW);
digitalWrite(4, HIGH);
delay(delaySpeed); // Wait for delaySpeed millisecond(s)
digitalWrite(4, LOW);
digitalWrite(13, HIGH);
delay(delaySpeed); // Wait for delaySpeed millisecond(s)
digitalWrite(13, LOW);
digitalWrite(5, HIGH);
delay(delaySpeed); // Wait for delaySpeed millisecond(s)
digitalWrite(5, LOW);
digitalWrite(13, HIGH);
delay(delaySpeed); // Wait for delaySpeed millisecond(s)
digitalWrite(13, LOW);
digitalWrite(6, HIGH);
delay(delaySpeed); // Wait for delaySpeed millisecond(s)
digitalWrite(6, LOW);
digitalWrite(13, HIGH);
delay(delaySpeed); // Wait for delaySpeed millisecond(s)
digitalWrite(13, LOW);
delaySpeed;
}

Schematic
Reflections (Conclusions):
Sequential Control: The code effectively demonstrates how to turn LEDs on and off in
sequence, highlighting basic control and timing concepts.
Visual Feedback: LEDs provide clear, immediate feedback on circuit and code functionality,
aiding in debugging.
Code Efficiency: Repetitive “digitalWrite” and “delay” calls can be improved using loops for
better readability and maintenance.
Circuit Design: Reinforces the importance of using resistors and proper connections to ensure
reliable LED operation.
Arduino Programming: Teaches control of digital outputs and timing, providing foundational
programming skills.
Exercise 1 (B)
With the help of Tinkercad, use push buttons to simulate the behavior of listed logic
gates (Without using ICs of logic gates)
Logic gates: AND, NAND, XOR

Hardware/Software Required
• Arduino Uno
• Breadboard
• LED and Resistors
• TinkerCad
• Jumper Wires

Circuit description
To simulate the behavior of AND, NAND, and XOR logic gates using push buttons and an
Arduino, start by setting up a breadboard with two push buttons and an LED for each gate. For
each logic gate simulation, connect the push buttons: one terminal of each button goes to a
designated Arduino digital input pin (such as pins 4 and 12), and the other terminal connects to
ground. Incorporate 10kΩ pull-down resistors between the Arduino input pins and ground to
ensure stable input readings. For the LED, connect the anode (long leg) to a separate Arduino
digital output pin (like pin 13) and the cathode (short leg) to ground through a 220Ω resistor to
limit current. In the Arduino code, implement the logic for each gate: for the AND gate, the LED
lights up only if both buttons are pressed; for the NAND gate, the LED is off only when both
buttons are pressed; and for the XOR gate, the LED is on when exactly one button is pressed.
This setup allows you to visually observe the logical operations through the LED's behavior in
response to different button combinations.

Code
(A) AND
void setup()
{
pinMode(4, INPUT);
pinMode(12, INPUT);
pinMode(13, OUTPUT);
}
void loop()
{
if (digitalRead(4) == HIGH && digitalRead(12) == HIGH)
{ digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}
(B) NAND
void setup()
{
pinMode(4, INPUT);
pinMode(12, INPUT);
pinMode(13, OUTPUT);
}

void loop()
{
if (digitalRead(4) == HIGH && digitalRead(12) == HIGH)
{ digitalWrite(13, LOW);
} else {
digitalWrite(13, HIGH);
}
delay(10); // Delay a little bit to improve simulation performance
}
(C) XOR
void setup()
{
pinMode(4, INPUT);
pinMode(12, INPUT);
pinMode(13, OUTPUT);
}

void loop()
{
if (digitalRead(4) == LOW && digitalRead(12) == HIGH || digitalRead(4) == HIGH &&
digitalRead(12) == LOW) {
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}

Schematic
Reflections (Conclusions):
 Gained practical understanding of how different logic gates (AND, NAND, XOR)
function and their real-world applications.
 Hands-on experience with Arduino and breadboard setup enhanced comprehension
of input reading and output control.
 Successfully simulated AND, NAND, and XOR gates, demonstrating how logic
gate principles are applied in digital circuits.
 Improved problem-solving skills in configuring hardware and coding for accurate
gate behavior.
 Validated theoretical logic gate operations through practical implementation,
reinforcing the connection between abstract concepts and physical electronics.

You might also like