list of products from Amazon (Not mine, i just link them!) Scroll Down For Article! Note: Elegoo boards are not Arduino, but they are compatible with Arduino IDE and are mutch more affordable!
This project implements a traffic light system with a countdown timer, designed using an Arduino microcontroller. It controls a sequence of traffic lights (red, yellow, and green) and a 7-segment display counter. Here’s a detailed description:
Features:
Traffic Light Phases:
- Red Light Phase: The red light is active for 9 seconds, during which a countdown is displayed on a 7-segment display.
- Yellow Light Phase: The yellow light blinks for 2 seconds before switching to green.
- Green Light Phase: The green light is active for 9 seconds, with the countdown displayed.
Countdown Display:
- A 7-segment display shows the countdown from 9 to 0 during the red and green light phases. This is achieved using a 4511 IC, with the display driven by 4 output pins.
Components:
- Traffic Light LEDs:
- Red, yellow, and green LEDs are connected to digital pins
11
,12
, and13
respectively. - Controlled using
digitalWrite
to turn them on or off.
- Red, yellow, and green LEDs are connected to digital pins
- 7-Segment Display:
- Driven by a 4511 IC, connected to pins
4
,5
,6
, and7
. - Displays the countdown timer during the active phases of red and green lights.
- Driven by a 4511 IC, connected to pins
Workflow:
Setup Phase:
- Configures the pins for the LEDs and the 7-segment display.
- Initializes the system with the red light on and the counter set to 9.
Loop Phase:
- Executes the traffic light phases in sequence:
- Red Light Phase: Lights the red LED and counts down from 9 to 0.
- Yellow Light Phase: Blinks the yellow LED for 2 seconds.
- Green Light Phase: Lights the green LED and counts down from 9 to 0.
- Repeats the cycle continuously.
Code Highlights:
- Pin Definitions: Predefined constants improve code readability by labeling the pin numbers.
- Modular Functions:
updateCounter(int value)
: Updates the display based on the counter value.countdown(int startValue)
: Handles the countdown logic with a 1-second delay for each decrement.
- Timing Control: Uses
delay()
for time intervals, providing precise timing for LED and countdown changes.
Applications:
This project can be used as:
- A simulation of a basic traffic light system for educational purposes.
- A starting point for more complex traffic management systems.
0 Comments