1 VCC Power input (3.3V-5.5V)
2 GND Ground
3 NRST Reset
4 ECHO Measured distance presented by the Data Output 0-25000US by PWM pulse width, 1 CM / 50US representative
5 SERVO Servo Control Pin
6 COMP/TRIG COMP: On/OFF mode, when the detected distance is smaller than a pre-set value, this pin pulls low./TRIG: PWM mode trigger input
7 DAC_OUT Analog voltage output; the voltage is proportional to the distance
8 RXD Asynchronous communication module data receiving pin: RS232/TTL level
9 TXD Asynchronous communication module data receiving pin: RS232/TTL level
Tutorial
The functions of URM37 V5.0 are so powerful. Now, let us get known about the basic functions of the module. There are three measurement modes:
PWM triggered measurement mode
Automatically measure mode
Serial passive measurement
Then it also supports:
Simulation volume output (proportional with measurement distance, 6.8mV/cm)
Temperature read
Serial level choose (TTL or RS232 level)
Internal EEPROM without losing data
Serial EEPROM data read
The products have been conducted a set of rigorous tests by us, when you get your purchase, you can do some setting according to your demands, firstly, you may have to set the serial port-level (or RS232 TTL level), then we Can access to the module through the serial port, then set the range mode (0x02 writes data on the internal EEPROM address), after that, you can access to ultrasound module through MCU or PC.
To begin with this Ultrasonic Sensor, there is a software could help to make it a lot of easier.And there are some parameters you may want to reverse to meet more situations.
Button for RS232/TTL Choosing
The first basic step to communicate with the model is to choose the serial level_TTL(default) or RS232. We step forward over the last version3.2 which by jumper, now we could do it by pressing the only one button on the board for 1 Second, after the light turn off from state-on, release the botton. Repower again, the indicator appears to flash like once long and once short -present TTL level output, once long and twice short flash presenting RS232 level.
Do not connect the sensor to TTL MCU when the output mode is set to RS232, doing so will permanently damage the unit.
Other Setting address in EEPROM
Here, we are talking about the meaning of the data in EEPROM several addresses.
0x00 Larger than set distance
0x01 Less than set distance
0x02 Measure mode(write 0xaa present automatically measure mode, other data except 0xaa present PWM Passive measurement mode )
0x03 Serial level mode (TTL/RS232) (write 0x00 present TTL mode, 0x01 present RS232 mode, other data will be modified to 0x00)
0x04 Automatic measure time span(minimum value: 70ms; maximum value: 255ms; default value: 100ms. Witting format is 8-bit 16 binary, and its unit is ms. eg Write 6E means 110ms)
0x05 Measure sensitivity(the range of writing data is 0x0a-0xc8(equivalent to decimal 10-200), the smaller the value, the higher the sensivity. The default value is 0x0a, and the sensitivity is the highest.)
The factory default settings
Serial TTL level
Measure mode: PWM trigger
Comparison of distance : 0
Automatically measure interval time: 25ms
Internal EEPROM Data are all 0x00
The EEPROM address are unavailable: 0x00~0x04, please do not try to modify the data.
Three Measure Modes
PWM trigger mode
PWM Output in Trigger Mode
In trigger mode, pin COMP/TRIG produces a trigger pulse signal of low level, starting distance measurement operation once. At the same time, this low level pulse width represents the parameter for controlling the angle of the servo's rotation. 180 degree split into 46 The parameter ranges from 0 to 45 and every 50 US pulses represent a angle controlling parameter. When send out the trigger pulse, the MOTO pin of the module will produce servo controlling pulse to And then the detected distance of the servo. And then the detected distance will be output in the form of low level pulse via PWM from the ECHO pin. Every 50US values represent 1 centimeter. In this way, we can read the distance. Invalid if it returns a pulse of 50000US.
Upload the code below to your arduino board, wire the devices together, then you can realize the distance measurement.
int URECHO = 3; // PWM Output 0-25000US,Every 50US represent 1cm
int URTRIG = 5; // trigger pin
unsigned int DistanceMeasured = 0;
void setup()
{
//Serial initialization
Serial.begin(9600); // Sets the baud rate to 9600
pinMode(URTRIG, OUTPUT); // A low pull on pin COMP/TRIG
digitalWrite(URTRIG, HIGH); // Set to HIGH
pinMode(URECHO, INPUT); // Sending Enable PWM mode command
delay(500);
Serial.println("Init the sensor");
}
void loop()
{
Serial.print("Distance=");
digitalWrite(URTRIG, LOW);
digitalWrite(URTRIG, HIGH);
unsigned long LowLevelTime = pulseIn(URECHO, LOW) ;
if (LowLevelTime >= 50000) // the reading is invalid.
{
Serial.println("Invalid");
}
else
{
DistanceMeasured = LowLevelTime / 50; // every 50us low level stands for 1cm
Serial.print(DistanceMeasured);
Serial.println("cm");
}
delay(200);
}
Result
Arduino will send the distance to master computer through serial port. The baud rate should be set to 9600.
Analog Voltage Output in Trigger Mode
Once we are able to implement the most basic measurements, we can use more of the features on our module, such as the analog voltage output function mentioned above. The output voltage is proportional to the measured distance with the proportion of 4.125mV / cm. When the output range, the output voltage is 3.3V at full voltage. By reversing the code”#define Measure 1 ” to “#define Measure 0”, we can read the distance by analog voltage. Upload the demo code to Arduino, And connect the ultrasonic sensor with Arduino as the way shown below.
int URTRIG = 5; // trigger pin
int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
unsigned int DistanceMeasured = 0;
void setup()
{
//Serial initialization
Serial.begin(9600); // Sets the baud rate to 9600
pinMode(URTRIG, OUTPUT); // A low pull on pin COMP/TRIG
digitalWrite(URTRIG, HIGH); // Set to HIGH
delay(500);
Serial.println("Init the sensor");
}
void loop()
{
Serial.print("Distance=");
digitalWrite(URTRIG, LOW);
digitalWrite(URTRIG, HIGH);
delay(200);
sensorValue = analogRead(sensorPin);
sensorValue = sensorValue * 1.1; // (sensorValue * 5000 / 1024 ) / 4.125 = sensorValue * 1.1 , calculate the voltage value ADC collected and divide it by 4.125mV /cm.
Serial.print(sensorValue);
Serial.println("cm");
}
Note : the error of the distance got by calculating output analog voltage is bigger than that of the distance by other ways.
Auto Measure Mode
By means of the computer software or MCU Module, write 0xAA to 0x02 address to switch to automatic measurement mode. Writting a 8-bit 16 binary data to 0x04 address to reverse the measure time interval. This module measures distance automatically every 25 ms (Settable In addition, in every measure, the PWM Terminal will read the distance as a low level pulse, 50uS 1 cm.
Tips : if you have set the Compare value, you could use this module as a Ultrasonic Switch.
Download the sample code to the Arduino board, then wire as shown modules and Arduino connected on ultrasonic distance measurement can be achieved.
Note :download first before connect the Arduino TX/RX, otherwise it will fail.
int URECHO = 3; // PWM Output 0-25000US,Every 50US represent 1cm
unsigned int Distance = 0;
uint8_t AutomaticModelCmd[4] = {0x44, 0x02, 0xaa, 0xf0}; // distance measure command
void setup()
{
Serial.begin(9600); // Serial initialization
delay(5000); // wait for sensor setup
AutomaticModelSetup(); //Automatic measurement model set
}
void loop()
{
AutomaticMeasurement();
delay(100);
}
void AutomaticModelSetup(void)
{
pinMode(URECHO, INPUT);
for (int i = 0; i < 4; i++)
{
Serial.write(AutomaticModelCmd[i]);// Sending Automatic measurement model command
}
}
void AutomaticMeasurement(void)
{
unsigned long DistanceMeasured = pulseIn(URECHO, LOW);
if (DistanceMeasured >= 50000) // the reading is invalid.
{
Serial.print("Invalid");
}
else
{
Distance = DistanceMeasured / 50; // every 50us low level stands for 1cm
Serial.print("Distance=");
Serial.print(Distance);
Serial.println("cm");
}
}
Result
Arduino sends the distance information to the computer through serial port.