[vc_row][vc_column][vc_column_text]In this project, we design a circuit to simulate the traffic light.
[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”Parts List” tab_id=”1396072671685-3-6″][vc_column_text]
- 1 x Red LED
- 1 x Yellow LED
- 1 x Green LED
- 3 x resistor with 220Ω
- 1 x Breadboard
- [bigcommerce link=”/breadboard-jumper-wire-set-140pcs/” target=”_blank”]Jumper wires[/bigcommerce]
[/vc_column_text][/vc_tab][vc_tab title=”Schematics” tab_id=”1394768852-1-64″][vc_column_text]The LEDs are connected to digital pins 10,7, and 4 respectively.
[/vc_column_text][/vc_tab][vc_tab title=”Wiring Diagram” tab_id=”1394768852-2-3″][vc_column_text][/vc_column_text][/vc_tab][vc_tab title=”Arduino Code” tab_id=”1394772356076-2-3″][vc_column_text]To simulate a traffic light, we will turn on and off the LEDs in a predetermined pattern, i.e., red, yellow, and green pattern. We use delay() of Arduino to control the duration.
int redled = 10; / / define the interface number 10 int yellowled = 7; / / define the number 7 Interface int greenled = 4; / / define the number 4 Interface void setup () { pinMode (redled, OUTPUT) ;/ / define a small red light interface output interface pinMode (yellowled, OUTPUT); / / define the yellow light interface output interface pinMode (greenled, OUTPUT); / / define the small green light interface output interface } void loop () { digitalWrite (redled, HIGH) ;/ / lit red lights delay (1000) ;/ / delay of 1 second digitalWrite (redled, LOW); / / off red light digitalWrite (yellowled, HIGH) ;/ / light yellow light delay (200) ;/ / delay of 0.2 seconds digitalWrite (yellowled, LOW) ;/ / off yellow light
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.