Description
This is a mini-traffic light display module, high brightness, very suitable for the production of traffic light system model. It is featured with its small size, simple wiring, targeted, and custom installation. It can be connected PWM to control the brightness of the LED.
Features:
- Small size.
- Simple wiring.
- Targeted.
- Custom installation.
Interfacing LED Traffic Light Module with Arduino
Before you are getting started, prepare all the item needed:
- Arduino UNO
- LED traffic light module
- Jumper wires
- Breadboard
Step 2: Connection Setup
Follow the connection as shown above.
Step 3: Sample Code
#define RED_SET_TIME 5000
#define YELLOW_SET_TIME 2000
#define GREEN_SET_TIME 5000
#define LIGHT_1_RED 2
#define LIGHT_1_YELLOW 3
#define LIGHT_1_GREEN 4
#define GREEN_LIGHT 0
#define YELLOW_LIGHT 1
#define RED_LIGHT 2
unsigned long gulStart_Timer = 0;
unsigned short gusSet_Time[3] = {GREEN_SET_TIME, YELLOW_SET_TIME, RED_SET_TIME};
short gsWhich_Light_Index = GREEN_LIGHT;
void setup()
{
Serial.begin(9600);
pinMode(LIGHT_1_RED, OUTPUT);
pinMode(LIGHT_1_YELLOW, OUTPUT);
pinMode(LIGHT_1_GREEN, OUTPUT);
digitalWrite(LIGHT_1_GREEN, HIGH);
digitalWrite(LIGHT_1_YELLOW, LOW);
digitalWrite(LIGHT_1_RED, LOW);
gulStart_Timer = millis();
}
// the loop function runs over and over again forever
void loop()
{
if((millis()-gulStart_Timer) >= gusSet_Time[gsWhich_Light_Index])
{
gsWhich_Light_Index++;
if(gsWhich_Light_Index > RED_LIGHT)
{
gsWhich_Light_Index = GREEN_LIGHT;
}
gulStart_Timer = millis();
if(gsWhich_Light_Index == GREEN_LIGHT)
{
digitalWrite(LIGHT_1_GREEN, HIGH);
digitalWrite(LIGHT_1_YELLOW, LOW);
digitalWrite(LIGHT_1_RED, LOW);
}
else if(gsWhich_Light_Index == YELLOW_LIGHT)
{
digitalWrite(LIGHT_1_GREEN, LOW);
digitalWrite(LIGHT_1_YELLOW, HIGH);
digitalWrite(LIGHT_1_RED, LOW);
}
else if(gsWhich_Light_Index == RED_LIGHT)
{
digitalWrite(LIGHT_1_GREEN, LOW);
digitalWrite(LIGHT_1_YELLOW, LOW);
digitalWrite(LIGHT_1_RED, HIGH);
}
}
}
Reviews
There are no reviews yet.