2008年10月17日 星期五

URM V3.2 ultrasonic sensor to Arduino board

http://www.yerobot.com/forum/viewtopic.php?f=5&t=7&p=10&sid=72f4c2fbb84bf3

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/download/software/URMV3.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:

Attachment:
Roboduino-URM.jpg
Roboduino-URM.jpg [ 122.45 KiB | Viewed 250 times ]



V3.2 Arduino

Pin2 GND
Pin1 Pin12
Pin4 Pin11
Pin6 Pin10
Pin7 Pin9


Last edited by ricky on Sat Sep 13, 2008 4:31 pm, edited 7 times in total.

Top
Profile

ricky
Post subject: Re: Interfacing URM Ultrasonic Sensor to Arduino (Roboduino)
PostPosted: Tue Jul 29, 2008 10:27 pm
Offline

Joined: Sat Jul 12, 2008 3:50 pm
Posts: 17
Here is the Arduino code:

Code:
/* 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 low pulse
delayMicroseconds(500);

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

digitalWrite(ultraTrigger, HIGH); // Send low 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);
}

沒有留言: