0

I want to use two ultrasonic sensors for counting incoming cars to a garage. What I want is: When both sensors detect the object then the counter should increase.

Can anyone help me and give me an example?

2

If you have two sensors, you use analogRead.

int sensor1 = A0;
int sensor2 = A1;
int distance = 50; // or whatever you want here
bool car_passing = false;

void setup(){
    int counter = 0;
}

void loop(){
    if(analogRead(sensor1) < distance && 
       analogRead(sensor2) < distance && 
       !car_passing)
    {
        car_passing = true;
        counter++; 
    }

    if(analogRead(sensor1) > distance){
        car_passing = false;
    }
}

To prevent the counter keep counting while the car is passing by, we need to make a boolean, so the counter does not wait for count again, before the car has passed.

  • In order not to count kids in a Kettcar, big dogs or birds, a smarter algorithm should be used to define, what a car is and what not. – ott-- Mar 26 '16 at 20:36
  • @ott that is true. Personally I wouldnt go for two ultra sonic sensors. But yea, that is what he asks for. – el3ien Mar 26 '16 at 20:45

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .