Good afternoon,
I am using an HC-SR04 ultrasonic sensor to detect people walking into a room. I have two sensors, depending on which one detects presence first it determines the direction you are moving so it is bidirectional. This works great swiping my hands or a box in front of them, it increments or decrements a counter as things pass by.
However, when using myself (a person) as a test subject passing by the sensors, at approximately 50cm both sensors read me as being 2884cm away when the maximum distance of sensors is 600cm. This causes the entire project not to work, as I am looking for someone to be less than 80cm away before counting.
I have tested using only one sensor at a time, as well as swapping for new sensors, checking all wires, increasing delays between each pulse, etc. Does anyone have any ideas on why this happens?
It works perfectly fine using my hand - just not people. Do they not work with clothing for some reason? This is a project I am making for work due to the COVID-19 pandemic, so any guidance as to why this happens would be extremely appreciated! I have removed everything except for the sensors from my circuit and tested it with this code;
#define trigPin 5
#define echoPin 6
#define trigPin2 9
#define echoPin2 10
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
delay(100);
long duration2, distance2;
digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
duration2 = pulseIn(echoPin2, HIGH);
distance2 = (duration2/2) / 29.1;
Serial.print(distance);
Serial.print(", ");
Serial.print(distance2);