RB-Dfr-12 DFRobot URM04 v2.0 Ultrasonic Sensor URM04 is developed based upon our popular URM37 ultrasonic sensor. The RS485 interface allows a number of sensors working together. Up to 32 URM04 may be connected together in a network.
URM04 Beam Width 60 degree Dimension and Pin definition URM4 V2 front view and dimension URM4 V2 Back view
RS485 Interface: Two connectors, + : +5V DC Power +5V - : GND Ground A : A RS485 A(+) B : B RS485 B(-) ISP Pin:For factory firmware uploading Communication LED: As the device is powered up, this LED will flash four times which indicates that the sensor is working properly. This LED will also flash when it is communcating with other devices. Jumper A:Not in use Jumper B:When the sensor is working under a network, only the Jumper B for the first Device and the last Device need to be bridged.
PS: The command will return the temperature reading. The return temperature reading is using Celsius scale. If the temperature is above 0 Celsius, the first four bits of High will be all 0. If the temperature is below 0 Celsius, the first four bits of High will be all 1. The last 4 bits of High together with the Low bits stands for 12bits temperature. The resolution is 0.1.
Connect Sensor to PC via USB-RS485 converter Connect Sensor to PC via RS232-RS485 Converter Connect Sensor to Arduino Via MAX485 IC
Sensor Networking Upto 32 URM04 sensors are able to join a network. Simply serially connect the sensors uses twisted pair cables. A diagram is illustrated: URM04 Networking Arduino sketch for driving one URM04 sensor The sketch code: /* # The Sample code for driving single URM04 measuring distance function # Editor : Lauren # Date : 2012.2.8 # Ver : 0.
static unsigned long timePoint = 0; runUrm4(); // Drive URM04 Sensor and transmit the protocol to the sensor via RS485 interface // (IO Expansion shield V5 for arduino) decodeURM4(); // Read and get the distance value from the sensor if(millis() - timePoint > 100){ PrintData(); // print the data timePoint = millis(); } // PrintData(); // delay(100); } void PrintData(){ Serial.print("Distance value: "); for(int i = 0; i < urmAccount; i++){ Serial.print(urmData[i]); Serial.
# finish driving single URM function # if use the IO expansion shield to drive the urm sensors, the measuring rate may be 20Hz or slower[if you want]. # The sample code is compatible with the Arduino IDE 1.0 and also the earlier version. */ #if defined(ARDUINO) && ARDUINO >= 100 #include "Arduino.h" #define printByte(args) Serial.write(args) #else #include "WProgram.h" #define printByte(args) Serial.
startAddr = 0x11; managerTimer = millis(); for(int i = 0 ;i < urmAccount; i ++){ //Init the URM04 command receiving address urmID[i] = startAddr + i; urmData[i] = 0; } SerialPort.begin(19200); // Init the RS485 interface // Also when you are driving the URM04, you could open serial monitor to // tracing the steps and data feedback from URM04 SerialPort.println(); SerialPort.print("The URM ID: 0x"); for(int i = 0 ;i < urmAccount; i ++){ //Init the URM04 command receiving address SerialPort.
digitalWrite(TriggerPin, LOW); //Turn on reading mode for the RS485 interface managerTimer = 10; break; default: readingStep = 0; break; } // Finish reading the distance and start a new measuring for the sensor if(readingStep < 2) readingStep++; //step manager else readingStep = 0; timer = millis(); } } /********************* Transmit Command via the RS485 interface ***************/ void urmTrigger(int id){ // The function is used to trigger the measuring cmdst[2] = id; cmdst[3] = 0x00; cmdst[4] = 0x01; t
if(SerialPort.available()){ unsigned long timerPoint = millis(); int RetryCounter = 0; byte cmdrd[10]; for(int i = 0 ;i < 10; i++) cmdrd[i] = 0; int i=0; // SerialPort.println("OK"); boolean flag = true; boolean valid = false; byte headerNo = 0; while(RetryCounter < CommMAXRetry && flag) { if(SerialPort.available()){ cmdrd[i]= SerialPort.read(); // printByte(cmdrd[i]); if(i > 7){ flag=false; printByte(0xEE); printByte(0xFF); SerialPort.
// // printByte(millis() - timerPoint); if(valid) analyzeUrmData(cmdrd); else SerialPort.println("Invalid feedback"); //Get an invalid error command } } void analyzeUrmData(byte cmd[]){ byte sumCheck = 0; for(int h = 0;h < 7; h ++) sumCheck += cmd[h]; if(sumCheck == cmd[7] && cmd[3] == 2 && cmd[4] == 2){ byte id = cmd[2] - startAddr; urmData[id] = cmd[5] * 256 + cmd[6]; // // // SerialPort.print(id); SerialPort.print(":"); SerialPort.