URM37 V4.0 Ultrasonic Sensor (SKU:SEN0001)
URM37 V4.0 Ultrasonic Sensor
Contents
1 Introduction
2 Specification
3 PinOut
4 Tutorial
4.1 Button for RS232/TTL Choosing
4.2 Test on Software
4.3 Othere Setting address in EEPROM
4.4 The factory default settings
4.5 Three Measure Modes
4.5.1 PWM trigger mode
4.5.2 Auto Measure Mode
4.5.3 Serial Passive Mode
4.6 Servo Rotation Reference Table
5 Protocol
6 Trouble shooting
7 More
Introduction
URM37 V4.0 Ultrasonic Sensor uses an industrial level AVR processor as the main processing unit.
It comes with a temperature correction which is very unique in its class. URM37 V3.2 (last version)
has already been a very good realization of ultrasonic switch and serial (TTL and RS232 level
optional), pulse output function, the module can also control a servo rotation to realize a spatial
ultrasound scanner. On this basis we have to upgrade the function. URM37 V4.0, the current version
has better intelligence capabilities, meanwhile, mechanical dimensions and pin interface and
communication commands are compatible with V3.2, V3.2 has been reversed based on the following
changes:
Serial level selected from the skipped stitches to button, user can easily select RS232 or TTL-level
output level output by pressing the settings( after reboot ).
Modified the algorithm, so dead zone was reduced and enhance accuracy.
Analog voltage output, voltage and the measured distance is proportional.
Wide voltage support +3.3V-5.0V.
Power reverse protection.
Automatic measurement of time interval can be modified.
Modify a servo controlled angle of 0-180, compatible with the most of the servos on the market.
Measuring time is 100ms.
Specification
Power: +3.3V~+5.0V
Current: Pin 1 VCC (URM V4.0)
15 // #
GND (Arduino)
-> Pin 2 GND (URM V4.0)
16 // #
Pin 3 (Arduino)
-> Pin 4 ECHO (URM V4.0)
17 // #
Pin 5 (Arduino)
-> Pin 6 COMP/TRIG (URM V4.0)
18 // #
Pin A0 (Arduino) -> Pin 7 DAC (URM V4.0)
19 // # Working Mode: PWM trigger pin
mode.
20
21 #define
Measure
1
//Mode select
22 int URECHO = 3;
// PWM Output 0-25000US,Every 50US represent 1cm
23 int URTRIG = 5;
// PWM trigger pin
24 int sensorPin = A0;
// select the input pin for the potentiometer
25 int sensorValue = 0;
sor
// variable to store the value coming from the sen
26
27 unsigned int DistanceMeasured= 0;
28
29 void setup()
30 {
31
//Serial initialization
32
Serial.begin(9600);
// Sets the baud rate to 9600
33
G
pinMode(URTRIG,OUTPUT);
// A low pull on pin COMP/TRI
34
digitalWrite(URTRIG,HIGH);
// Set to HIGH
35
pinMode(URECHO, INPUT);
mmand
36
delay(500);
37
Serial.println("Init the sensor");
// Sending Enable PWM mode co
38
39
}
40 void loop()
41 {
42
PWM_Mode();
43
delay(100);
44 }
45
46 void PWM_Mode()
G triggering a sensor reading
// a low pull on pin COMP/TRI
47 {
48
Serial.print("Distance Measured=");
49
digitalWrite(URTRIG, LOW);
50
digitalWrite(URTRIG, HIGH);
pulses
51
if( Measure)
52
{
// reading Pin PWM will output
53
unsigned long LowLevelTime = pulseIn(URECHO, LOW) ;
54
if(LowLevelTime>=45000)
55
{
56
Serial.print("Invalid");
57
}
58
else{
59
DistanceMeasured = LowLevelTime /50;
for 1cm
60
Serial.print(DistanceMeasured);
61
Serial.println("cm");
62
63
// the reading is invalid.
}
// every 50us low level stands
64
}
65
else {
66
sensorValue = analogRead(sensorPin);
67
if(sensorValue Pin 1 VCC (URM V4.0)
16 // #
GND (Arduino)
-> Pin 2 GND (URM V4.0)
17 // #
Pin 3 (Arduino)
-> Pin 4 ECHO (URM V4.0)
18 // #
Pin TX1 (Arduino)
-> Pin 8 RXD (URM V4.0)
19 // #
Pin RX0 (Arduino)
-> Pin 9 TXD (URM V4.0)
20 // # Working Mode: autonomous
mode.
21
22 int URECHO = 3; // PWM Output 0-25000US,Every 50US represent 1cm
23
24 unsigned int Distance=0;
25 uint8_t EnPwmCmd[4]={0x44,0x02,0xaa,0xf0};
// distance measure command
26
27 void setup(){
// Serial initialization
28
0
Serial.begin(9600);
// Sets the baud rate to 960
29
AutonomousMode_Setup();
30 }
31
32 void loop()
33 {
34
AutonomousMode();
35
delay(100);
36 }
//PWM mode setup function
37
38 void AutonomousMode_Setup(){
39
pinMode(URECHO, INPUT);
command
40
for(int i=0;i=45000){
47
Serial.print("Invalid");
48
49
}
else{
50
Distance=DistanceMeasured/50;
ds for 1cm
51
Serial.print("Distance=");
52
Serial.print(Distance);
53
Serial.println("cm");
54
// the reading is invalid.
// every 50us low level stan
}
55
56 }
result
Arduino send the distance information to the computer through serial.
Serial Passive Mode
In this mode, actually, as long as you wire the module TX & RX with the MCU, just as we did in the
[test on software],you are using this mode.By serial, you have all authority to access to the sensor
such as: ultrasonic distance measurement, temperature measurement, the distance changes,
automatic measurement intervals set, serial port set(RS232 or TTL, reboot to take effect).
e.g.
1.
2.
3.
4.
Read the temperature data command: 0x11 0x00 0x00 0x11
Read the distance data command: 0x22 0x00 0x00 0x22
Read EEPROM data command: 0x33 0x00 0x00 0x33
Write EEPROM data command: 0x44 0x02 0x00 0x46
Download the code below to your uno board(if you use the leonardo,please modify the code for the
serial problem, help on arduino.cc ), then wire the TX/RX,5V,GND.Follow [test on software].Here,we
use the sensor to read the tempreture.
Demo Code
1
2 // # Editor
: ZRH from DFRobot
3 // # Date
: 29.08.2014
4
5 // # Product name: URM V4.0 ultrasonic sensor
6 // # Product SKU : SEN0001
7 // # Version
: 1.0
8
9 // # Description:
10 // # The sketch for using the URM37 Serial
11 // #
mode from DFRobot
and writes the values to the serialport
12
13 // # Connection:
14 // #
Vcc (Arduino)
-> Pin 1 VCC (URM V4.0)
15 // #
GND (Arduino)
-> Pin 2 GND (URM V4.0)
16 // #
Pin TX1 (Arduino)
-> Pin 8 RXD (URM V4.0)
17 // #
Pin RX0 (Arduino)
-> Pin 9 TXD (URM V4.0)
18 // # Working Mode: Serial
Mode.
19
20 uint8_t EnTempCmd[4]={0x11,0x00,0x00,0x11};
and
21 uint8_t TempData[4];
22 unsigned int TempValue=0;
23 void setup()
24 {
25
Serial.begin(9600);
26
delay(100);
27
Serial.println("Init the sensor");
28 }
29 void loop()
30 {
31
SerialCmd();
32
delay(200);
33 }
// temperature measure comm
34 void SerialCmd()
35 {
36
int i;
37
for(i = 0;i < 4;i++){
38
39
Serial.write(EnTempCmd[i]);
}
40
while (Serial.available() > 0)
41
{
42
//if serial receive any data
for(i = 0;i < 4;i++){
43
TempData[i] = Serial.read();
44
}
45
TempValue = TempData[1] GND (Arduino)
// #
Pin 4 PWM (URM V3.2) -> Pin 3 (Arduino)
// #
Pin 6 COMP/TRIG (URM V3.2) -> Pin 5 (Arduino)
// # Pin mode: PWM
// # Working Mode: PWM passive control mode.
// # If it is your first time to use it,please make sure the two jumpers to t
he right hand
// # side of the device are set to TTL mode. You'll also find a secondary jum
per on
// # the left hand side, you must break this connection or you may damage you
r device.
#include
// Include Servo library
Servo myservo;
control a servo
// create servo object to
int pos=0;
servo position
// variable to store the
int URPWM=3;
very 50us represent 1cm
// PWM Output 0-25000us,e
int URTRIG=5;
// PWM trigger pin
boolean up=true;
ble
// create a boolean varia
unsigned long time;
// create a time variable
unsigned long urmTimer = 0;
e sensor reading flash rate
// timer for managing th
unsigned int Distance=0;
uint8_t EnPwmCmd[4]={0x44,0x22,0xbb,0x01};
nd
// distance measure comma
void setup(){
// Serial initialization
Serial.begin(9600);
600
// Sets the baud rate to 9
myservo.attach(9);
// Pin 9 to control servo
PWM_Mode_Setup();
}
void loop(){
if(millis()-time>=20){
time=millis();
f programme
if(up){
// interval 0.02 seconds
// get the current time o
// judge the condition
if(pos>=0 && pos179)
up= false;
ain
}
else {
if(pos>=1 && pos