SEN0300 Water-proof Ultrasonic Sensor (ULS)

Introduction

This is an ultrasonic distance sensor(ULS) of high performance with an enclosed waterproof probe. The sensor, like many other ultrasonic sensors, based on the principle of ultrasonic echo ranging, determines the distance to a target by measuring time lapses between the sending of a pulse and receiving of the echo without contacting. It can be used to detect transparent or non-ferrous objects, metal or non-metallic objects, liquid, solid, powder materials and so on. The unique physical bell-mouth shell of the sensor greatly improves the directivity and stability of its output ultrasound.

Features

Specification

SEN0300 Water-proof Ultrasonic Sensor (ULS) Specification

Dimension Diagram

SEN0300 Water-proof Ultrasonic Sensor (ULS) Dimension Diagram

Operation Instruction

The ultrasonic sensor has three output modes: serial, PWM, switch. The default output mode of the sensor is serial output. Change the mode by pressing or triggering. The indicators will flash in different ways to indicate the corresponding mode.

Button Operation Description

Trigger Signal

Indicator Description

Output Format

SEN0300 Water-proof Ultrasonic Sensor (ULS) Output Format
Num Pin Description
1 VCC 3.3V~12V Power input
2 Trigger Trigger
3 TX/PWM Serial and PWM Output
4 ON-OFFout Switch Output
5 GND Ground

Serial Output

The default output mode of the product is serial mode. If currently it is not in the serial mode, you can switch to this mode by short-pressing. when successfully switched, the LED flashes blue three times, stop 1 second and flashes three times again.

When the trigger pin "2.Trigger" is at falling edge and the Low level is kept for 0.1-10ms, the controller will be triggerred once, and the output pin "3.TX/PWM" will output one frame serial data of 3.3V TTL with temperature compensation. The trigger period of the controller must be over 60ms.

SEN0300 Water-proof Ultrasonic Sensor (ULS) Serial Output

Note: T1=0.1-10ms; T2=4-6ms; T3=1-55ms

Command frame format of serial communication

Interface Type Start byte Data byte Stop byte Parity check Band rate
Full duplex 1 8 1 None 9600

Output frame format

Frame Header ID Distance Data High Distance Data Low Temperature Data High Temperature Data Low Checksum
0xFF Data_H Data_L Temp_H Temp_L SUM

Distance Calculation

Distance=Data_H*256+Data_L (Unit: mm)

Temperature Calculation

When the highest bit of Temp_H is 0, the temperature value is positive; when it is 1, the temperature value is negative.

If Temp_H=0x01=0b0000 0001, the most highest bit is 0, which means the temperature value is positive.

Temperature=Temp _H*256+ Temp _L

Eg: the temperature value is 281 when converted to decimal; The currently detected temperature is 28.1℃. (Unit: ℃)

Checksum Calculation

Note: just reserve the eight lower bits of the accumulated value of checksum.

SUM=(frame header+ Data_H+ Data_L+ Temp_H+ Temp_L)&0x00FF

PWM Output

Switch to PWM mode by short-pressing the button. When succeeded, the LED flashes blue once, wait 1 second, then flash once again.

When the trigger pin "2.Trigger" is at falling edge and the Low level is kept for 0.1-10ms, the controller will be triggerred once and the output pin "3.TX/PWM" will output PWM signal of 3.3V TTL. The trigger period of the controller must be over 60ms.

Output Principle

When the trigger pin received the falling edge trigger level, the module will emit 40kHz ultrasound, at the same time, the output pin "3.TX/PWM" will be pulled up. when it detected the echo signal, the output pin will be pulled down immediately. When it did't detect any objects, the output pin will be pulled down to stop detecting after 55ms, and there is no temperature compensation in this process.

Use MCU to judge the time of high level, which also is the time for the ultrasound to travel between the module and the detected object. The distance can be calculated then when we get the ultrasound velocity and the time.

SEN0300 Water-proof Ultrasonic Sensor (ULS) PWM Output

Note: T1=0.1-10ms; T2=4-6ms; T3=1-55ms

Calculation

Distance=High level time×Velocity(340m/s)/2, us/58=cm or us/148=inch; in different temeprature, the velocity of the ultrasound: v=332+0.6t(m/s). If the controller did't detect any objects, the output pin will output constant pulse width for 55ms.

Switch Output

When the trigger pin "2.Trigger" is at low level or grounded, the controller will be in Switch mode, and automatically starts detecting with 250ms working period. Compare the detected value with the pre-set threshold value so as to control the output state of the switch.

Set the threshold value

Step 1: evaluate the threshold distance value, put an object or baffle at the distance equal to the preset threshold distance. For instance, when we set the threshold vlaue to 3m, then we need to place a flat baffle at 3m away. Level the baffle on the ground to form an open field so as to assure the detection accuracy.

Step 2: direct the controller at the object or the flat baffle, long-press for 3 seconds above. When the LED flashed red and blue alternately, the setting is done. The controller will remember the currently detected distance and take it as the threshold value. Continue to long-press the button if you need to reset the threshold value.

Output State

Case 1: if the detected value is smaller than the preset threshold, the output pin "4.ON-OFFout" output low value, at the same time, the LED emits red.

Case 2: if the detected vaule is bigger than the perset threshold, "4.ON-OFFout" output pull-up high level and the LED turns off.

ULS Tutorial

Requirements

Connection Diagram

SEN0300 Water-proof Ultrasonic Sensor (ULS) Connection Diagram

warning_yellow.png Note: the internal probe surface is regarded as the detecting starting point by default. If you take the plane of the bell-mouth as starting point, then the distance will be the detected distance minus 40mm.

