Practical - 5
Practical - 5
void setup(){
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
}
void loop(){
digitalWrite(red, HIGH);
delay(15000);
digitalWrite(red, LOW);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(green, HIGH);
delay(20000);
digitalWrite(green, LOW);
//
digitalWrite(yellow, HIGH);
By Harsh Darji
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
delay(500);
}
Output
Ans :-
Materials:
Arduino board (Uno is a good starter choice)
Three LEDs (Red, Yellow, Green)
Resistors (100-220 ohm, will depend on your LEDs)
Breadboard
Jumper wires
Steps:
1. Connect the LEDs:
Each LED has a longer leg (positive) and a shorter leg (negative).
Connect the shorter leg of each LED to the ground (GND) pin on the Arduino.
Important: Use a resistor in series with the longer leg of each LED before
connecting it to an Arduino pin. This protects the LED from damage. Connect the
resistor to the longer leg, then the wire from the resistor to an Arduino pin.
2. Program the Arduino:
You'll need software called Arduino IDE
(https://support.arduino.cc/hc/en-us/articles/360019833020-Download-and-install-
Arduino-IDE) to write the code.
The code will tell the Arduino to turn the LEDs on and off in the specific pattern
of a traffic light.
Many resources online provide beginner-friendly code for this project. Search for
"Arduino traffic light code" and find one that explains each step clearly.
3. Upload the code and run the program:
Connect your Arduino to your computer using a USB cable.
In the Arduino IDE, open the code you downloaded or wrote.
Click the "upload" button to send the code to your Arduino.
If everything is connected correctly, your traffic light should start working!