Automatic Traffic System

I want to make an automatic traffic lighting system so if the IR sensor doesn't detect any cars for 20 seconds the pedestrian crossing goes on and if there aren't any pedestrians for 30 seconds the green light goes on for the cars but i am having issues with the timer, what i want to do is if an IR sensor doesn't detect something( so it stays on low for 30 seconds) a light goes on, can somebody help me with the code

Thanks in advance :slight_smile:

How can we help you coding without seeing your code?

Read the sticky topics on top of the forum, on using the forum and on posting code.

The following is a simple way to check if a button is pressed continuously for a certain length of time - the same technique can be used for your IR sensor.

void loop() {
   buttonState = digitalRead(buttonPin);
   if (buttonState == HIGH) {   // assumes LOW when pressed and HIGH when not-pressed
       lastTimeButtonWasHigh = millis();
   }

   if (millis() - lastTimeButtonWasHigh >= requiredTime) {
       // input has been LOW throughout the required time
       // do whatever needs to be done
   }
}

If you need to ensure that the button has NOT been pressed during that time you will obviously need to invert the logic.

...R

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.... :slight_smile: