Giter VIP home page Giter VIP logo

ultrasonic's Introduction

Open Source badge GitHub GitHub release (latest by date) Check Arduino

🇬🇧 English | 🇧🇷 Português Brasileiro

Ultrasonic

Minimalist library for ultrasound module to Arduino

Compatible with HC-SR04, Ping))) and Seeed SEN136B5B (from Seeed Studio)

Work with ultrasonic modules is fairly simple, but can be even more practical if you abstract the control of some features. This library aims to resource efficiency and to simplify access to data.

Where necessary use the ultrasonic module HC-SR04 (one of the most common on the market), Ping))) and/or Seeed SEN136B5B (from Seeed Studio), there are hundreds of libraries that purport to provide the most diverse roles for the user, however, the vast majority of the time, we just need to find out the distance and is that's what does this library.

This library is minimalist, reduces code execution, validation and unnecessary use of global variables, prioritizing smaller data types.

You can run the library examples on the Wokwi Arduino simulator. Wokwi is a free Arduino simulator which runs on the browser. Here are two examples presenting the features of the Ultrasonic library

Example 1 - Ultrasonic distance measurement using 4 pin and 3 pin sensor versions

Example 2 - Reading distance in both centimeters and inches

Wiring:

It is very easy to connect an ultrasound module to the Arduino. For example, if you are using HC-SR04, connect the trigger and echo pin module on pin 12 and 13 of the Arduino, respectively. As in the picture:

HC-SR04 with Arduino

If you are using a module with three pins (like Ping))) or Seeed SEN136B5B), you can conect the sig pin module on pin 13 of the Arduino.

You can use the Fritzing(.fzz) files inside extras to draw your prototypes.

How to use:

The idea is to provide a simpler environment possible. To do this, simply follow the steps:

  1. Installing

    First you need to import the library so that the IDE recognizes it. The simplest way is importing through the IDE itself:

    • Click in Sketch > Include Library > Manage Libraries...;
    • In the search field type: ultrasonic;
    • In the list, look for Ultrasonic by Erick Simões;
    • Click on Install.

    Alternatively, you can download the library here and import the .zip file into the IDE (see how to import a library here).

  2. Importing on code

    To import the library to your code, just write at the beginning of the code #include <Ultrasonic.h> or, in the Arduino IDE, click in Sketch > Include Library > Ultrasonic (will have the same result).

  3. Starting (the most exciting part)

    Now is simply create a variable of type Ultrasonic passing as parameters two values representing, respectively, the Trig (emitter) and Echo (receiver) pins. Like this:

    Ultrasonic ultrasonic(12, 13);

    If you are using a module with three pins (like Ping))) or Seeed SEN136B5B), pass as a parameter only the signal pin. Like this:

    Ultrasonic ultrasonic(13);
  4. Discovering the distance

    Having initialized a variable, you can run hers from the method that returns the distance read by module Ultrasonic: read():

    ultrasonic.read();
  5. Only this?

    Yes. That's it. By default, the value returned from the function read() is the distance in centimeters. See full sample code here.

  6. Seriously?

    You can still do a little more determining the unit of measurement that will be returned (centimeters (CM) or inches (INC)).

    ultrasonic.read()    // distance in CM
    ultrasonic.read(CM)  // distance in CM
    ultrasonic.read(INC) // distance in INC

    You can also use more than one ultrasound module:

    Ultrasonic ultrasound1(12, 13);
    Ultrasonic ultrasound2(10, 11);
    Ultrasonic ultrasound3(5);
  7. Timeouts

    If there is no object in range, the library will lock-up as it waits for the return pulse. You can change how long to wait by setting a timeout (in microseconds) in the constructor:

    Ultrasonic ultrasonic(12, 13, 40000UL);

    Or during runtime:

    ultrasonic.setTimeout(40000UL);

    The default value is 20000UL (Unsigned Long).

    Using a 40ms timeout should give you a maximum range of approximately 6.8m. You may need to adjust this parameter.

See the examples here.

License

Ultrasonic by Erick Simões is licensed under a MIT License. Based on the work of Carl John Nobile available here. Feel free to contact the author on Twitter: @AloErickSimoes

See LICENSE for details.

ultrasonic's People

Contributors

eliotlim avatar ericksimoes avatar matititam avatar otacilion avatar otaldol2 avatar per1234 avatar steffanop avatar viniciusnicassio 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  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  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

ultrasonic's Issues

Change license

