In this tutorial, we will integrate Surilli WiFi with 3 LEDs 5mm (RED, GREEN & YELLOW) to replicate a traffic light. It uses code as an internal timer and continues to run until you cut Surilli WiFi supply.
Required Hardware- Surilli WiFi
- Breadboard
- Connecting wires
- Red, yellow, and green LED lights (5mm)
- Arduino IDE software
- RED LED (+ PIN) (Anode) ---> SURILLI WiFi(PIN 14)
- RED LED (- PIN) (Cathode) ---> SURILLI WiFi(PIN GND)
- GREEN LED (+ PIN) (Anode) ---> SURILLI WiFi(PIN 12)
- GREEN LED (- PIN) (Cathode) ---> SURILLI WiFi(PIN GND)
- YELLOW LED (+ PIN) (Anode) ---> SURILLI WiFi(PIN 15)
- YELLOW LED (- PIN) (Cathode) ---> SURILLI WiFi(PIN GND)
Insert one side of the jumper wire into the GND side on the board. Lead the other side to the breadboard. Put it on the far right column on the breadboard, at the top. This is the ground column. ALL the way to the right.
STEP 2: Adding the LEDsTake out your LEDs. Our LEDs will go on the same row. We will stick one end of the LED on one side of the breadboard, and the other end on the other side of the breadboard. The shorter (cathode) end of the LEDs will be connected to the GND side of the breadboard whereas the other (anode) end of the LEDs will be connected to the 12, 14 and 15 digital pins as are specified on your Surilli WiFi.
Note: If you don't put the LEDs in correctly, the project will not work.
STEP 3: Set Up Arduino IDE for SurilliMake sure you have selected the right port, board and processor for the Surilli as shown in the picture below and it is programmable (compile and upload “Blink” from File>Examples>Digital>Blink onto your Surilli to check if everything is working fine).
STEP 4: The CircuitryThe circuitry is very simple. Follow the figure below to set up your hardware.
Now you have completed setting up your hardware and Arduino IDE. Copy and paste the Arduino sketch given below into your Arduino IDE and hit upload.
After the Arduino Code has been uploaded, you can visualize the actual Traffic Light Simulation. First the RED LED will turn ON with both the GREEN and YELLOW LEDs turned OFF, then after a delay of 2 seconds, the YELLOW LED will turn ON with both the RED and GREEN LEDs turned OFF. At last, the GREEN LED will turn ON with both the RED and YELLOW LEDs turned OFF. The same action will be performed again and again.
Arduino Code// Variables
int GREEN = 12;
int YELLOW = 15;
int RED = 14;
int DELAY_GREEN = 2000;
int DELAY_YELLOW = 2000;
int DELAY_RED = 1000;
// Basic functions
void setup()
{
pinMode(GREEN, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(RED, OUTPUT);
}
void loop()
{
red_light();
delay(DELAY_RED);
yellow_light();
delay(DELAY_YELLOW);
green_light();
delay(DELAY_GREEN);
}
void red_light()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, HIGH);
}
void yellow_light()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);
digitalWrite(RED, LOW);
}
void green_light()
{
digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
}
Live Video DemonstrationFollow the link below to see the live video demonstration of the project:
Play with the program to see how it reacts to different values and logic.
If you make something fun and interesting do share it with our community.
That’s all for now. If you have any queries, visit surilli.io or contact our support. Stay connected with Surilli family for more amazing stuff. :-)
Comments
Please log in or sign up to comment.