GithubHelp home page GithubHelp logo

oupula / node_hcsr04 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sza2/node_hcsr04

0.0 1.0 0.0 151 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 Introduction

node_hcsr04

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

This example shows how to interface HC-SR04 ultrasonic sensor to ESP8266 with NodeMCU firmware (2015-01-27 or later, since it uses floating point).

It uses 2 GPIOs, trig (GPIO2, IO index: 4) and echo (GPIO0, IO index: 3).

The accuracy is usually ~1-2cm, Most probably the reason is not the sensor but the interrupt and timing accuracy of the NodeMCU firmware, although it was not tested.

The device class (hcsr04) has two user usable functions:

hcsr04.init() accepts two parameter, trig and echo pin index. hcsr04.measure() initiate the measurement and returns the distance in meters (or -1 if distance cannot be determined).

Bear in mind HC-SR04 nominal VDD is 5V. Based on my experience it stops working under 3.5V, so the ESP8266 VDD may not be sufficient to power the ultrasonic sensor.

Based on Rolox recommendation an average function was introduced. Theoretically it makes the distance measurement more precise.

node_hcsr04's People

Contributors

sza2 avatar

Watchers

Vampire avatar

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.