⌁ ⌁⌁⌁ ⌁⌁ ⌁ ⌁⌁ ⌁⌁⌁ Running LEDs with Arduino ⌁⌁⌁ ⌁⌁⌁ ⌁⌁⌁ ⌁⌁ ⌁ ⌁
In this project we will create an integrated program, to know the traffic , And the changes that cause the three LEDs to glow.
We will choose to study the traffic flow at the traffic intersection.
For this project we will need:
4-LEDs yellow , 4-LEDs red , 4-LEDs green , 12 resistor 220 ohm , 2Breadboard , Arduino UNO , Jumper wires
Control to 6 leds
GND LED red1 ----> PIN 2GND LED yellow1 ----> PIN 3
GND LED green1 ----> PIN 4
GND LED red2 ----> PIN 5
GND LED yellow2 ----> PIN 6
GND LED green2 ----> PIN 7
The cationic electrodes of the LEDs connect to the 3.3Volts . We rely on this electronic layout:
CASE1:
📒 on --->> the red lad 1 and the green lad 2 .
Time taken 1000 ms
digitalWrite(red1, LOW); // LOW ------->>> LED==1 and HIGH ------- >>> LED == 0
digitalWrite(green2, LOW);
delay(1000);
CASE2:
📒 oFF--->> the green lad 2 .
📒 on --->> the yellow lad 2 .
Time taken 500ms
digitalWrite(green2, HIGH);
digitalWrite(yellow2, LOW);
delay(500);
CASE3:
📒 oFF --->> the yellow lad 2 and red lad 1 .
📒 on --->> the red lad 2 and green lad 1 .
Time taken 1000 ms
digitalWrite(yellow2, HIGH);
digitalWrite(red1, HIGH);
digitalWrite(red2, LOW);
digitalWrite(green1, LOW);
delay(1000);
CASE4:
📒 oFF --->> the green lad 1 .
📒 on --->> the yellow lad 1 .
Time taken 500 ms
digitalWrite(green1, HIGH);
digitalWrite(yellow1, LOW);
delay(500);
CASE5:
The program returns to the starting point, so this tag must be added at the starting point for the program to be valid.
digitalWrite(yellow1, HIGH); digitalWrite(red2, HIGH);
📒 on --->> the red lad 1 and the green lad 2 .
📒 oFF --->>the yellow lad 1 and the green lad 2 .
Time taken 1000 ms
digitalWrite(red1, LOW); // LOW ------->>> LED==1 and HIGH ------- >>> LED == 0
digitalWrite(green2, LOW);
digitalWrite(yellow1, HIGH);
digitalWrite(red2, HIGH);
delay(1000);
Full Code:
// Traffic lights with Arduino :
int red1=2; // Determine the pin number for the LED
int yellow1=3;
int green1=4;
int red2=5;
int yellow2=6;
int green2=7;
void setup()
{
pinMode(red1,OUTPUT); // Determine LED as output
pinMode(yellow1,OUTPUT);
pinMode(green1,OUTPUT);
pinMode(red2,OUTPUT);
pinMode(yellow2,OUTPUT);
pinMode(green2,OUTPUT);
}
void loop()
{
digitalWrite(red1, LOW); // LOW ------->>> LED==1 and HIGH ------- >>> LED == 0
digitalWrite(green2, LOW);
digitalWrite(yellow1, HIGH);
digitalWrite(red2, HIGH);
delay(1000);
digitalWrite(green2, HIGH);
digitalWrite(yellow2, LOW);
delay(500);
digitalWrite(yellow2, HIGH);
digitalWrite(red1, HIGH);
digitalWrite(red2, LOW);
digitalWrite(green1, LOW);
delay(1000);
digitalWrite(green1, HIGH);
digitalWrite(yellow1, LOW);
delay(500);
}
Through this simple explanation we have reached the end of our first experience in the field of traffic lights.
We will be based on the same code as before
But remember, you can always modify the code and add something new to the experience.
Here you will find a full section on the experience and a model of this traffic intersection was made.
No comments