• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomeArduinoAdvanced Learning Kit for ArduinoProject 4: Traffic Lights
Previous Next

Project 4: Traffic Lights

Posted by: Alvin Jin , March 13, 2014

[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. 1 x Red LED
  2. 1 x Yellow LED
  3. 1 x Green LED
  4. 3 x resistor with 220Ω
  5. 1 x Breadboard
  6. [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.

03[/vc_column_text][/vc_tab][vc_tab title=”Wiring Diagram” tab_id=”1394768852-2-3″][vc_column_text]04[/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]

Tags: Advanced Learning Kit for Arduino

Share!
Tweet

Alvin Jin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors