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 Arduino UNO is programmed to control the traffic light sequence, cycling through green, yellow, and red lights with specific timing intervals. The green LED is on for 5 seconds, followed by the yellow LED for 2 seconds, and then the red LED for 5 seconds. This cycle repeats indefinitely.
/*
* This Arduino sketch controls a traffic light system.
* The green LED is on for 5 seconds, followed by the yellow LED for 2 seconds,
* and then the red LED for 5 seconds. This cycle repeats indefinitely.
*/
// Pin definitions
const int redPin = 1;
const int yellowPin = 2;
const int greenPin = 3;
void setup() {
// Initialize the digital pins as outputs
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop() {
// Turn on the green LED
digitalWrite(greenPin, HIGH);
delay(5000); // Wait for 5 seconds
digitalWrite(greenPin, LOW);
// Turn on the yellow LED
digitalWrite(yellowPin, HIGH);
delay(2000); // Wait for 2 seconds
digitalWrite(yellowPin, LOW);
// Turn on the red LED
digitalWrite(redPin, HIGH);
delay(5000); // Wait for 5 seconds
digitalWrite(redPin, LOW);
}
Filename: sketch.ino
Description: The code provided is an Arduino sketch that defines three pins connected to the respective LEDs of the traffic light module. In the setup()
function, these pins are configured as outputs. The loop()
function then controls the state of each LED, turning them on and off in sequence with delays to create the traffic light effect.