Traffic Light Intersection
In this project, I am going to explain how to mimic a traffic light intersection with an Arduino on Tinkercad.
Function of the Circuit
*This step is optional as it is just to understand the circuit better*
When the simulation begins in Tinkercad, a timer will turn the three LEDs on and off (it will start with the red LED on for 9 seconds then the yellow for 3 seconds and then the green for 9 seconds and will go on a continuous loop). To add a more realistic touch to it, the 7 segment display will represent the timer on intersections, counting down how many seconds before the red light turns on again. When the countdown approaches zero, the yellow LED will turn on, followed by the red LED. The pushbutton will function as the button we press to make a green light come faster. When the pushbutton is pressed on a red light, the green LED and buzzer both activate (the buzzer will buzz every time the green light comes on). Furthermore, depending on the timing, the RGB LED will become green or red: green on green lights, and red on red lights (It will be an LED version of the walk and stop sign above the timers on real-life intersections). Finally, the PIR sensor will be utilized to detect a "vehicle". The green LED will turn on when motion is detected at a red light.
Understanding Components:
LEDs: Anode (power/positive) and cathode (ground/negative) are the two sides of an LED. In this circuit, the anode is connected to the Arduino. A 330 Ω resistor is connected to the cathode of the LED. If there is no resistor, the LED would burn out.
Common Cathode RGB LED: There are three colours shown on this LED: red, green, and blue. The "common" pin needs a resistor to be connected with a resistor, just like a regular LED. Usually, PWM pins are connected to the other three legs, but in this circuit we are syncing this LED to the red and green LEDs (shown later on), therefore it is not needed. Just to know: On the Arduino, a PWM pin has ~ in front of it. PWM (Pulse Width Modulation) is a method to control power. It is also used to adjust the brightness of LEDs (which we are not doing) and to replicate an analog or changing signal.
7 Segment Display: This display is just seven LEDs lined up in a specific pattern to show numerical digits depending on which segment is illuminated.
Pushbutton: When a pushbutton is pressed, a small metal spring within contacts two wires, letting electricity to flow. When the switch is not pressed, the spring goes back, contact is disrupted, and current cannot flow through it.
Piezo: When a voltage is applied to a piezo, it vibrates and produces a tone. Piezos can be used to detect as well as play tones.
PIR (passive infrared sensor) Sensor: The motion (PIR) sensor detects motion using infrared sensors, allowing it to turn on. The motion is detected when the light turns on.
Gather Materials
- Arduino Uno (1)
- 3 LEDs
- CC RGB LED (1)
- Pushbutton (1)
- 7 resistors
- 7 Segment Display (1)
- PIR Sensor (1)
- Piezo (1)
- Wires (24: 4 black, 4 red, 16 any other colour)
- Breadboard (1)
*Links to the products have been attached (as of June 22nd 2021). Prices and availability might change.*
Connecting the Components - LEDs
Start connecting the components by connecting the ground (GND) and five volt (5V) pin from the Arduino onto the negative and positive rails on the breadboard, as shown in the image above. Then connect the two rails to give both sets of rails power and ground. Next, grab the three LEDs (Red, Yellow & Green) and three 330 Ω resistors. Connect the anode of the red LED to pin 13, yellow LED to pin 12 and green LED to pin 11 on the Arduino. Then connect each resistor from the cathode of each LED to the negative rail of the breadboard. This will allow the LED to turn on and off. Take the RGB LED and another 330 Ω resistor. Connect the RGB LED to the breadboard and connect the red pin to pin 13 and green pin to pin 11 on the Arduino. The red and green LEDs need to be in sync with the red and green colour on the RGB LED, which is why they are connected on the same pins. The 330 Ω resistor should be connected from the cathode of the RGB LED to the negative rail of the breadboard.
Connecting the Components - 7 Segment Display & Pushbutton
First connect the 7 segment display. Refer to the image on the right for letters on the display. Connect pin G to pin 10, pin F to pin 9, pin A to pin 8, pin B to pin 7, pin C to pin 6, pin D to pin 5 and pin E to pin 4. Ignore the decimal point (DP) pin as we are not using it in this project. Grab the two 560 Ω resistors and connect them from each side of the "common" pin to the positive rail of the breadboard.
Place the pushbutton onto the breadboard. Connect Terminal 2a to pin 3 on the Arduino. Then take the 10 kΩ resistor and connect it from Terminal 2a to the negative rail on the breadboard. To finish the connection, connect Terminal 1a to the power rail on the breadboard.
Connecting the Components - Piezo & PIR Sensor
Place the Piezo on the breadboard. Connect the negative pin to the negative rail on the breadboard. Connect the positive pin to pin 11 on the Arduino as it is going to be in sync with the green LED (It will buzz every time the green LED turns on).
Place the PIR sensor on the breadboard. Connect the ground pin to the negative rail and the power pin to the positive rail on the breadboard. Connect the signal pin to pin 2 on the Arduino.
Code
Copy the code below into the "code" section on Tinkercad. Read the comments to understand what each line means.
Downloads
Final Product
The video above shows how the project should work. The image below that is the intractable Tinkercad circuit. Turn your volume up to hear the buzzer.
I hope this helped you mimic a traffic light intersection on Tinkercad! You can always modify the code and add/take away components as you wish. You can also try to create this on real-life components as well. Have fun building!