Need help in coding for a density based traffic management system


#1

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


#2

dear Venom,

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.


#3

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.


#4

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.


#5

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.


#6

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


#7

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.


#8

ok,
can you use this code and resend to me the result.
//////////////////////////////
int IR1,IR2,IR3,IR4;
void setup() {
Serial.begin(9600);
}

void loop() {
IR1=Serial.read(A0);
IR2=Serial.read(A1);
IR3=Serial.read(A2);
IR4=Serial.read(A3);
Serial.print("IR1= ");
Serial.println(IR1);
Serial.print("IR2= ");
Serial.println(IR2);
Serial.print("IR3= ");
Serial.println(IR3);
Serial.print(“IR4= “);
Serial.println(IR4);
Serial.print(”///////////////////////”);
delay(5000);

}
/////////////////////////////////////////
this code just to know what the IR give when it cutting.
after that i will send to you the full code.