GithubHelp home page GithubHelp logo

sza2 / node_hcsr04 Goto Github PK

View Code? Open in Web Editor NEW
44.0 44.0 21.0 15 KB

Distance measurement example for ESP8266/NodeMCU using HC-SR04 ultrasonic sensor

License: GNU General Public License v3.0

Lua 100.00%

node_hcsr04's People

Contributors

sza2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node_hcsr04's Issues

Incorrect reading?

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

This is the debug printout of the self.time_start and _end

1079788923
1079789402

479


1079897355
1079897818

463


1080035710
1080036173

463


1080174067
1080174530

463

7

1080788919
1080789402

483


1080897355
1080897822

467


1081035711
1081036177

466


1081174065
1081174532

467

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

accuracy / repeatability experiences?

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?

timer has nil value?

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.

not working -1 returned on all measurements

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.