🚀 Hurry! Offer Ends In
00 Days
00 Hours
00 Mins
00 Secs
Enroll Now
X
Questions
























Write a program for Pedestrian Crossing System comprising 4 LED that is Red, Yellow, Green and Blue LED, 5 Resistors and push button interfaced with Arduino Uno. The Blue LED will represent the pedestrian light, while the Red, Yellow, and Green LEDs will represent the traffic light.

Last Updated : 16 Jul 2025

Solution:

const int redled = 2;       // RED LED = pin 2
const int yellowled = 3;    // YELLOW LED = pin 3
const int greenled = 4;     // GREEN LED = pin 4
const int blueled = 5;      // BLUE LED = pin 5
const int btnpin = 6;       // Button = pin 6
int buttonstate = 0;        // Current button state
int lastbtnstate = 0;      // Previous button state

void setup(){
    pinMode(redled, OUTPUT);       // Set RED LED pin as output
    pinMode(yellowled, OUTPUT);    // Set YELLOW LED pin as output
    pinMode(greenled, OUTPUT);     // Set GREEN LED pin as output
    pinMode(blueled, OUTPUT);      // Set BLUE LED pin as output
    pinMode(btnpin, INPUT_PULLUP); // Set button pin with internal pull-up resistor
}

void loop(){
    buttonstate = digitalRead(btnpin);  // Read the button state
    // Check for button press (button state changes from HIGH to LOW)
    if (buttonstate == LOW && lastbtnstate == HIGH){
        // Sequence of LED actions
        digitalWrite(greenled, LOW);     // Turn off GREEN LED
        digitalWrite(yellowled, HIGH);   // Turn on YELLOW LED
        delay(2000);                     // Wait for 2 seconds
        digitalWrite(yellowled, LOW);    // Turn off YELLOW LED
        digitalWrite(redled, HIGH);      // Turn on RED LED
        delay(2000);                     // Wait for 2 seconds
        digitalWrite(blueled, HIGH);     // Turn on BLUE LED
        delay(5000);   
}
Report an error

Meanwhile you can watch this video

Watch Video
Latest Updates