Traffic Light ,9 Led Using Arduino Uno by oadil in arduino
Introduction: Traffic Light ,9 Led Using Arduino Uno
Materials required:
1. 3 red led, 3 yellow led, 3 green led
2. Breadboard
3. Arduino UNO
4. Cable
5. Arduino IDE on PC
6. Connecting wires
Summary of project:
This project is making a simple traffic light but helps in understanding Arduino basics. Basically there are 3 traffic lights with 9 leds that light up according to turn. In this project you will learn:
Using digital output pins
Using the Arduino IDE
Uploading code on the Arduino
and most important of all make a project yourself
Step 1: Step 2 :Make Connections
Connect the red, yelow, green,red, yelow, green, red, yelow, green leds to pins 2,3,4,5,6,7,8,9,10 of Arduino respectively . (connect longer ends of the led)
Connect the shorter side of the led to ground and the longer side to the output pins and then connect it to the GND pin on the Arduino
Connect the Arduino to the PC and download the software if not present already (from www.ardunio.cc)
Open the arduino programmer go to tools> board and select "Arduino Uno"
Next go to tools> serial port and select appropriate port to which Arduino is connected
Next click file>new and paste the code below
//CODE BY OMAR ADIL
int led2 = 2;
int led3 = 3;
int del=1000;
int led4 = 4;
int led5 = 5;
int led6 = 6;
int led7 = 7;
int led8 = 8;
int led9 = 9;
int led10 =10;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
pinMode(led8, OUTPUT);
pinMode(led9, OUTPUT);
pinMode(led10, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
delay(del/2);
//ALL RED
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
delay(2*del);
//GREEN1
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
delay(del);
//YELLOW1
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
delay(del/2);
//ALL RED
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, HIGH);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
delay(del*2);
//GREEN2
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
delay(del);
//YELLOW2
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
delay(del/2);
//ALL RED
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, HIGH);
delay(del*2);
//GREEN 3
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
delay(del);
//YELLOW3
0 Comments