Product Introduction #
The traffic light module integrates three different colors of red, yellow and green LED, which has four pins, one of which is a public pin, and the other three pins respectively control three different colors of LED work. The common end GND is connected to the GND port of the controller board. Pins R, Y and G are connected to different I/O ports of the controller board respectively. When each pin R, Y and G inputs high voltage, the corresponding color LED will light up.
Application reference: Traffic lights, indicators, etc.
Parameter Specification #
Parameter | Value//Description |
---|---|
Operating voltage | 3.3V~5V |
Operating temperature | -40°C~+70°C |
Output signal | Digital signal |
Size | 4.8cm*2.4cm |
Wiring Diagram #
Note: Expansion board is attached to esp32 controller board.
Traffic Light Module | UNO |
---|---|
G | 0 |
Y | 2 |
R | 14 |
GND | GND |
Sample Code #
#define R 14 //Define the pin for the red light of the traffic light
#define Y 2 //Define the pin for the yellow light of the traffic light
#define G 0 //Define the pin for the green light of the traffic light
void setup() {
pinMode(R, OUTPUT);//Set the red light pin to output mode
pinMode(Y, OUTPUT);//Set the yellow light pin to output mode
pinMode(G, OUTPUT);//Set the green light pin to output mode
}
void loop() {
Traffic_Light(0, 0, 1);//Green light on
delay(2000);//Delay 2 seconds
Traffic_Light(0, 1, 0);//Yellow light on
delay(1000);//Delay 1 second
Traffic_Light(1, 0, 0);//Red light on
delay(3000);//Delay 3second
}
//Define traffic light color control function
void Traffic_Light(int r, int y, int g) {
digitalWrite(R, r);
digitalWrite(Y, y);
digitalWrite(G, g);
}
Note: If you are using an Arduino board, then change the red pin in the program to PIN3, yellow pin in the program to PIN4, green pin in the program to PIN5, and then connect the hardware pin to PIN3, PIN4, PIN5 and upload the program.
Test Result #
When you have successfully connected the circuits according to the wiring diagram and successfully uploaded the correct program, your traffic light will be green for 2 seconds, yellow for 1 second, and red for 3 seconds.
Related Resources #
Get One Now #
B2B Business: info@acebott.com