Car Volume Based Traffic Light System using IR sensor (Arduino)
can someone give me advice about the code for this project
this is my sample code
int r1 = 1;// pin for the LED
int g1 = 2;
int r2 = 4;
int g2 = 5;
int r3 = 7;
int g3 = 8;
int r4 = 10;
int g4 = 11;
int y0 = 13;// all yellow LED are connected in parallel
int timer = 7000;// set initial timer for the system after first boot
int isObstaclePinA = 3;// pin for the IR sensor
int isObstaclePinB = 6;
int isObstaclePinC = 9;
int isObstaclePinD = 12;
int var = 0;
void setup () {
pinMode(r1, OUTPUT);
pinMode(g1, OUTPUT);
pinMode(r2, OUTPUT);
pinMode(g2, OUTPUT);
pinMode(r3, OUTPUT);
pinMode(g3, OUTPUT);
pinMode(r4, OUTPUT);
pinMode(g4, OUTPUT);
pinMode(y0, OUTPUT);
pinMode(isObstaclePinA, INPUT);
pinMode(isObstaclePinB, INPUT);
pinMode(isObstaclePinC, INPUT);
pinMode(isObstaclePinD, INPUT);
}
void loop () {
switch (var) { // for enabling the switch command
case 1:
if (isObstaclePinA == HIGH);
digitalWrite(isObstaclePinB, LOW);
digitalWrite(isObstaclePinC, LOW);
digitalWrite(isObstaclePinD, LOW);
digitalWrite(g1, HIGH);// LED lights on
digitalWrite(r1, LOW);
digitalWrite(r2, HIGH);
digitalWrite(r3, HIGH);
digitalWrite(r4, HIGH);
delay(timer); // time the lights will turn on
digitalWrite(y0, HIGH);
delay(3000); // time the yellow LED will light
for (isObstaclePinA == HIGH; timer < 50000; timer + 5000); // for adding seconds in the timer every time the sensor responds
break;
case 2: // next case
if (isObstaclePinB == HIGH);
digitalWrite(isObstaclePinA, LOW);
digitalWrite(isObstaclePinC, LOW);
digitalWrite(isObstaclePinD, LOW);
digitalWrite(g2, HIGH);
digitalWrite(r2, LOW);
digitalWrite(r1, HIGH);
digitalWrite(r3, HIGH);
digitalWrite(r4, HIGH);
delay(timer);
digitalWrite(y0, HIGH);
delay(3000);
for (isObstaclePinB == HIGH; timer < 50000; timer + 5000);
break;
case 3:
if (isObstaclePinC == HIGH);
digitalWrite(isObstaclePinB, LOW);
digitalWrite(isObstaclePinA, LOW);
digitalWrite(isObstaclePinD, LOW);
digitalWrite(g3, HIGH);
digitalWrite(r3, LOW);
digitalWrite(r1, HIGH);
digitalWrite(r2, HIGH);
digitalWrite(r4, HIGH);
delay(timer);
digitalWrite(y0, HIGH);
delay(3000);
for (isObstaclePinC == HIGH; timer < 50000; timer + 5000);
break;
case 4:
if (isObstaclePinD == HIGH);
digitalWrite(isObstaclePinB, LOW);
digitalWrite(isObstaclePinC, LOW);
digitalWrite(isObstaclePinA, LOW);
digitalWrite(g4, HIGH);
digitalWrite(r4, LOW);
digitalWrite(r1, HIGH);
digitalWrite(r2, HIGH);
digitalWrite(r3, HIGH);
delay(timer);
digitalWrite(y0, HIGH);
delay(3000);
for (isObstaclePinD == HIGH; timer < 50000; timer + 5000);
break;
this is my sample code
int r1 = 1;// pin for the LED
int g1 = 2;
int r2 = 4;
int g2 = 5;
int r3 = 7;
int g3 = 8;
int r4 = 10;
int g4 = 11;
int y0 = 13;// all yellow LED are connected in parallel
int timer = 7000;// set initial timer for the system after first boot
int isObstaclePinA = 3;// pin for the IR sensor
int isObstaclePinB = 6;
int isObstaclePinC = 9;
int isObstaclePinD = 12;
int var = 0;
void setup () {
pinMode(r1, OUTPUT);
pinMode(g1, OUTPUT);
pinMode(r2, OUTPUT);
pinMode(g2, OUTPUT);
pinMode(r3, OUTPUT);
pinMode(g3, OUTPUT);
pinMode(r4, OUTPUT);
pinMode(g4, OUTPUT);
pinMode(y0, OUTPUT);
pinMode(isObstaclePinA, INPUT);
pinMode(isObstaclePinB, INPUT);
pinMode(isObstaclePinC, INPUT);
pinMode(isObstaclePinD, INPUT);
}
void loop () {
switch (var) { // for enabling the switch command
case 1:
if (isObstaclePinA == HIGH);
digitalWrite(isObstaclePinB, LOW);
digitalWrite(isObstaclePinC, LOW);
digitalWrite(isObstaclePinD, LOW);
digitalWrite(g1, HIGH);// LED lights on
digitalWrite(r1, LOW);
digitalWrite(r2, HIGH);
digitalWrite(r3, HIGH);
digitalWrite(r4, HIGH);
delay(timer); // time the lights will turn on
digitalWrite(y0, HIGH);
delay(3000); // time the yellow LED will light
for (isObstaclePinA == HIGH; timer < 50000; timer + 5000); // for adding seconds in the timer every time the sensor responds
break;
case 2: // next case
if (isObstaclePinB == HIGH);
digitalWrite(isObstaclePinA, LOW);
digitalWrite(isObstaclePinC, LOW);
digitalWrite(isObstaclePinD, LOW);
digitalWrite(g2, HIGH);
digitalWrite(r2, LOW);
digitalWrite(r1, HIGH);
digitalWrite(r3, HIGH);
digitalWrite(r4, HIGH);
delay(timer);
digitalWrite(y0, HIGH);
delay(3000);
for (isObstaclePinB == HIGH; timer < 50000; timer + 5000);
break;
case 3:
if (isObstaclePinC == HIGH);
digitalWrite(isObstaclePinB, LOW);
digitalWrite(isObstaclePinA, LOW);
digitalWrite(isObstaclePinD, LOW);
digitalWrite(g3, HIGH);
digitalWrite(r3, LOW);
digitalWrite(r1, HIGH);
digitalWrite(r2, HIGH);
digitalWrite(r4, HIGH);
delay(timer);
digitalWrite(y0, HIGH);
delay(3000);
for (isObstaclePinC == HIGH; timer < 50000; timer + 5000);
break;
case 4:
if (isObstaclePinD == HIGH);
digitalWrite(isObstaclePinB, LOW);
digitalWrite(isObstaclePinC, LOW);
digitalWrite(isObstaclePinA, LOW);
digitalWrite(g4, HIGH);
digitalWrite(r4, LOW);
digitalWrite(r1, HIGH);
digitalWrite(r2, HIGH);
digitalWrite(r3, HIGH);
delay(timer);
digitalWrite(y0, HIGH);
delay(3000);
for (isObstaclePinD == HIGH; timer < 50000; timer + 5000);
break;
Replies
-
Abhishek HavanurJoerel Bacanican someone give me advice about the code for this project
this is my sample code
int r1 = 1;// pin for the LED
int g1 = 2;
int r2 = 4;
int g2 = 5;
int r3 = 7;
int g3 = 8;
int r4 = 10;
int g4 = 11;
int y0 = 13;// all yellow LED are connected in parallel
int timer = 7000;// set initial timer for the system after first boot
int isObstaclePinA = 3;// pin for the IR sensor
int isObstaclePinB = 6;
int isObstaclePinC = 9;
int isObstaclePinD = 12;
int var = 0;
void setup () {
pinMode(r1, OUTPUT);
pinMode(g1, OUTPUT);
pinMode(r2, OUTPUT);
pinMode(g2, OUTPUT);
pinMode(r3, OUTPUT);
pinMode(g3, OUTPUT);
pinMode(r4, OUTPUT);
pinMode(g4, OUTPUT);
pinMode(y0, OUTPUT);
pinMode(isObstaclePinA, INPUT);
pinMode(isObstaclePinB, INPUT);
pinMode(isObstaclePinC, INPUT);
pinMode(isObstaclePinD, INPUT);
}
void loop () {
switch (var) { // for enabling the switch command
case 1:
if (isObstaclePinA == HIGH);
digitalWrite(isObstaclePinB, LOW);
digitalWrite(isObstaclePinC, LOW);
digitalWrite(isObstaclePinD, LOW);
digitalWrite(g1, HIGH);// LED lights on
digitalWrite(r1, LOW);
digitalWrite(r2, HIGH);
digitalWrite(r3, HIGH);
digitalWrite(r4, HIGH);
delay(timer); // time the lights will turn on
digitalWrite(y0, HIGH);
delay(3000); // time the yellow LED will light
for (isObstaclePinA == HIGH; timer < 50000; timer + 5000); // for adding seconds in the timer every time the sensor responds
break;
case 2: // next case
if (isObstaclePinB == HIGH);
digitalWrite(isObstaclePinA, LOW);
digitalWrite(isObstaclePinC, LOW);
digitalWrite(isObstaclePinD, LOW);
digitalWrite(g2, HIGH);
digitalWrite(r2, LOW);
digitalWrite(r1, HIGH);
digitalWrite(r3, HIGH);
digitalWrite(r4, HIGH);
delay(timer);
digitalWrite(y0, HIGH);
delay(3000);
for (isObstaclePinB == HIGH; timer < 50000; timer + 5000);
break;
case 3:
if (isObstaclePinC == HIGH);
digitalWrite(isObstaclePinB, LOW);
digitalWrite(isObstaclePinA, LOW);
digitalWrite(isObstaclePinD, LOW);
digitalWrite(g3, HIGH);
digitalWrite(r3, LOW);
digitalWrite(r1, HIGH);
digitalWrite(r2, HIGH);
digitalWrite(r4, HIGH);
delay(timer);
digitalWrite(y0, HIGH);
delay(3000);
for (isObstaclePinC == HIGH; timer < 50000; timer + 5000);
break;
case 4:
if (isObstaclePinD == HIGH);
digitalWrite(isObstaclePinB, LOW);
digitalWrite(isObstaclePinC, LOW);
digitalWrite(isObstaclePinA, LOW);
digitalWrite(g4, HIGH);
digitalWrite(r4, LOW);
digitalWrite(r1, HIGH);
digitalWrite(r2, HIGH);
digitalWrite(r3, HIGH);
delay(timer);
digitalWrite(y0, HIGH);
delay(3000);
for (isObstaclePinD == HIGH; timer < 50000; timer + 5000);
break; -
Abhishek HavanurMay i know your project problem Statement?
-
Joerel Bacanican you help me do the code for this?
this is how the system will work
the IR sensor will count the no. of vehicle then convert it to time that the green light will turn on.
I'm having trouble dealing with it
thank you
You are reading an archived discussion.
Related Posts
My name is Doug. I am not an engineer. If either of those statements disqualifies me from being a member here, please tell me. If there is a more appropriate...
With an Amara Raja Amaron Tribal UPS/Inverter 1400va/24v and with a connected load of 365 watts I need a back up for 4 hours. I have 2X12 V 150ah batteries....
When and how does over heating occurs.....
Is it true that when driving your car with first gear overheating occurs....an How is that possible if so..
Hi...am Kofi an engineering student and an auto mechanically... I just join the forum.....and please forgive me for my late introduction.....
Hi,
I m entc engineer with aggregate 58%. I want to get into it sector. What should do. Batch 2016 pass out.