I need help in the coding part, mainly because I am beginner.
I am using 4 ir sensors, one for each of the 4 traffic lanes to sense the density of traffic.
If there are vehicles on a particular lane the signal should change to green while staying on for about 10-15 seconds this means that all the other lane’s signals should be changed to red.
In case there is traffic on all the lanes the traffic signal should change based on a time delay
you can make an array and check the IR sensor an save the result,
then light the green and red light using if statement .
4 if statement i think its enough.
i hope that’s helped you in your project.
I am very thankful for your inputs but as I have stated before I am beginner. I have understood what you are trying to put across.
But I have just started to learn to code a few months ago in c language. Though I can understand the codes, currently I am not at a stage where I can write a code as required for my project.
Ok Ok ,I am very Sorry,
lets start together, first for your project you need to check the four IR:
and save the result in some place { ex: make a four integer int IR1=0,IR20,IR3=0,IR4=0;}
and make
IR1=analogRead(A0);
IR2=analogRead(A1);
IR3=analogRead(A2);
IR4=analogRead(A3);
}
after that you but your polarity in for if statment.
if(IR1 == HIGH){
digitalWrite(Green1,HIGH);
digitalWrite(red1,low);
delay(5000);
digitalWrite(Green1,LOW);
digitalWrite(red1,HIGH);
}
if(IR2 == HIGH){
digitalWrite(Green2,HIGH);
digitalWrite(red2,low);
delay(5000);
digitalWrite(Green2,LOW);
digitalWrite(red2,HIGH);
}
if(IR3 == HIGH){
digitalWrite(Green3,HIGH);
digitalWrite(red3,low);
delay(5000);
digitalWrite(Green3,LOW);
digitalWrite(red3,HIGH);
}
if(IR4 == HIGH){
digitalWrite(Green4,HIGH);
digitalWrite(red4,low);
delay(5000);
digitalWrite(Green4,LOW);
digitalWrite(red4,HIGH);
}
if you want more details i am here, but if you take some details and try to write in your way,
that can make more advance for you.
Write your code and try it and tell me i am with you.
Thanks a ton for your explanation. I got an idea of how to do the coding.
But then, while going through the code I got some doubts.
What if all the 4 sensors give an input of high because of the presence of traffic on all the 4 lanes. How would you write the code such that the signals change after a certain delay. And, is it possible to keep a count of how many vehicles pass by during this alternate signaling system, if so how.
nice question,
this is depend about what you want.
first If you want just if the IR cut it ,select the line and make the led green,
Or you can make count how mush car in cut the IR and give the polarity.
the first one its not very difficult.but the second its very butty full for your project and need some work.
if you want take it without counting the car.
just cheek the 4 IR and make 4 if statement the first rod if the ir cut it green the first road 5 sec and make it red after that if the second ir cut it make the second road green 5 sec and make it red and so as .
in this case if any IR not cut it the road will not change (will be red).
but if you want to make your code with counting the car.
let me know to start thinking together to make it.
its not very difficult but need some time to test it to make it working very well.
sorry for not give you a ready code. that’s will not help you.
but if you want a code , i will try to make it for you
I kind of understood what you are trying to say. Could you give me the code for when all the 4 ir sensors give an input of high so that the signal changes based on a certain time delay.
Once I write the code for what has been discussed since before I’ll get back to u with the complete code after which we can think about implementing the counting vehicles idea in the whole program.