There are 4 pins on the module: VCC , Trig, Echo, and GND . To use the sensor: pull the Trig pin to high level for more than 10us to trigger an impulse. The module will begin sending ultrasonic pulses. If an object is detected in front of the sensor the Echo pin will rise to a logic high level. The distance between the sensor and the object can then be calculated using the equation below.
*
M1 |
M2 |
|
|
NC |
NC |
GPIO |
Trig, Echo |
NC |
R8(10K) |
I2C |
SCL , SDA |
R7(10K) |
NC |
UART |
TX , RX |
R7(10K) |
R8(10K) |
1-Wire |
Trig(I/O) |
*
//--------------------- GPIO (Trig Echo) --------------------
/*
Module: RCWL-9610,RCWL-9600,RCWL-9620 16MM Split Type Open Type Ultrasonic Ranging Module
Version: V2.0
Date: 20220710
Master chip: RCWL-9610
Function: In GPIO mode, RCWL-9610 ultrasonic ranging module measures distance and displays it on the serial port
Notice: Module default GPIO mode
Write: Wuxi Richen IoT Technology Co., Ltd.
Test board: RCWL-3310
Program customization: 13915288564
Connection :
-VCC = 3.3V/5.5V
-Trig_RX_SCL_I/O = A5
-Echo_TX_SDA = A4
-GND = GND
*/
float distance;
const int echo=A4; // echo to A4 pin
const int trig=A5; // trig connected to pin A5
void setup()
{
Serial.begin(9600); //Baud rate 9600
pinMode(echo,INPUT); //Set echo as input pin
pinMode(trig,OUTPUT); //Set trig as output pin
Serial.println("RCWL-9610-GPIO Ranging start:");
}
void loop()
{
digitalWrite(trig,HIGH);
delayMicroseconds(500);
digitalWrite(trig,LOW); // Trig pin outputs 10US high level pulse trigger signal
distance = pulseIn(echo,HIGH); // Count the received high time
distance = distance*340/2/10000; // Calculation distance
// 1: speed of sound: 340M/S
// 2: actual distance is 1/2 speed of sound distance
// 3: counting clock is 1uS
// temperature compensation formula:
// c=(331.45+0.61t/℃)ms-1 (where 331.45 is at 0 Spend)
Serial.print("distance: ");
Serial.print(distance); // Serial port output distance signal
Serial.print("CM");
Serial.println(""); // new line
delay(20); // After a single measurement is completed,
// add a 30mS delay before the next measurement.
// To prevent the aftermath of the last measurement
// When measuring at close range, resulting in inaccurate measurement.
delay(100); // Delay 200mS to measure again, delay is not necessary
}
*
*
//-------------------------- UART (TX RX) -----------------------
/*
module: RCWL-9610,RCWL-9600,RCWL-9620 16MM Split Type Open Type Ultrasonic Ranging Module
Version: V2.0
date: 20220710
Master chip: RCWL-9610
Function: RCWL-9610 ultrasonic distance measuring module distance measurement and serial port display in UART mode
Notice: Need to set the module in UART mode
test board: RCWL-3310
write: Wuxi Richen IoT Technology Co., Ltd.
Program customization: 13915288564
I2C data format: The IIC of RCWL-9610 outputs three 8BIT data, and the distance MM
value = 24-bit data is converted into decimal/10000.
connection :
-VCC = 3.3V/5.5V
-Trig_RX_SCL_I/O = A5
-Echo_TX_SDA = A4
-GND = GND
*/
#include "SoftwareSerial.h"
SoftwareSerial mySerial(A4, A5); // A4 is RX, A5 is TX; A4 is connected to module TX, A5 is connected to module RX
float Data_h = 0; // 16-23bit
float Data_m = 0; // 8-15bit
float Data_l = 0; // 0-7 bits
float distance = 0; // Distance data decimal value
void setup()
{
Serial.begin(9600); //Define serial port baud rate 9600 Factory default baud rate 9600
mySerial.begin(9600); //Define the analog serial port baud rate
Serial.println("RCWL-9610-UART Ranging start:");
}
void loop()
{
Data_h = 0;
Data_m = 0;
Data_l = 0;
distance=0; //Initialize three 8BIT distance data and the distance value is 0
mySerial.flush(); //Clear analog serial port cache data
mySerial.write(0XA0); //Send the start ranging command 0XA0, 0XA0 is the start test command data
delay(150); //Measurement cycle delay, one cycle is 120mS, set 150MS, leave a margin
if (mySerial.available()>0) //Wait for 3 data to be received
{
Data_h= mySerial.read(); //read cached data
Data_m= mySerial.read();
Data_l= mySerial.read();
}
else
{
Data_h= 0; //The cache data cannot be read, and the data is cleared to 0
Data_m= 0;
Data_l= 0;
}
distance=(Data_h*65536+Data_m*256+Data_l)/10000; //Calculated as CM value
Serial.print("Distance:"); //Remove the "Distance:" and "CM" to draw on the serial port
if ((1<=distance)&&(900>=distance)) //Numerical display between 1CM-9M
{
Serial.print(distance);
Serial.print("CM"); //The serial port outputs the distance data, remove the "distance:" and "CM" to draw the serial port
}
else
{
Serial.println();
Serial.print(Data_h);
Serial.println();
Serial.print(Data_m);
Serial.println();
Serial.print(Data_l);
Serial.println();
Serial.print(" - - - - "); //Invalid value Numerical display - - - -
}
Serial.println(); //new line
delay(20); // After a single measurement is completed,
// add a 30mS delay before the next measurement.
// To prevent the aftermath of the last measurement
// when measuring at close range, resulting in inaccurate measurement.
delay(100); // Delay 200mS to measure again, delay is not necessary
}
*
*
//-------------------------- I2C (SDA, SCL) -------------------------------------
/*
module: RCWL-9610,RCWL-9600,RCWL-9620 16MM Split Type Open Type Ultrasonic Ranging Module
Version: V2.0
date: 20220710
Master chip: RCWL-9610
Function: RCWL-9610 ultrasonic distance measuring module distance measurement and serial port display in IIC mode
Notice: Need to set the module in IIC mode
test board: RCWL-3310
write: Wuxi Richen IoT Technology Co., Ltd.
Program customization: 13915288564
I2C data format: The IIC of RCWL-9610 outputs three 8BIT data, and the distance MM
value = 24-bit data is converted into decimal/10000.
connection :
-VCC = 3.3V/5.5V
-Trig_RX_SCL_I/O = A5
-Echo_TX_SDA = A4
-GND = GND
*/
#include "SoftwareSerial.h"
#include "Wire.h"
float distance = 0; // Distance data decimal value
float ds[3]; // [3] 8BIT distance data
void setup()
{
Serial.begin(9600); //Define serial port baud rate 9600 Factory default baud rate 9600
Wire.begin();
Serial.println("RCWL-9610 ranging start:");
}
void loop()
{
char i = 0;
ds[0]=0;
ds[1]=0;
ds[2]=0; // Initialize three 8BIT distance data as 0
Wire.beginTransmission(0x57); // The address is 0X57, write 8-bit data as AE, and read 8-bit data as AF
Wire.write(1); // Write command 0X01, 0X01 is the start measurement command
Wire.endTransmission(); // I2C end command
delay(150); //Measurement cycle delay, one cycle is 120mS, set 150MS, leave a margin
Wire.requestFrom(0x57,3); //The address is 0X57 to read three 8-bit distance data
while (Wire.available())
{
ds[i++] = Wire.read();
}
distance=(ds[0]*65536+ds[1]*256+ds[2])/10000; //Calculated as CM value
Serial.print("distance:");
if ((1<=distance)&&(distance<=900)) // Numerical display between 1CM-9M
{
#if 0
Serial.println();
Serial.print(ds[0]);
Serial.println();
Serial.print(ds[1]);
Serial.println();
Serial.print(ds[2]);
Serial.println();
#endif //#if 1, output 3 distance data of I2C
Serial.print(distance);
Serial.print(" CM ");
}
else
{
Serial.println();
Serial.print(ds[0]);
Serial.println();
Serial.print(ds[1]);
Serial.println();
Serial.print(ds[2]);
Serial.println();
Serial.print(" - - - - "); //Invalid value Numerical display - - - -
}
Serial.println(); //new line
delay(20); // After a single measurement is completed,
// add a 30mS delay before the next measurement.
// To prevent the aftermath of the last measurement
// when measuring at close range, resulting in inaccurate measurement.
delay(100); // Delay 200mS to measure again, delay is not necessary
}
*
*
*
*
//-------------------------- 1 Wire (Trig I/O) ------------------------------
/*
Module: RCWL-9610,RCWL-9600,RCWL-9620 16MM Split Type Open Type Ultrasonic Ranging Module
Version: V2.0
Date: 20220710
Master chip: RCWL-9610
Function: RCWL-9610 ultrasonic distance measuring module distance measurement and serial port display in single bus mode
Notice: Need to set the module in 1-WIRE mode (R7 R8 = 10K)
Write: Wuxi Richen IoT Technology Co., Ltd.
Test board: RCWL-3310
Program customization: 13915288564
Connection :
-VCC = 3.3V/5.5V
-Trig_RX_SCL_I/O = A5
-Echo_TX_SDA NC (not connect)
-GND = GND
*/
float distance;
const int trig_echo=A5; //Trig_RX_SCL_I/O connected to A5 pin
void setup()
{
Serial.begin(9600); //Define serial port baud rate 9600 Factory default baud rate 9600
pinMode(trig_echo,OUTPUT); //Set Trig_RX_SCL_I/O as output
Serial.println("RCWL-9610-1-WIRE Ranging start:");
}
void loop()
{
pinMode(trig_echo,OUTPUT); //Set Trig_RX_SCL_I/O as output
digitalWrite(trig_echo,HIGH);
delayMicroseconds(10);
digitalWrite(trig_echo,LOW); //Trig_RX_SCL_I/O pin outputs 10US high level pulse trigger signal
pinMode(trig_echo,INPUT); //Set Trig_RX_SCL_I/O as the input to receive the distance signal fed back by the module
distance = pulseIn(trig_echo,HIGH); //Count the received high time
//Serial.print("Original value: ");
//Serial.print(distance);
distance = distance*340/2/10000; // Calculation distance
// 1: speed of sound: 340M/S
// 2: actual distance is 1/2 speed of sound distance
// 3: counting clock is 1US// temperature compensation formula: c=(331.45+0.61t/℃)ms-1
// (where 331.45 is at 0 degrees
Serial.print("distance: ");
Serial.print(distance);
Serial.println("CM"); //Serial port output distance signal
//digitalWrite(trig_echo,LOW);
pinMode(trig_echo,OUTPUT); // Set Trig_RX_SCL_I/O as output, ready for next measurement
//Serial.println(""); // new line
delay(20); // After a single measurement is completed,
// add a 30mS delay before the next measurement.
// To prevent the aftermath of the last measurement
// When measuring at close range, resulting in inaccurate measurement.
delay(100); // Delay 200mS to measure again, delay is not necessary
}
//------------------------------------------------------------------------
https://docs.arduino.cc/built-in-examples/sensors/Ping/
M1 --- R10K ---GND
M2 --- R10K --- GND
/*
Ping))) Sensor
This sketch reads a PING))) ultrasonic rangefinder and returns the distance
to the closest object in range. To do this, it sends a pulse to the sensor to
initiate a reading, then listens for a pulse to return. The length of the
returning pulse is proportional to the distance of the object from the sensor.
The circuit:
- +V connection of the PING))) attached to +5V
- GND connection of the PING))) attached to ground
- SIG connection of the PING))) attached to digital pin 7
----------------------------------------------------
Module: RCWL-9610,
-VCC = 3.3V/5.5V
-Trig_RX_SCL_I/O = attached to digital pin 7
-Echo_TX_SDA = NC (not connect)
-GND = attached to ground
M1 --- R10K ---GND
M2 --- R10K --- GND
-----------------------------------------------------
created 3 Nov 2008
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/Ping
https://docs.arduino.cc/built-in-examples/sensors/Ping/
https://wiki.seeedstudio.com/Ultra_Sonic_range_measurement_module/
Parallax PING))) Ultrasonic Sensor
*/
// this constant won't change. It's the pin number of the sensor's output:
const int pingPin = 7;
void setup() {
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// establish variables for duration of the ping, and the distance result
// in inches and centimeters:
long duration, inches, cm;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH pulse
// whose duration is the time (in microseconds) from the sending of the ping
// to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
}
long microsecondsToInches(long microseconds) {
// According to Parallax's datasheet for the PING))), there are 73.746
// microseconds per inch (i.e. sound travels at 1130 feet per second).
// This gives the distance travelled by the ping, outbound and return,
// so we divide by 2 to get the distance of the obstacle.
// See: https://www.parallax.com/package/ping-ultrasonic-distance-sensor-downloads/
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds) {
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the object we
// take half of the distance travelled.
return microseconds / 29 / 2;
}