Read serial port data

* **************************************************** 
* @brief Water-proof Ultrasonic Sensor (ULS)

 * @copyright    [DFRobot](https://www.dfrobot.com), 2016
 * @copyright    GNU Lesser General Public License

* @author [Xiaoyu](Xiaoyu.zhang@dfrobot.com)
* @version  V1.0
* @date  2019-03-11

* GNU Lesser General Public License.
* All above must be included in any redistribution
* ****************************************************/
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
char col;
unsigned char buffer_RTT[6] = {};
int Rage = 0;
float Temp = 0;
int Tflag = 0;
void setup() {
        Serial.begin(57600);     // Enable the serial port and set the band rate to 57600 bps
        mySerial.begin(9600);
        pinMode(LED_BUILTIN, OUTPUT);
        digitalWrite(LED_BUILTIN, HIGH);
}
void loop() {
        digitalWrite(LED_BUILTIN, HIGH);
        delay(100); 
        digitalWrite(LED_BUILTIN, LOW);
        delay(4);
        digitalWrite(LED_BUILTIN, HIGH);    
        do{ 
           for (int j = 0; j <= 5; j++){
                col = mySerial.read();
                buffer_RTT[j] = (char)col;
                }      
        } while(mySerial.read() == 0xff);
                mySerial.flush();
                if(buffer_RTT[0]==0xff){
                  int cor;
                  cor=(buffer_RTT[0]+buffer_RTT[1]+buffer_RTT[2]+buffer_RTT[3]+buffer_RTT[4])&0x00FF;//Check
                  if(buffer_RTT[5]==cor)
                  {
                  Rage = (buffer_RTT[1] << 8) + buffer_RTT[2];
                  Tflag=  buffer_RTT[3]&0x80;
                  if(Tflag==0x80){
                  buffer_RTT[3]=buffer_RTT[3]^0x80; 
                  }
                  Temp = (buffer_RTT[3] << 8) + buffer_RTT[4];
                  Temp = Temp/10;
                  }
                  else{
                    Rage = 0;
                    Temp = 0;
                     }
                 }
                Serial.print("Rage : ");
                Serial.print(Rage);//Output distance unit mm
                Serial.println("mm");
                Serial.print("Temperature: ");
                if(Tflag ==0x80)
                {
                  Serial.print("-");           
                }
                Serial.print(Temp);//Output temperature
                Serial.println("℃");
                Serial.println("============================== ");
           }  
SEN0300 Water-proof Ultrasonic Sensor (ULS) Read serial port data

PWM Output

* **************************************************** 
* @brief Water-proof Ultrasonic Sensor (ULS)

 * @copyright    [DFRobot](https://www.dfrobot.com), 2016
 * @copyright    GNU Lesser General Public License

* @author [Xiaoyu](Xiaoyu.zhang@dfrobot.com)
* @version  V1.0
* @date  2019-03-11

* GNU Lesser General Public License.
* All above must be included in any redistribution
* ****************************************************/
#include <SoftwareSerial.h>
char col;// for storing the data read from the serial port
unsigned long duration;
int datapin = 10;
int val = 0;
void setup() {
        Serial.begin(57600);     //Enable the serial port and set band rate to 57600 bps
        pinMode(LED_BUILTIN, OUTPUT);
        pinMode(datapin, INPUT);
        digitalWrite(LED_BUILTIN, HIGH);
}

void loop(){
        digitalWrite(LED_BUILTIN, HIGH);
        delay(57); 
        digitalWrite(LED_BUILTIN, LOW);
        delay(4);                         //give level signal          
        duration = pulseIn(datapin, HIGH);//read the high level pulse on the pin, the maximum pulse interval is 55ms; assign the result to the variable "duration"
        delay(3);
        digitalWrite(LED_BUILTIN, HIGH);//Pull up the signal pin 
        duration = duration/ 58.00; //convert time to distance    
        Serial.print(duration);//serial port print data
        Serial.println("cm");
        Serial.println("=========== ");        
        } 
SEN0300 Water-proof Ultrasonic Sensor (ULS) Read PWM Output

Switch Output

* **************************************************** 
* @brief Water-proof Ultrasonic Sensor (ULS)

 * @copyright    [DFRobot](https://www.dfrobot.com), 2016
 * @copyright    GNU Lesser General Public License

* @author [Xiaoyu](Xiaoyu.zhang@dfrobot.com)
* @version  V1.0
* @date  2019-03-11

* GNU Lesser General Public License.
* All above must be included in any redistribution
* ****************************************************/
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
unsigned char buffer_RTT[7] = {};
unsigned long duration;
int datapin = 9;
void setup() {
        Serial.begin(57600);     // Enable serial port and set band rate to 57600 bps
        mySerial.begin(9600);
        pinMode(LED_BUILTIN, OUTPUT);
        pinMode(datapin, INPUT);
        digitalWrite(LED_BUILTIN, HIGH);
}

void loop() {
        digitalWrite(LED_BUILTIN, LOW);//give low level
        duration = digitalRead(datapin);//read pin state 
        delay(3);
        switch(duration){
        case 0 :Serial.println("LOW"); break;//the distance to the object is less than the preset distance, set the defalut to 1m
        case 1 :Serial.println("HIGH"); break;//the distance to the object is more than the preset distance    
        }          
        }  
SEN0300 Water-proof Ultrasonic Sensor (ULS) Read Switch Output

FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum

More Documents

DFshopping_car1.png Get Water-proof Ultrasonic Sensor (ULS) from DFRobot Store or DFRobot Distributor.

Turn to the Top