Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Traffic Light Control System with Pushbutton Cycling

View and Edit Project In Cirkit DesignerImage of Arduino UNO Traffic Light Control System with Pushbutton Cycling

Traffic Light Control System Documentation

Summary

This document describes a simple traffic light control system implemented using an Arduino UNO microcontroller. The system controls three LEDs (red, yellow, and green) to simulate a traffic light. A pushbutton is used to cycle through the LEDs, changing the active light from red to yellow to green and back to red. The system is designed to be responsive to user input while preventing signal bouncing through debounce delays.

Component List

Arduino UNO

Resistor (200 Ohms)

LED: Two Pin (Red)

LED: Two Pin (Green)

LED: Two Pin (Yellow)

Pushbutton

Wiring Details

Arduino UNO

Resistor (200 Ohms)

LED: Two Pin (Red)

LED: Two Pin (Green)

LED: Two Pin (Yellow)

Pushbutton

Documented Code

/*
 * This Arduino sketch controls a traffic light system with red, yellow, and green LEDs.
 * Each time the button is pressed, the system cycles through the colors in the order:
 * red -> yellow -> green -> red.
 */

const int buttonPin = 5; // Pin connected to the pushbutton
const int redLEDPin = 11; // Pin connected to the red LED
const int yellowLEDPin = 12; // Pin connected to the yellow LED
const int greenLEDPin = 13; // Pin connected to the green LED

int buttonState = 0; // Variable for reading the pushbutton status
int currentLED = 0; // Variable to keep track of the current LED

void setup() {
  pinMode(buttonPin, INPUT); // Initialize the pushbutton pin as an input
  pinMode(redLEDPin, OUTPUT); // Initialize the red LED pin as an output
  pinMode(yellowLEDPin, OUTPUT); // Initialize the yellow LED pin as an output
  pinMode(greenLEDPin, OUTPUT); // Initialize the green LED pin as an output
  digitalWrite(redLEDPin, HIGH); // Start with the red LED on
}

void loop() {
  buttonState = digitalRead(buttonPin); // Read the state of the pushbutton
  if (buttonState == HIGH) { // Check if the button is pressed
    delay(50); // Debounce delay
    while (digitalRead(buttonPin) == HIGH); // Wait for button release
    delay(50); // Debounce delay
    cycleLED(); // Cycle to the next LED
  }
}

void cycleLED() {
  // Turn off all LEDs
  digitalWrite(redLEDPin, LOW);
  digitalWrite(yellowLEDPin, LOW);
  digitalWrite(greenLEDPin, LOW);
  // Cycle through the LEDs
  currentLED = (currentLED + 1) % 3;
  switch (currentLED) {
    case 0:
      digitalWrite(redLEDPin, HIGH); // Turn on the red LED
      break;
    case 1:
      digitalWrite(yellowLEDPin, HIGH); // Turn on the yellow LED
      break;
    case 2:
      digitalWrite(greenLEDPin, HIGH); // Turn on the green LED
      break;
  }
}

This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the pins connected to the LEDs and the pushbutton, and contains a main loop that checks for button presses to cycle through the LEDs. The cycleLED function manages which LED is turned on at any given time.