Water-proof Ultrasonic Sensor (ULA) Wiki - DFRobot

SEN0301 Water-proof Ultrasonic Sensor (ULA)

Introduction

This is an ultrasonic distance sensor(ULA) 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.

There are two output modes for the sensor: RS232 output and voltage analog output. The default mode of the product is RS232 output, and it can be changed through the button.

Features

Specification

SEN0301 Water-proof Ultrasonic Sensor (ULA)

Dimension Diagram

SEN0301 Water-proof Ultrasonic Sensor (ULA) Dimension Diagram

Output Format

SEN0301 Water-proof Ultrasonic Sensor (ULA) Output Format
Num Pin Description
1 VCC 5V~12V Power input
2 RX Receive serial data under RS232 mode
3 TX Output serial data under RS232 mode
4 Vout Output Voltage under voltage analog mode
5 GND Ground

RS232 Output

If currently it is not in the RS232 output 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.

Every time the controller is powered on, it will automatically start detecting with 500ms working period, and "3.TX" will output one frame serial data.

If the input pin "2.RX" receives the correct serial command, the controller will output data under the control of the command. When receiving commands once, the controller will be triggerred once and output one frame serial data. But the trigger period must be over 60ms.

To distinguish between different controllers, users can change the addresses of different controllers through the corresponding instruction code. It won't be lost when powered down.

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 Controller Address(0x01 default) Distance Data High Distance Data Low Temperature Data High Temperature Data Low Checksum
0xFF Add Data_H Data_L Temp_H Temp_L SUM

Distance Calculation

Distance=Data_H*256+Data_L

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

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

Example for Auto-output

SEN0301 Water-proof Ultrasonic Sensor (ULA) Output Format

Note: T1=T2=T3=500ms

Example for Controlled Output

SEN0301 Water-proof Ultrasonic Sensor (ULA) Output Format

Note: T1=1~55ms

Example 1

Read the distance and temperature of the controller whose address is 0x01.

Frame Header Add Control Command SUM
Host sends 0xFF 0x01 0x01 0x01
Frame Header ID Controller Address(0x01 default) Distance Data High Distance Data Low Temperature Data High Temperature Data Low Checksum
Slave sends back 0xFF Add Data_H Data_L Temp_H Temp_L SUM

Example 2

Change the controller address to 0x05

Frame Header Add Control Command SUM
Host sends 0xFF 0x05 0x03 0x07
Frame Header Add Control Command SUM
Slave sends back 0xFF 0x05 0x03 0x07

After the above instruction done, the controller address will be changed into: Add=0x05. The control command is 0x03, which is used to change address.

Voltage Analog Output

Switch to Voltage analog output mode

Switch to the voltage analog output mode by short-pressing. When successfully switched, the LED flashes blue once, stop 1 second, and flashed once again.

The controller will automatically detect distance with 500ms period and output voltage in proportion to the detected distance.

Voltage vs Distance

SEN0301 Water-proof Ultrasonic Sensor (ULA) Voltage vs Distance

Calculation

Under voltage analog output mode, read the output voltage from the pin "4.Vout", then we can calculate the related distance. The controller's voltage from 0.0V to 3.30V corresponds with the distance from 0-330cm, which also means 0.01V is equal to 1cm. When the detected distance is larger than 330cm or no object is detected, it outputs 3.30V voltage.

ULA Tutorial

Requirements

Connection Diagram

SEN0301 Water-proof Ultrasonic Sensor (ULA) 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;// For storing data read from the serialport
unsigned char buffer_RTT[7] = {};
unsigned char buffer_coderead[]{0xFF,0x01,0x01,0x01};
int Rage = 0;
float Temp = 0;
int Tflag = 0;
void setup() {
        Serial.begin(57600);     // Enable serial port and set band rate to 57600 bps
        mySerial.begin(9600);
        pinMode(LED_BUILTIN, OUTPUT);
        digitalWrite(LED_BUILTIN, HIGH);
}

void loop(){
         do{ 
           for (int j = 0; j <= 6; j++){
                col = mySerial.read();
                buffer_RTT[j] = (char)col;
                }      
        } while(mySerial.read() == 0xFF);
                mySerial.flush();
                if(buffer_RTT[0]==0xFF){//Judge the first bit of the data
                  int cor;
                  cor=buffer_RTT[0]+buffer_RTT[1]+buffer_RTT[2]+buffer_RTT[3]+buffer_RTT[4]+buffer_RTT[5];
                  cor=cor&0x00FF;
                  if(buffer_RTT[6]==cor)
                  {                     
                  Rage = (buffer_RTT[2] << 8) + buffer_RTT[3];
                  Tflag=  buffer_RTT[4]&0x80;
                  if(Tflag==0x80){
                  buffer_RTT[4]=buffer_RTT[4]^0x80;  
                  }
                  Temp = (buffer_RTT[4] << 8) + buffer_RTT[5];
                  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("============================== ");  
                delay(100);       
        }                
SEN0301 Water-proof Ultrasonic Sensor (ULA) Result

Voltage Analog 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
int analogPin = 0;//Define analog pin 0
int val = 0;
void setup() {
        Serial.begin(57600);     // Enable serial port  and set band rate to 57600 bps
        mySerial.begin(9600);
        pinMode(LED_BUILTIN, OUTPUT);
        digitalWrite(LED_BUILTIN, HIGH);
}

void loop() {      
        val = analogRead(analogPin);// Read analog port value
        float voltage= val* (3.3/1023);//Convert data
        Serial.print("Vout:");
        Serial.print(voltage);
        Serial.println("m");
        delay(200);  
        }  
SEN0301 Water-proof Ultrasonic Sensor (ULA) Result

FAQ

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

More Documents