Hi all, I am playing with the HC-SR04 on my esp8266 today and found that the outputted cm value doesn't seem correct at all. it looks like this(see below). a very large value returned. btw, I am completely new to this iot. but I did played with the ultrasonic sensor once with the arduino uno a while back and the distance output seems correct. so, my question is that is it possible that there's a bug in the distance calculation? I highly doubt that. but just want to make sure. If not, what am I doing wrong here? thanks in advance
I used the code straight from https://www.espruino.com/HC-SR04
35964.50877192983 cm away
144735.33333333340 cm away
153507.50877193000 cm away
162278.77192982469 cm away
171052.05263157916 cm away
179822.78947368444 cm away
188593.07017543850 cm away
197371.64912280708 cm away
206141.92982456140 cm away
214913.57894736839 cm away
223685.52631578940 cm away
232456.89473684219 cm away
241229.26315789471 cm away
249997.29824561413 cm away
258771.82456140377 cm away
267546.50877192983 cm away
276315.40350877214 cm away
285087.42105263157 cm away
293859.31578947376 cm away
302631.43859649135 cm away
What did yòu change A0 and A1 to and how did you wire it up?
I think the values you are seeing are random values.
A0 map to NodeMCU.D1(Label D1 on board) => Trig on sensor
A1 map to NodeMCU.D2(Label D2 on board) => Echo On sensor
Is the HC-SR04 code even known working on ESP8266? Because of how it has to keep yielding to do the radio stuff, timing-critical things can be problematic....
I don't know if the code is working on the esp8266. Can any body share their experience with the esp8266 here?
I have same issue on esp32, just increasing numbers ...
I don't think it's a bug with timing, rather setWatch not triggering on rising signal only on falling. As values are based on timer of falling event numbers are increased all the time.
Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
For a full reference visit the Markdown syntax.
© Espruino, powered by microcosm.
Report a problem