I am trying to use garage door safety sensors as a way of counting cars. From my understanding, if there is no object (car) between the sensors, then they output a 3.3V signal every 6 milliseconds. If an object (car) is detected, then they output a close to 0 voltage. Has anyone done this before? Currently, when I use digitalRead(), whether I compare it to LOW or HIGH, it results as true. I had a hard time finding a circuit schematic, but what I have seems to work.
SensorA and SensorB correspond to the two sensors of a garage door safety sensor.
Here is the output of the gpio tested using an oscilloscope, when no object is between the sensors:
Here is my code:
#include <stdio.h>
#include <unistd.h>
#include <wiringPi.h>
#define IRSensor 21 //Pin 40
int main(int argc, char **argv) {
if(wiringPiSetupGpio() != 0){
printf("ERROR\n");
return 1;
}
pinMode(IRSensor, INPUT);
printf("Checking\n");
while(1){
if(digitalRead(IRSensor == LOW)){
printf("LOW\n");
sleep(1);
}
if(digitalRead(IRSensor == HIGH)){
printf("HIGH\n");
sleep(1);
}
}
return 1;
}
Current Output: LOW HIGH LOW HIGH . . . . etc.
Expected Output:
LOW (when something is between the sensors)
HIGH (when nothing is between the sensors)
Has anyone done this before?