Home Code Arduino and US – 100 ultrasonic ranging module serial data mode example

Arduino and US – 100 ultrasonic ranging module serial data mode example

by shedboy71
[lebox id="1"]

US – 100 ultrasonic ranging module can be realized 2cm ~ 450cm of non-contact distance measurement function, with 2.4V to 4.5V wide voltage input range, the static function GPIO, serial variety of communication methods, within the band watchdog, stable and reliable.

This module is improved, the module itself has temperature compensation, the accuracy of the highest module now clean out treasure, absolute stable, economical, practical 20 * 45 mm module circuit 15 mm thick
US-100 ultrasonic ranging module can realize 2 cm ~ 4.5 m non-contact ranging function, with a 2.4 ~ 5.5 V of wide voltage input range, static power consumption less than 2 mA, bring their own temperature sensor calibration on the ranging results, and has GPIO, serial ports and so on many kinds of communication mode, inside take watchdog, stable and reliable.

Specification:

Voltage: DC 2.4V – 5V
Quiescent current: < 2mA
Output mode: level or UART
Induction angle: < 15°
Detection distance: 2cm – 450cm
Precision: 0.3cm ± 1%
Working temperature: -20°C to +70°C
Size: 45 x 20 x 1.6mm

 

1. VCC: 5V DC
2. Trig: trigger input
3. Echo: pulse output
4. GND: ground
5. GND: ground

 

Connection

Module Connection Arduino Connection
VCC 5v
GND GND
Trig TX (Pin 1)
Echo RX (Pin 0)

 

Code

[codesyntax lang=”cpp”]

// RX (Pin 0 of Arduino digital IO) to Echo
// TX (Pin 1 of Arduino digital IO) to Trig 
unsigned int HighLen = 0;
unsigned int LowLen  = 0;
unsigned int Len_mm  = 0;

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

void loop() 
{
    Serial.flush();                               
    Serial.write(0X55);                           // trig US-100 begin to measure the distance
    delay(500);                                   
    if(Serial.available() >= 2)                   // receive 2 bytes 
    {
        HighLen = Serial.read();                   // High byte of distance
        LowLen  = Serial.read();                   // Low byte of distance
        Len_mm  = HighLen*256 + LowLen;            // Calculate the distance
        if((Len_mm > 1) && (Len_mm < 10000))       // normal distance should between 1mm and 10000mm (1mm, 10m)
        {
            Serial.print("Present Length is: ");   
            Serial.print(Len_mm, DEC);             
            Serial.println("mm");                  
        }
    }
    delay(500);                                   
}

[/codesyntax]

 

Output

UUUPresent Length is: 58mm
UPresent Length is: 57mm
UPresent Length is: 58mm
UPresent Length is: 58mm
UUUUPresent Length is: 53mm
UPresent Length is: 57mm
UUUUPresent Length is: 78mm

 

Link

1 pc US-100 Ultrasonic Sensor Module With Temperature Compensation Range Distance 450cm For Arduino

Share
[lebox id="2"]

You may also like

Leave a Comment