The license is poorly defined.
It is necessary to choose a permissive license, which projects the copyright and stimulates the external contribution.

No longer use the 'pulseIn()' method

Apparently, when this library is used on a non-Arduino-based device, the pulseIn() method, used to wait the echo, causes incompatibility problems.
To prevent any future problems, is recommended to use another strategy to read the length of the pulse (in microseconds), like using micros().

An Arduino simulation page for the Ultrasonic library!

hi there

Thank you very much for the library.
I have created a simulation page for the Ultrasonic sensor library here:.
https://wokwi.com/arduino/projects/296099969420493322

It is a permanent page and it gives an opportunity for your future library users to play with the library and get a feel of it even before they integrate the library into their own project.

Kindly let me know what you think!
image

If you feel it is good, I would love to create a PR to add the simulation link in the ReadMe file.

Thanks a lot!
Puneeth

Ultrasonic Android on Madsonic Server

Hi! I'm using an older version of Madsonic server, latest free, without activation (MADSONIC 5.1.5260.20150831.0820) and after your latest update your android client can't connect to server. (A network error ocurred. Please check the server address or try again.)
Thank you for all your work!

Commit language

There are many old commits with title and description in Portuguese.
In order to internationalize this project, it is important to translate into English.

Update README.md file

  • Add image and description about wiring;
  • Change ultrasound for ultrasonic (to help with library searches)
  • Add link to download of .zip;
  • Stylize text (add bold and italic where necessary, highlighting important words);
  • Update link to twitter of author.

Library doesn't work with new Seead Ultrasonic Distance Ranger V2

Describe the bug
Code loads, Serial monitor prints line statements but measurement value is always 0

Code to reproduce

#include <Ultrasonic.h>

Ultrasonic myUltrasonicSensor(5);
int distance;

void setup() {
  Serial.begin(9600);
}

void loop() {
  // Pass INC as a parameter to get the distance in inches
  distance = myUltrasonicSensor.read();
  
  Serial.print("Distance in CM: ");
  Serial.println(distance);
  delay(1000);
}

Wiring
Connected to a Seead Senor Shield

Expected behavior
As Sensor is moved distance value should show distance to object

Error message
none

Context (please complete the following information):

  • OS: [e.g. Windows x64]
  • IDE version: [e.g. Arduino 1.8.5]
  • Sensor: [e.g. HC-SC04]
  • Library version [e.g. 2.1.0]

Update the sample file

There are minor fixes to be made to this file:

  • Line size;
  • Spelling of the author's name;
  • Document that by passing INC as a parameter to the distanceRead() method it will be possible to obtain the distance in inches;
  • Update library site;
  • Document that pins are not necessarily 12 and 13;
  • Define update date (after creation date);

Translate README to PT-BR

Translate README file to Brazilian portuguese

Description
The README.md file is available in English only. To expand the reach of this lib, it is important that it be available in other languages.

Enable the change of sound velocity constants

Currently the constants referring to sound speed can not be modified by the API, just by modifying the code manually.
Consider allowing the value to be passed as a parameter, as a setting.

Consider suspending the use of classes and adopting structures

Classes are useful, but their performance is less than using structs (given due proportions).
Therefore, it may be interesting to adopt the use of structs where classes are used today. Considering that one of the objectives of this library is to be minimal and optimized, consuming as few resources as possible.

Create library.properties file

The latest Arduino library specification recommends that there be a library.properties file at the root of the project.
This file should follow the pattern specified here.

Translate README to ES

Translate README file to Spanish.

Description
The README.md file is available in English only. To expand the reach of this lib, it is important that it be available in other languages.

Add WProgram.h to .h

Old IDEs of Arduino haven't support to Arduino.h library.
To keep the most hight compatibility, is important to use the #include <WProgram.h> code block.

Update documentation comments with shorter texts

The comments are very long, in some cases taking up 10 lines.

To improve readability, I recommend putting only references to the latest update. The history of who created or contributed is already registered on GitHub itself.

Time the distance calculation is based on

Why is the time of the answer on the echo-Pin used for distance calculations?? The resulting values are fluctuating strongly.
They are also far worse than calculations based on the runtime of the plus?
This design decision seems to be a "wrong" choice. I noticed this while using the library and couldn't isolate the fluctuating measurements I got while using the sensor because it came from this library with over 1500 uses on Platform IO.
I am somewhat puzzled that the way the time is measured can at all be used for distance calculations!!

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.