Giter Site home page Giter Site logo

st_hw_hc_sr04's Introduction

ST_HW_HC_SR04

Advanced arduino library for HC-SR04 ultrasonic sensors

Usage

Basic example:

#include <ST_HW_HC_SR04.h>

ST_HW_HC_SR04 ultrasonicSensor(13, 12); // ST_HW_HC_SR04(TRIG, ECHO)

// Get the time the ultrasonic pulses took from the sensor to the blocking object
int hitTime = ultrasonicSensor.getHitTime();

// Calculate the approximate distance in centimeters (as seen in extras/HC-SR04.txt)
int distanceInCm = hitTime / 29;

The getHitTime function will return 0 if the ultrasonic sensor doesn't receive back the packets it sent before the timeout value.

Timeouts

The default timeout value is 5000 microseconds, which sould be enough for approximately 86 centimeters ([5000 / 58] ~= 86.2).

Although I didn't confirm, it is stated in this datasheet (alternate link) that max. range of this sensor is 4 meters (400cm). As so, setting the timeout value to 23200 microseconds (23.2 ms) should be enough for all cases where the object distance is less or equal to 4 meters.

The timeout-related methods of this library are:

// Setters
ultrasonicSensor.setTimeout(unsigned long desiredTimeout);
ultrasonicSensor.setTimeoutToDefaultValue();

// Getters
unsigned long currentTimeout = ultrasonicSensor.getTimeout();

Extra information

Information about how the ultrasonic sensor works is present in the extras/HC-SR04.txt file.

st_hw_hc_sr04's People

Contributors

feikname avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

tubbz-alt

st_hw_hc_sr04's Issues

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.