I decided to build this project and getting it going was easy with the great directions.
My problem as a first time Photon user is why does it not seem to work. I was able to successfully compile and flash. I see with the app the data fields but they make no reliable sense. The Photon connects just fine and the app displays the variables.
Thought the SR04 was defective so I bought 2 more, same garbage readings. I get: oil-gallons=0.0, oil-inches=46.9, distance=-1.0 and 4.73 VDC on the GND and VCC of the SR04.
To cut down on any issues I commented out all the alert code.
Can you share your code (if using Web IDE the easiest is to use the SHARE THIS REVISION button and post the link) and also state how you connected the sensor?
That’d make debugging your issue easier
@Condoman, posting a picture of your wiring might be helpful. You can find other posts from other members regarding the SR04 sensor which may be helpful.
I’ve played around with the HC-SR04 myself and discovered a bit of an issue with the basic way mine functioned.
Using the simple examples I found on the net I would keep gettting randon strange way off the scale results from time to time. It turns out after scopeing the echo pin, if the sensor failed to get an echo back within some time out value it would send the echo pin high before resetting itself. There are a lot of reasons it might not get an echo, be it unrefleactive surfaces, not pointing in the right direction etc… but this reset throws your code if your not aware of it. To that end I re-worked the basic example to allow for an out of range reading and then to ignor the next echo high pulse. I found it alot more reliable.
I’ve just realised the version I shared, was faulty, so I’ve deleted the link… I’ve doing this during my lunch break, so I’ll reshare once I’ve double, doubled checked the version…
Above is how I wired this in accordance with the project I am copying.
VideoLiam: I don’t know if the code ventz wrote accommodated the echo timing.
Without a scope it is very hard to determine what is not working. I have checked the continuity of the jumpers and the pin voltage on the sensor. I simply do not know what else to do. I suppose I could have gotten 3 bad sensors but not likely.
Because the Particle app displays some number in the device data I have to assume the Photon is working. Is there something else I can do to verify that?
Nice catch. I had followed the instructable which shows D1 & D2. I see the code comment shows D0 & D1. I will change and report back. The wires are 8".
OK, This is the code I wote to return a much more reliable reading from the HC-SR04, that I got off the net.
This actually rejects dud readings and returns 0cm… You can tell its a dud reading if there is a pause in the reading whilst monitoring it on the serial terminal.