Hello,
I have a HC-SR05 Distance Sensor, more exact this one: Velleman VMA306
I've been using the NewPing library, but it seems my sensor is behaving differently and not compatible with that library.
Problem #1 - Two pin mode don't work with default config (ONE_PIN_ENABLED=true)
When using the library with the default settings and using two pins, the trigger signal is always 5V and therefor creates and endless loop of measurements so the trigger signals becomes useless (see upper part of this image):
Seems to be the same issue being raised here: teckel12 / Arduino New Ping / issues / #53 - Trigger pin set to "input" ? — Bitbucket.
It appears the library is supposed to work with default config (ONE_PIN_ENABLED=true) even when you run with two pins. So I don't know if this becomes a problem for me because my sensor is always looking for 5V signal on the trigger instead of only looking for a 5V raise from ground?
Has anyone seen this problem or behaviour before? It seems to be an odd behaviour as it isn't compatible with the NewPing library.
Code:
#include <NewPing.h>
// SONAR
#define TRIGGER_PIN 13
#define ECHO_PIN 5
#define MAX_DISTANCE 450
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
long distance = 0;
// Periodic running of code
unsigned long lastTimestamp = 0;
const int period = 500;
void setup() {
Serial.begin(9600);
}
void loop() {
if ((millis() - lastTimestamp) >= period) {
lastTimestamp = millis();
distance = sonar.ping_cm();
}
}
Problem #2 - Echo 5V signal isn't starting until the sonar response is received
In the NewPing library code, it seems to assume the echo signal is starting directly after the sonar pulses are sent. But looking at my sensor, it starts the echo 5V signal AFTER the sonar pulses have returned. You can see that there is always a wait before the echo signal that is the same width as the echo pulse afterwards:
see second part of image above, couldn't post more than 1 image
This means many assumptions in the NewPing library are wrong for my sensor. For example, you can find this in the code:
Maximum time we'll wait for ping to start (most sensors are <450uS, the SRF06 can take up to 34,300uS!)
Sounds like the code writer is surprised by the 34,300uS value, but if it works like my sensor, it makes sense as that is equal to a distance of ~5.8 meter which maybe makes sense to measure with that sensor. So maybe it is just that SRF06 is behaving like mine, that is waiting for the sonar pulses to return before starting the echo signal (which then is ~34ms long).
This also means that when measuring long distances of the max distance of 4.5m, you need to have ~60ms between pings (measuring 4,5m @ 53ms + some margins), or double the time vs a sensor starting the echo signal directly.
I haven't found this issue/behaviour discussed anywhere, so wanted to check in here if anyone has run into it before or if my sensor is unique.
Maybe @teckel knows something.
Thanks!