MIT License

项目介绍

ErickSimoes/Ultrasonic 是一个托管在 GitHub 上的开源项目,主要使用 C++ 编写,采用 MIT License 许可证,目前获得 145 个 Star、70 次 Fork。

仓库全名
ErickSimoes/Ultrasonic
开源许可证
MIT License
Star 数
145
Fork 数
70
未关闭 Issue
11

README 摘要

🇬🇧 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…

完整内容见 GitHub 原始 README 或本页 。

常见问题

Ultrasonic 用什么语言开发?

主要使用 C++ 编写,采用 MIT License 许可证,目前有 145 个 Star。

Ultrasonic 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 Ultrasonic 的源码?

可以直接克隆仓库:git clone https://github.com/ErickSimoes/Ultrasonic.git,默认分支为 master;安装与运行步骤见仓库 README。

Ultrasonic 最近还在维护吗?

仓库最近一次更新为 2月25日,当前有 11 个未关闭 Issue;Star 数为 145,可作为社区活跃度的参考。

关于

Minimalist library for Ultrasonic Module HC-SR04, PING))) and Seeed SEN136B5B to Arduino

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
295
价值分
108
活跃状态
活跃

README

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.

评论

暂无评论