This document describes a simple traffic light control system using an Arduino UNO microcontroller and a traffic light module with three LEDs (Green, Yellow, and Red). The system operates by cycling through the LEDs in a typical traffic light sequence: green light for 5 seconds, yellow light for 2 seconds, and red light for 5 seconds. This sequence repeats indefinitely to simulate a traffic light operation.
/*
* This Arduino sketch controls a traffic light system.
* The traffic light has three LEDs: Green, Yellow, and Red.
* The sequence is as follows:
* - Green LED is on for 5 seconds
* - Yellow LED is on for 2 seconds
* - Red LED is on for 5 seconds
* This sequence repeats indefinitely.
*/
// Pin definitions
const int redPin = 1; // Red LED connected to pin D1
const int yellowPin = 2; // Yellow LED connected to pin D2
const int greenPin = 3; // Green LED connected to pin D3
void setup() {
// Initialize the digital pins as outputs
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop() {
// Green LED on for 5 seconds
digitalWrite(greenPin, HIGH);
delay(5000);
digitalWrite(greenPin, LOW);
// Yellow LED on for 2 seconds
digitalWrite(yellowPin, HIGH);
delay(2000);
digitalWrite(yellowPin, LOW);
// Red LED on for 5 seconds
digitalWrite(redPin, HIGH);
delay(5000);
digitalWrite(redPin, LOW);
}
Filename: sketch.ino
Description: The code defines three pins corresponding to the red, yellow, and green LEDs of the traffic light. In the setup()
function, these pins are configured as outputs. The loop()
function then controls the LEDs in the specified sequence, turning each on and off for the designated duration.