Thursday, June 17, 2021

Project 2: Arduino Traffic Light

 Project 2: Arduino Traffic Light

Main Ideas:

Introduction to the electronic parts (LED & Resistor), introduction to the basic concepts of electrical/electronic i.e. Voltage/Current and analog vs digital.  Introduction Arduino Uno microcontroller board and Arduino IDE (programming application).

Project Description

Make simple Traffic light signal. Turns on the Green LED on for three seconds, then Turn on the Yellow LED for one second and then Turn on Red LED for two seconds repeatedly



Circuit

  • RED LED
  • Yellow LED
  • Green LED
  • 3* 1K Resistor
  • Arduino UNO


int led_green = 11; // the red LED is connected to Pin 11 of the Arduino
int led_yellow = 12; // the yellow LED is connected to Pin 12 of the Arduino
int led_red = 13; // the green LED is connected to Pin 13 of the Arduino

void setup() {
  // set up all the LEDs as OUTPUT
  pinMode(led_red, OUTPUT);
  pinMode(led_yellow, OUTPUT);
  pinMode(led_green, OUTPUT);
}

void loop() {
  // turn the green LED on and the other LEDs off
  digitalWrite(led_red, LOW); 
  digitalWrite(led_yellow, LOW);
  digitalWrite(led_green, HIGH );
  delay(3000);    // wait 2 seconds
  
  // turn the yellow LED on and the other LEDs off
  digitalWrite(led_red, LOW);   
  digitalWrite(led_yellow, HIGH);
  digitalWrite(led_green, LOW);
  delay(1000);   // wait 0.5 second
  
  // turn the red LED on and the other LEDs off
  digitalWrite(led_red, HIGH);  
  digitalWrite(led_yellow, LOW);
  digitalWrite(led_green, LOW);
  delay(2000);  // wait 2 seconds        
}


No comments:

Post a Comment