_SKU_SEN0310_URM12_ultrasonic_sensor_1500cm&RS485_ - jimaobian/DFRobotWikiCn GitHub Wiki
概 述
这是一款针对大量程测距及避障应用设计的超声波传感器,具有长达15米的检测量程,探测角度15°,内置温度补偿,RS485通信接口,适用于液位物位检测或机器人避障等应用。
技术参数
- 工作电压:DC 9-24V
- 额定功率:4.8W
- 有效量程:70 ~ 1500cm
- 距离分辨率:1cm
- 距离误差:±1%
- 温度分辨率:0.1℃
- 温度误差:±1℃
- 测量频率:3HZ
- 工作温度:-10℃~+70℃
- 工作湿度范围:RH<75%
- 传感器声学频率:38~42KHz
- 传感器方向角:15°±2°(-6dB)
- 防护等级:IP65
- 通信接口:RS485
接口说明
模块接口线序如下:
1、黑色粗线-----屏蔽线
2、黑色细线-----GND
3、白 ------VCC
4、橙 ------RS485-A
5、棕 ------RS485-B
寄存器说明
| | | | | | | | | | | | | | | | | | | | | | | | | |
寄存器一览表
SEN0310寄存器读写示例
准备
- 硬件
- 1 x Arduino Leonardo控制板(RS485转TTL需要占用一个串口,推荐使用两个串口以上的设备,示例中用的是Arduino Leonardo,由于Arduino Modbus协议会占用较大内存,所以建议使用Arduino Mega2560控制板)
- 1 x Arduino TTL转485扩展板
- 1 x 直流电源(模块需要DC24V外接供电)
- 1 x USB数据线(USB数据线一端连接Arduino板USB口,另一端连接至电脑USB口)
- 软件
- Arduino IDE, 点击下载Arduino IDE
- 在IDE中打开Library Manager(Ctrl+Shift+I),找到并安装ArduinoModbus和ArduinoRS485两个库
- 硬件接线示意图
读取测量距离示例
该示例演示了被动测距模式下的测距功能。
|
/**************************************************************************************************************
*This code tests the range finder function of the URM12 ultrasonic sensor(1500cm&RS485)
*@ author : [email protected]
*@ data : 30.09.2019
*@ version: 1.0
**************************************************************************************************************/
#include <ArduinoModbus.h>
#include <ArduinoRS485.h>
#define slave_addr 0x0b
#define TEMP_CONFIG_BIT (0x03)
#define MEASURE_MODE_BIT (0x01 << 2)
#define MEASURE_TRIG_BIT (0x01 << 3)
typedef enum
{
PID,
VID,
SLAVE_ADDR,
COM_BAUDRATE,
COM_PARITY_STOP,
DISTANCE,
INTERNAL_TEMP,
EXTERN_TEMP,
CR
} regindex;
volatile uint16_t cr_t = 0;
uint16_t read_data(uint16_t addr_t, uint16_t reg)
{
uint16_t data_t;
if (!ModbusRTUClient.requestFrom(addr_t, HOLDING_REGISTERS, reg, 1))
{
Serial.print("failed to read registers! ");
Serial.println(ModbusRTUClient.lastError());
data_t = 0xffff;
}
else
{
data_t = ModbusRTUClient.read();
}
return data_t;
}
uint16_t write_data(uint16_t addr_t, uint16_t reg, uint16_t data)
{
if (!ModbusRTUClient.holdingRegisterWrite(addr_t, reg, data))
{
Serial.print("Failed to write coil! ");
Serial.println(ModbusRTUClient.lastError());
return 0;
}
else
return 1;
}
void setup() {
ModbusRTUClient.begin(19200);
Serial.begin(9600);
cr_t |= MEASURE_MODE_BIT;// Set bit2
cr_t &= ~(uint16_t)TEMP_CONFIG_BIT;//internal temp compensation
write_data(slave_addr, CR, cr_t); //write CR
delay(100);
}
volatile uint16_t dist_t;
void loop() {
cr_t |= MEASURE_TRIG_BIT;//Set bit3
write_data(slave_addr, CR, cr_t); //write CR
delay(300);// delay 300ms
dist_t = read_data(slave_addr,DISTANCE);
Serial.print("distance = ");
Serial.print(dist_t, 1);
Serial.println("cm");
}
|}
读取板载温度传感器数据示例
|
/**************************************************************************************************************
*This code tests the temperature measurement function of the URM12 ultrasonic sensor(1500cm&RS485)
*@ author : [email protected]
*@ data : 30.09.2019
*@ version: 1.0
*RX(TTL-RS485转接板) -> TX1/D1 (Arduino Leonardo) TX(TTL-RS485转接板)-> RX1/D0 (Arduino Leonardo)
**************************************************************************************************************/
#include <ArduinoModbus.h>
#include <ArduinoRS485.h>
#define slave_addr 0x0b
typedef enum
{
PID,
VID,
SLAVE_ADDR,
COM_BAUDRATE,
COM_PARITY_STOP,
DISTANCE,
INTERNAL_TEMP,
EXTERN_TEMP,
CR
} regindex;
uint16_t read_data(uint16_t addr_t, uint16_t reg)
{
uint16_t data_t;
if (!ModbusRTUClient.requestFrom(addr_t, HOLDING_REGISTERS, reg, 1))
{
Serial.print("failed to read registers! ");
Serial.println(ModbusRTUClient.lastError());
data_t = 0xffff;
}
else
{
data_t = ModbusRTUClient.read();
}
return data_t;
}
uint16_t write_data(uint16_t addr_t, uint16_t reg, uint16_t data)
{
if (!ModbusRTUClient.holdingRegisterWrite(addr_t, reg, data))
{
Serial.print("Failed to write coil! ");
Serial.println(ModbusRTUClient.lastError());
return 0;
}
else
return 1;
}
void setup() {
Serial.begin(9600);
ModbusRTUClient.begin(19200);
}
volatile float temp;
void loop() {
temp = read_data(slave_addr,INTERNAL_TEMP) / 10.0;
Serial.print("internal temp = ");
Serial.print(temp,1);
Serial.println("C");
delay(500);
}
|}
修改模块地址
|
/**************************************************************************************************************
*This code tests the address modification function of the URM12 ultrasonic sensor(1500cm&RS485)
*@ author : [email protected]
*@ data : 30.09.2019
*@ version: 1.0
*RX(TTL-RS485转接板) -> TX1/D1 (Arduino Leonardo) TX(TTL-RS485转接板)-> RX1/D0 (Arduino Leonardo)
**************************************************************************************************************/
#include <ArduinoModbus.h>
#include <ArduinoRS485.h>
#define addr_public 0x00
typedef enum
{
PID,
VID,
SLAVE_ADDR,
COM_BAUDRATE,
COM_PARITY_STOP,
DISTANCE,
INTERNAL_TEMP,
EXTERN_TEMP,
CR
} regindex;
uint16_t cr_t = 0;
uint16_t read_data(uint16_t addr_t, uint16_t reg)
{
uint16_t data_t;
if (!ModbusRTUClient.requestFrom(addr_t, HOLDING_REGISTERS, reg, 1))
{
Serial.print("failed to read registers! ");
Serial.println(ModbusRTUClient.lastError());
data_t = 0xffff;
}
else
{
data_t = ModbusRTUClient.read();
}
return data_t;
}
uint16_t write_data(uint16_t addr_t, uint16_t reg, uint16_t data)
{
if (!ModbusRTUClient.holdingRegisterWrite(addr_t, reg, data))
{
//Serial.print("Failed to write coil! ");
//Serial.println(ModbusRTUClient.lastError());
return 0;
}
else
return 1;
}
void setup() {
Serial.begin(9600);
ModbusRTUClient.begin(19200);
delay(3000);
}
volatile uint16_t addr, res;
void loop() {
addr = 0x11;
res = write_data(addr_public, SLAVE_ADDR, addr);
Serial.print("The device address has been modified as ");
Serial.print(addr);
Serial.println(".please power off and restart the device");
while (1);
}
|}
修改模块波特率
|
/**************************************************************************************************************
*This code tests the baudrate modification function of the URM12 ultrasonic sensor(1500cm&RS485)
*@ author : [email protected]
*@ data : 30.09.2019
*@ version: 1.0
*RX(TTL-RS485转接板) -> TX1/D1 (Arduino Leonardo) TX(TTL-RS485转接板)-> RX1/D0 (Arduino Leonardo)
**************************************************************************************************************/
#include <ArduinoModbus.h>
#include <ArduinoRS485.h>
#define addr_default 0x0B
#define baudrate_default 19200
typedef enum
{
PID,
VID,
SLAVE_ADDR,
COM_BAUDRATE,
COM_PARITY_STOP,
DISTANCE,
INTERNAL_TEMP,
EXTERN_TEMP,
CR
} regindex;
uint16_t cr_t = 0;
uint16_t read_data(uint16_t addr_t, uint16_t reg)
{
uint16_t data_t;
if (!ModbusRTUClient.requestFrom(addr_t, HOLDING_REGISTERS, reg, 1))
{
Serial.print("failed to read registers! ");
Serial.println(ModbusRTUClient.lastError());
data_t = 0xffff;
}
else
{
data_t = ModbusRTUClient.read();
}
return data_t;
}
uint16_t write_data(uint16_t addr_t, uint16_t reg, uint16_t data)
{
if (!ModbusRTUClient.holdingRegisterWrite(addr_t, reg, data))
{
Serial.print("Failed to write coil! ");
Serial.println(ModbusRTUClient.lastError());
return 0;
}
else
return 1;
}
void setup() {
Serial.begin(9600);
ModbusRTUClient.begin(baudrate_default);
delay(3000);
}
volatile uint16_t baudrate_index, res;
void loop() {
baudrate_index = 3;//0x0001---2400 0x0002---4800 0x0003---9600 0x0004---14400
//0x0005---19200 0x0006---38400 0x0007---57600 0x0008---115200 Other----115200
res = write_data(addr_default, COM_BAUDRATE, baudrate_index);
if(res)
Serial.print("The baudrate has been modified as 9600.please power off and restart the device");
while (1);
}
|}
探测角度及灵敏度说明
超声波传感器的物理特性决定了其实际具有不规则的探测区域,因此超声波测距传感器的探测角度难以被准确的定义。在实际使用过程中我们测试发现此该传感器模块的探测区域及灵敏度可能相对于其它超声波传感器要更大,因此在狭窄空间内使用该款传感器可能会出现非理想目标物被检测的情况出现。
我们分别使用了2种参考目标障碍物对多样本产品进行了反复测试,对应目标的参照检测区域如下图示:
常见问题
| 1、如有疑问,欢迎通过qq或者论坛联系我们! 更多问题及有趣的应用,可以 访问论坛 进行查阅或发帖。 |
更多
[Link DFRobot商城购买链接]