Detecting if car is incoming or outgoing

Hi, I’m quite new to Arduino but find it quite easy to work with. Today I’m facing a problem : I’d like to detect when a car is incoming or is outgoing into a tunnel. I’m not interested in when the car is present; I only need to activate a digital output when the car goes inside to take it a photo only once and activate another different digital output when the car is outgoing.
My problem is how to trig the 2 outputs “one way” only. I want to use 2 ultrasonic transducers that already own and fixed into a bar of 2 meters long; they can detect from 40 to 500cm and I thought to use the quadrature system used for encoders, but I can’t imagine the code I should write.
Could you help me ?

Thanks.

Overbusy

If you mean one transmitter and one receiver for the 2 ultrasonic transducers, then you can't do it. If you mean two pairs, then you can see which one triggers first (A, then B) to indicate motion from A to B. If it is the other way around (B, then A) then you have motion in the other direction.

You basically have two possible states. Either there is a car or there isn't. If the first sensor is tripped then there is a car and if the second sensor is tripped while there is a car then you go back to no car.

// out at global scope:
boolean carPresent = false;



// somewhere in loop:
if (carPresent == false) {
    if (first sensor is tripped) {
         carPresent = true;
         // whatever else needs to happen when you first detect a car
    }
}
else if(carPresent == true){
    if(second sensor is tripped){
          carPresent = false;
          // whatever else you need to do whenever you first detect the car leaving
    }
}

blh64:
If you mean one transmitter and one receiver for the 2 ultrasonic transducers, then you can't do it. If you mean two pairs, then you can see which one triggers first (A, then B) to indicate motion from A to B. If it is the other way around (B, then A) then you have motion in the other direction.

I have 2 transducers that integrates transmitter and receiver in one cartridge each one ... the transducers are the same you can find on the rear of the cars.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
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.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Have you got the sensors connected to the Arduino?
What model Arduino are you using?

overbusy:
I have 2 transducers that integrates transmitter and receiver in one cartridge each one ... the transducers are the same you can find on the rear of the cars.

Do you have any data/specs on these transducers.
Before trying to get direction, you need to get ONE of the sensors working with your controller.
Thanks.. Tom... :slight_smile:

TomGeorge:
Please read the first post in any forum entitled how to use this forum.
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.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Have you got the sensors connected to the Arduino?
What model Arduino are you using?Do you have any data/specs on these transducers.
Before trying to get direction, you need to get ONE of the sensors working with your controller.

Hi TomGeorge, ok, I read “how to use this forum” few minutes ago; thanks.
In attachmentyou can fnd what I need to do.
My transducers are two JSN-SR04T connected to an Arduino UNO (not original). At the moment I have ONE sensor up and running with a sketch I wrote following the video at URL JSN-SR04T Ultrasonic module for Arduino - YouTube. The only modifications I did is to the pin numbers for TRIG and ECHO, moreover I added a second sensor. These transducers give back a “distance” information, but it is my intention to use it to only detect if a car is near to sensor (within a specified range) so I translate an integer into a boolean. If the car is ingoing one led should lit, if the same car (that could/couldn’t stop in front of the sensor) is outgoing another led should lit.
Thanks.
Overbusy

detecting car incoming-outgoing.pdf (145 KB)