A Traffic Light module is an electronic component that simulates a standard traffic light system. It is commonly used in educational settings to teach basic electronics and programming, as well as in hobbyist projects to control traffic in model setups. The module typically consists of three LEDs (Red, Yellow, and Green) that can be individually controlled to replicate the operation of real-world traffic signals.
Pin Number | Description | Notes |
---|---|---|
1 | Red LED Anode | Connect to digital output pin |
2 | Yellow LED Anode | Connect to digital output pin |
3 | Green LED Anode | Connect to digital output pin |
4 | Common Cathode | Connect to GND |
// Define the pin numbers for the LEDs
const int redLED = 10;
const int yellowLED = 9;
const int greenLED = 8;
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);
// Yellow light for 2 seconds (transition)
digitalWrite(yellowLED, HIGH);
delay(2000);
digitalWrite(yellowLED, LOW);
// Green light for 5 seconds
digitalWrite(greenLED, HIGH);
delay(5000);
digitalWrite(greenLED, LOW);
// Yellow light for 2 seconds (transition)
digitalWrite(yellowLED, HIGH);
delay(2000);
digitalWrite(yellowLED, LOW);
}
Q: Can I use a different voltage supply for the LEDs? A: Yes, but ensure that you adjust the current-limiting resistor values accordingly to prevent damage to the LEDs.
Q: How can I make the transition between lights smoother? A: Implement a PWM fading effect in your code to gradually change the brightness of the LEDs during transitions.
Q: Is it possible to control the Traffic Light module with a remote control? A: Yes, you can use an infrared receiver or a wireless module in conjunction with a microcontroller to receive remote commands and control the Traffic Light module.