A traffic light module is an electronic component that simulates the operation of standard traffic lights. It typically consists of a set of LEDs (red, yellow, and green) that can be controlled to replicate the sequence of a traffic signal. This module is commonly used in educational settings to teach the basics of electronic circuit design and control logic, as well as in hobbyist projects for creating traffic light systems for model roadways.
Pin Number | Description | Notes |
---|---|---|
1 | Red LED control | Active HIGH or LOW depending on module design |
2 | Yellow LED control | Active HIGH or LOW depending on module design |
3 | Green LED control | Active HIGH or LOW depending on module design |
4 | Ground (GND) | Common ground for all LEDs |
5 | VCC | Supply voltage for the module |
// Define the control pins for the traffic light LEDs
const int redLED = 2;
const int yellowLED = 3;
const int greenLED = 4;
void setup() {
// Set the LED pins as outputs
pinMode(redLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(greenLED, OUTPUT);
}
void loop() {
// Red light for 5 seconds
digitalWrite(redLED, HIGH);
delay(5000);
digitalWrite(redLED, LOW);
// Green light for 5 seconds
digitalWrite(greenLED, HIGH);
delay(5000);
digitalWrite(greenLED, LOW);
// Yellow light for 2 seconds
digitalWrite(yellowLED, HIGH);
delay(2000);
digitalWrite(yellowLED, LOW);
// Repeat the cycle
}
Q: Can I use a different voltage supply for the traffic light module? A: It is essential to use a voltage supply that matches the module's specifications to prevent damage to the LEDs.
Q: How can I make the traffic light sequence more realistic? A: Implement a state machine in your microcontroller code to more accurately represent the timing and sequence of a real traffic light.
Q: Can I control the brightness of the LEDs? A: Yes, you can use PWM on the control pins to adjust the brightness of the LEDs.