Data Sheet
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.print(" ");
}
/*
for(int i = 0; i < urmAccount;i ++){
Serial.print(urmID[i],HEX);
Serial.print(" ");
}
*/
Serial.println();
}
The library code: please place the library file Urm4parser.h in to the sketch folder.
/*
# The library for the URM04 sketch
# Editor : Lauren
# Date : 2012.2.8
# Ver : 0.3
# Product: URM04 Ultrasonic sensor
# Specification
* Detecting range: 4cm-500cm
* Resolution : 1cm
* Interface : RS485
* Units: Range reported in cm
* Temperature sensor: 12 bits reading from serial port
# Description: