Had some issues with the operation of my parking sensor which I resolved and now it seems to be working perfectly.
Thought I would pass on what I did in the hope that it might help others having the same problem.
There were 2 issues.
The first issue was random lighting of the led ring after the car was pulled out of the garage and the door was closed. My guess was that the sensor, in the absence of having the solid car to bounce off of, was picking up stray sensor ping echoes from other objects in the garage. Checking on internet revealed that others using the HC-SR04 Distance sensor had experienced this problem. Checking further, I discovered that there were updates to the NewPing library, the latest being version V1.7 and specifically that V1.6 included an update to the sonar.ping_median function used for distance measurement in the parking sensor code. The MySensors library current version is V1.5. After I updated to V1.7 I no longer had random readings when the car was not in the garage. First problem solved.
bolded textSo I would recommend updating to NewPing V1.7.
I then reinstalled the parking sensor in the garage for further testing. Everything appeared to be going well but when I returned to park my car in the garage later in the day I was greeting by the led ring flashing bright red with all its leds which is supposed to be a panic signal that the car was parked as close as it should be. But I had just entered the garage and was not anywhere near the range of being parked. Took the sensor down and brought it in for testing. Found out that everything worked fine except if it was left on in the condition where it was not sensing any object in range for an extended period of time, it went into the flashing led mode. Too me it had the symptom that given enough time, a variable was being overrun (an integer variable exceeding its capacity). Checking over the code I noted the following lines:
if (displayDist == 0) {
// No reading from sensor, assume no object found
numLightPixels--;}
So everytime the displayDist = zero (and it is zero when no object is detected) numLightPixels is decremented by 1. So if there is no car in the garage (and since I had fixed the random detection problem), the sensor returns a steady stream of zeros to indicate there is no car in the garage and the numLightPixels is decremented with no limit. Given enough time it will eventually decrement to -32,768 at which point it rolls over to +32,767 and at that point the red leds will all flash in the panic mode. To fix this, I changed the above code to read:
if (displayDist == 0) {
// No reading from sensor, assume no object found
//Make sure you don’t go below zero
if (numLightPixels>0) {
numLightPixels--;}
So now it won’t decrement numLightPixels below 0. That solved the problem.
There is also one related efficiency change I made. At the beginning of the loop there is code to skip 10 zero readings:
if (displayDist == 0 && skipZero<10) {
// Try to filter zero readings
skipZero++;
return;
}
I changed that code to skip all zero readings if numLightPixels is less the one (i.e., 0), since if numLightPixels is at zero all of the pixels are already off and if the sensor continues to read zeroes, they should all be skipped (don’t go through the rest of the loop) until a nonzero reading is obtained (something is found).
if (displayDist == 0 && numLightPixels<1) {
// Filter zero readings
return;
}
Mounted the sensor in the garage again and now everything works perfectly. Hope this helps someone else.