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

Arduino UNO Controlled Traffic Light with Pushbutton Activation

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled Traffic Light with Pushbutton Activation

Traffic Light Control Circuit Documentation

Summary

This circuit is designed to control a traffic light system using an Arduino UNO microcontroller and two pushbuttons. The system operates such that when the first pushbutton is pressed, the green light on the traffic light turns on. Pressing the second pushbutton turns the green light off. The circuit is powered by the Arduino UNO, which also provides ground connections to the pushbuttons and the traffic light.

Component List

Arduino UNO

Traffic Light

Pushbutton (x2)

Wiring Details

Arduino UNO

Traffic Light

Pushbutton 1

Pushbutton 2

Documented Code

/*
 * This Arduino sketch controls a traffic light system with two pushbuttons.
 * When the first pushbutton is pressed, the green light turns on.
 * When the second pushbutton is pressed, the green light turns off.
 */

const int button1Pin = 2; // Pin for the first pushbutton
const int button2Pin = 3; // Pin for the second pushbutton
const int greenLightPin = 4; // Pin for the green light

void setup() {
  // Initialize the pushbutton pins as inputs
  pinMode(button1Pin, INPUT);
  pinMode(button2Pin, INPUT);
  // Initialize the green light pin as an output
  pinMode(greenLightPin, OUTPUT);
  // Start with the green light off
  digitalWrite(greenLightPin, LOW);
}

void loop() {
  // Read the state of the first pushbutton
  int button1State = digitalRead(button1Pin);
  // Read the state of the second pushbutton
  int button2State = digitalRead(button2Pin);
  // If the first pushbutton is pressed, turn on the green light
  if (button1State == HIGH) {
    digitalWrite(greenLightPin, HIGH);
  }
  // If the second pushbutton is pressed, turn off the green light
  if (button2State == HIGH) {
    digitalWrite(greenLightPin, LOW);
  }
}

The code is written for the Arduino UNO and is responsible for reading the state of two pushbuttons to control the green light of the traffic light. The setup() function initializes the pins connected to the pushbuttons as inputs and the pin connected to the green light as an output. The loop() function continuously checks the state of the pushbuttons and turns the green light on or off accordingly.