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?
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It only takes a minute to sign up.
Sign up to join this communityIf 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.