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

Worksheet Number 1.

• Aim/Overview of the practical:

Interface an Arduino Uno with two pushbuttons to design the different patterns and follow the
different cases. Use 6 different color LEDs and name them T1 to T6 and pull up resistors
of suitable values. Consider delay 200.

When pushbutton 1 is Pressed:

All the LEDs are in ON conditions and then in OFF conditions

When pushbutton 2 is Pressed:

T1, T3 and T5 are in ON conditions and T2, T4 and T6 are in OFF conditions.

• Hardware Required:
• LED Lights
• Resistor
• Arduino UNO3
• Breadboard
• PushButtons

• Theory:
Arduino Uno is a microcontroller board that allows you to build electronics
projects by connecting sensors and other components to it. It is easy to use
and comes with a programming environment that simplifies the process of
writing code. It is used in a variety of applications, including robotics, home
automation, and many other projects.
A breadboard is a prototyping board used to build and test electronic circuits. It
has a grid of holes into which electronic components, such as resistors,
capacitors, and integrated circuits, can be inserted and connected without the
need for soldering. The holes are typically arranged in a series of parallel
rows and columns, allowing for easy circuit design and modification.
Breadboards come in various sizes and can be reused multiple times for
different projects. They are widely used by hobbyists, students, and
professionals for electronics prototyping and testing.
Pull Up and Pull Down
Pull-up and pull-down resistors are used in electronic circuits to ensure that a
digital input pin has a known state when it is not being actively driven by
another device. They are used to eliminate the possibility of the input pin
floating, which can lead to unpredictable behavior and can cause false
triggering of the input.
A pull-up resistor is used to ensure that the input pin is at a known HIGH state
when the switch or button is not pressed. The pull-up resistor is connected
between the input pin and the positive supply voltage (usually +5V). When
the switch or button is pressed, it connects the input pin directly to GND,
overriding the pull-up resistor and pulling the input pin to a LOW state.
A pull-down resistor is used to ensure that the input pin is at a known LOW state
when the switch or button is not pressed. The pull-down resistor is
connected between the input pin and GND. When the switch or button is
pressed, it connects the input pin directly to the positive supply voltage,
overriding the pull-down resistor and pulling the input pin to a HIGH state.

Implementation Steps:
Step-by-step explanation of how to interface an Arduino Uno with two pushbuttons
and six LEDs to follow the different cases you mentioned:

• Gather the materials: You'll need an Arduino Uno board, two pushbuttons,
six LEDs of different colors, six 220 ohm resistors, two pull-up resistors
with a value of 10k ohms, a breadboard, and some jumper wires.
• Connect the pushbuttons: Connect one end of each pushbutton to GND, and
the other end of each pushbutton to a digital pin on the Arduino board.
Connect a 10k ohm pull-up resistor between each digital pin and +5V.
• Connect the LEDs: Connect the anode (positive) leg of each LED to a digital
pin on the Arduino board, through a 220 ohm resistor. Connect the cathode
(negative) leg of each LED to GND.
• Write the code: Use the Arduino IDE to write a program that reads the state
of each pushbutton and controls the state of each LED accordingly. Use the
following logic:
• When pushbutton 1 is pressed, turn on all six LEDs, then turn off all
six LEDs.
• When pushbutton 2 is pressed, turn off LEDs T2, T4, and T6.
• Upload the code: Connect the Arduino board to your computer, select the
correct board and serial port in the Arduino IDE, and upload the code to the
board.
• Test the circuit: Press pushbutton 1 to turn on all six LEDs and press the 2nd
button to turn off the alternate LED’s.

• Arduino Code:

int t1 = 8,t2=9,t3=10,t4=11,t5=12,t6=13; // LED PINS


int b1State = 0; //FIRST PUSH BUTTON STATE
int b2State = 0; //SECOND PUSH BUTTON STATE
void setup()
{
// Set the LED pins to output mode
pinMode(t1, OUTPUT);
pinMode(t2, OUTPUT);
pinMode(t3, OUTPUT);
pinMode(t4, OUTPUT);
pinMode(t5, OUTPUT);
pinMode(t6, OUTPUT);
pinMode(2, INPUT);
pinMode(3, INPUT);
Serial.begin(9600);
}
void loop()
{
b1State = digitalRead(2);
b2State = digitalRead(3);
// Check the state of pushbutton 1
Serial.println("--");
if(b1State == 1){
// Turn on all six LEDs
digitalWrite(t1,HIGH);
digitalWrite(t2,HIGH);
digitalWrite(t3,HIGH);
digitalWrite(t4,HIGH);
digitalWrite(t5,HIGH);
digitalWrite(t6,HIGH);
}else{
// Turn off all six LEDs
digitalWrite(t1,LOW);
digitalWrite(t2,LOW);
digitalWrite(t3,LOW);
digitalWrite(t4,LOW);
digitalWrite(t5,LOW);
digitalWrite(t6,LOW);
// Wait for 200 milliseconds
delay(200);
}
// Check if button 2 is Pressed
if(b2State == 0){
// Turn off LEDs T2, T4, and T6
digitalWrite(t2,LOW);
digitalWrite(t4,LOW);
digitalWrite(t6,LOW);
// Wait for 200 milliseconds
delay(200);
}
}

• Output (Screenshots from TinkerCad):


Output of the Circuit

Gif Format from TinkerCad :


When button 1 is pressed , all led goes off, and starts again after 200ms,
When the 2nd button is pressed, LED 2,3,5 goes off and starts again after 200ms.

• Learning outcomes (What I have learnt):


1. Basic Learning and Implementation Tinker Cad
2. Functioning of Arduino Uno
3.Usage of Breadboard, LED and Resistors
4.Adding Push button to the board and connect to LED.
5. Coading and Creating a Blinking LED

You might also like