sza2 / node_hcsr04 Goto Github PK
View Code? Open in Web Editor NEWDistance measurement example for ESP8266/NodeMCU using HC-SR04 ultrasonic sensor
License: GNU General Public License v3.0
Distance measurement example for ESP8266/NodeMCU using HC-SR04 ultrasonic sensor
License: GNU General Public License v3.0
I used your code but I only get incorrect readings from the HC-SR04 sensor.
I did some debug modifications in the function self.measure() see below:
function self.measure()
gpio.trig(self.echo, "up", self.echo_cb)
gpio.write(self.trig, gpio.HIGH)
tmr.delay(100)
gpio.write(self.trig, gpio.LOW)
tmr.delay(100000)
if (self.time_end - self.time_start) < 0 then
return -1
end
-- Modified for debug purpose
print ("-------------------")
print (self.time_start)
print (self.time_end)
print (self.time_end - self.time_start)
print ("-------------------")
return (self.time_end - self.time_start) / 58
1079788923
1079789402
1079897355
1079897818
1080035710
1080036173
1080174067
1080174530
1080788919
1080789402
1080897355
1080897822
1081035711
1081036177
1081174065
1081174532
8
Do you have an explination to why the time between trigger and echo is constant at around 460-470 us even if there is nothing infront of the sensor.
Could you also explain why you devide the delta time by 5800, I am guessing it has something to do with the speed of sound in air. 343 m/s = 34300 cm/s
What am i doing wrong? ;)
Thanx for your support
Hi,
With my srf05 sensor I get readings jumping by ~1 meter - every 10seconds I get a drastically different reading.
Do you have any similar experiences? Or perhaps is it a faulty module?
after ~10 successful readings I will get an error -
PANIC: unprotected error in call to Lua API (hcsr04.lua:42: attempt to index global 'tmr' (a nil value))
line 42 is a delay(100) command... so is there something with the triggers making it screw up?
update: without sensor connected returns 0 and no errors. so probably some hardware issue.
I am able to make the module/setup work perfectly with the Arduino code and can confirm hardware is in proper order.
With this library unfortunately i get only -1 as a reading and sometimes 15 sporadically not sure what is the cause.
function self.measure() missing 'end' at end of if statement
function self.measure_avg() missing end at end of if statement
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.