Skip to content

jihoonkimtech/UltraSonic_Lib

Repository files navigation

UltraSonic_Lib

Library for UltraSonic Distance Sensor.

KOREAN VERSION


arduino-library-badge
NPM Version Build Status

Follows the MIT license ( Please check LICENSE file for more information. )


Function and How to Use

Code

Library Import

  • in case of Library file in Arduino/Library folder
    #include <UltraSonic.h>
  • In case of Library file in Source code file
    #include <"UltraSonic_Lib/UltraSonic.h">

Create Object

  • FOUR PIN TYPE
    UltraSonic us_sensor(FOUR_PIN, (int)TRIG, (int)ECHO);
    // us_sensor is object name
    // pinType = FOUR_PIN (TRIG pin, ECHO pin)
  • THREE PIN TYPE
    UltraSonic us_sensor(THREE_PIN, (int)SIG);
    // us_sensor is object name
    // pinType = THREE_PIN (only SIG pin)

Function

  • mesureDist (int ms = 0, int legthType = 1)
    float distance = 0;
    distance = us_sensor.mesureDist();
    //return measured distance value(float type)

    distance = us_sensor.mesureDist(1000);
    //return and then delay 1000 ms

    distance = us_sensor.mesureDist(0 , CM);
    //return centimeter type
    //legthType = CM = 0, FEET, INCH, MM, METER
  • distPrint (int ms = 0, int legthType = 1)
    Serial.begin(baud_rate);
    us_sensor.distPrint();
    //print measured distance value
    //"distance : (distance value) (legth type)"

    us_sensor.distPrint(1000);
    //print and then delay 1000 ms

    us_sensor.distPrint(0, CM);
    //print centimeter type
    //"distance : (distance value) CM"
  • sensing (int legthType)
    sensing(legthType);
    //Renew distance value inside object

Hardware

  • Supports the sensors below.

    • HC-SR04 (datasheet in /doc/HCSR04.pdf)
    • all TRIG, ECHO Type UltraSonic Sensor
  • The boards below are supported.

    • Test Finished.
      • Arduino UNO
      • Arduino MEGA
      • Arduino NANO
    • Support Forecast
      • All boards using Arduino IDE

Example

The contents of the example are see Exemples folder.


Update History

  • 1.0.1
    • fix: Change default length type to CM(centimeter)
  • 1.0.0
    • First official version
    • fix: Combine function (distByFloat + distByInt -> mesureDist).
    • feat: Add length_type, pin_type.
  • 0.0.2 (demo)
    • fix: Combine unnecessarily separate function.
  • 0.0.1 (demo)
    • Start of Develop.
    • Register with Library Manager.
    • feat: Add distByFloat(),(int ms) / distByInt(),(int ms) / distPrint(),(int ms).

Information

Maker

About

Library for UltraSonic distance sensor (HC-SR04)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages