Arduino and SR04 ultrasonic sensor – robot eyes !
Posted by Mike Redrobe | Posted in Arduino | Posted on 20-05-2012
Tags: arduino, electronics, robots
1
Hooked an SR04 ultrasonic sensor to my arduino board – robot eyes !
Ranger sensor uses sonar to give accurate distance measurement to objects or obstacles placed in front of it. They’re surprisingly sensitive / accurate – I was able to reliably measure to a millimeter at 15cm range.
These sensors are also now VERY cheap £2.37 (4$) delivered from HK, and accurate to a few mm.
Added a servo for visual feedback:
Arduino code is basically sending a trigger on one pin, receiving a timing value on another,
which can then be converted into a distance:
-
pinMode(TP,OUTPUT);
pinMode(EP,INPUT);
Trig_pin=TP;
Echo_pin=EP;
digitalWrite(Trig_pin, LOW);
delayMicroseconds(2);
digitalWrite(Trig_pin, HIGH);
delayMicroseconds(10);
digitalWrite(Trig_pin, LOW);
duration = pulseIn(Echo_pin,HIGH);