Author Topic: How to interface URM Ultrasonic Sensor to Arduino  (Read 1396 times)

admin

  • Administrator
  • Jr. Member
  • *****
  • Posts: 62
    • View Profile
    • Email
How to interface URM Ultrasonic Sensor to Arduino
« on: November 08, 2009, 07:28:57 AM »
This article gives a sample how to interfacing URM V3.2 ultrasonic sensor to Arduino board. Of couse, our Roboduino works as well.

1) Change URM V3.2 Mode to PWM output

To connect URM V3.2 to Arduino type board, you have to change the URM V3.2 mode to PWM output. To do that, you need send 0x44, 0x02,0xbb, 0x01 to the sensor through serial connection. You can use URM helpmate V1.2 to do that.

http://www.yerobot.com/products/manual/URM37V3.2helpmate.rar

All URM V3.2 shipped after 15th August 2008, the PWM function will be enabled before shipping.
2) Connect URM V3.2 to Arduino

Here is a connection diagram:



V3.2 Arduino

Pin2 GND
Pin1 Pin12
Pin4 Pin11
Pin6 Pin10
Pin7 Pin9



Code: [Select]
/* URM V3.2 Ultrasonic Sensor
*------------------
*
* Reads values from an ultrasonic sensor (5m sensor)
* and writes the values to the serialport.
* Help, please goto www.yerobot.com
* First written by Ricky on 2008 08 13
* Last modified by Crystal  on 2008 09 27
*/

int ultraData = 11; // Ultrasonic data pin
int ultraTrigger = 10; // Ultrasonic trigger pin
int ultraEnable=9; //Ultrasonic enable pin
int ultraPower=12;//Ultrasonic power pin
int val = 0;
int ultraValue = 0;
int timecount = 0; // Echo counter
int ledPin = 13; // LED connected to digital pin 13


void setup() {
  Serial.begin(9600);                  // Sets the baud rate to 9600
  pinMode(ledPin, OUTPUT);            // Sets the digital pin as output
  pinMode(ultraPower, OUTPUT); 
  digitalWrite(ultraPower, HIGH); // Set to HIGH to provide 5V power
  pinMode(ultraEnable, OUTPUT);
  digitalWrite(ultraEnable, HIGH); // Set Enable Pin to HIGH
  delay(200); //Give sensor some time to start up --Added By crystal  from Singapo, Thanks Crystal.
}

void loop() {
  ultraValue = 0;
digitalWrite(ledPin,LOW);
timecount = 0;
val = 0;
pinMode(ultraTrigger, OUTPUT); // Switch signalpin to output

/* Send low-high-low pulse to activate the trigger pulse of the sensor
* -------------------------------------------------------------------
*/
digitalWrite(ultraTrigger, HIGH); // Send High pulse
delayMicroseconds(500);

digitalWrite(ultraTrigger, LOW); // Send low pulse
delayMicroseconds(200);

digitalWrite(ultraTrigger, HIGH); // Send High pulse
delayMicroseconds(200);
/* Listening for echo pulse
* -------------------------------------------------------------------
*/

pinMode(ultraData, INPUT); // Switch signalpin to input



do // Loop until pin reads a high value
{
val = digitalRead(ultraData);
}while(val == HIGH);

do // Loop until pin reads a high value
{
val = digitalRead(ultraData);
timecount ++;            // Count echo pulse time
delayMicroseconds(50);
}while(val == LOW);


/* Writing out values to the serial port
* -------------------------------------------------------------------
*/

ultraValue = timecount; // Append echo pulse time to ultraValue


Serial.println(ultraValue,DEC);
Serial.flush();



/* Lite up LED if any value is passed by the echo pulse
* -------------------------------------------------------------------
*/

if(ultraValue > 20){
  digitalWrite(ledPin, HIGH);
}

/* Delay of program
* -------------------------------------------------------------------
*/

delay(50);
}


« Last Edit: November 12, 2009, 12:20:10 PM by admin »
Logged

Pierre333

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: How to interface URM Ultrasonic Sensor to Arduino
« Reply #1 on: November 08, 2009, 03:34:34 PM »
Hi

The link: http://www.yerobot.com/Products/manual/URMV3.2HelpMate.rar

shows:
'The page you requested was not found....'
Logged

admin

  • Administrator
  • Jr. Member
  • *****
  • Posts: 62
    • View Profile
    • Email
Re: How to interface URM Ultrasonic Sensor to Arduino
« Reply #2 on: November 12, 2009, 12:18:07 PM »
Link corrected.
Logged

Du_akinis

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: How to interface URM Ultrasonic Sensor to Arduino
« Reply #3 on: May 11, 2010, 02:49:26 PM »
Hello

Can you write code which writes the values to the LCD Keypad Shield...

Thanks
Logged