Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: jim on April 23, 2013, 04:29:05 AM

Title: arduino with HC SR 04
Post by: jim on April 23, 2013, 04:29:05 AM
hi.. i bought an HC SR 04 and arduino.
I found this link to connect the HC_SR04 module to the arduino uno (http://www.essentialtech.co.nz/content/first_play_arduino_uno_and_hcsr04_ultrasonic_distance_module (http://www.essentialtech.co.nz/content/first_play_arduino_uno_and_hcsr04_ultrasonic_distance_module))


Well i want my robot to stop its motion when an obstacle is detected.. the code in the above link is useful to measure the distance.. but could someone help me in modifying it to stop the motion of the robot below a certain distance like say 20 cm away from the obstacle?? thank you in  advance..


Title: Re: arduino with HC SR 04
Post by: obiwanjacobi on April 23, 2013, 11:29:15 AM
in the loop() method:

Code: [Select]
if (distance <= 20)
{
   Stop();
}

The Stop() method would cut the power to the motors (or whatever you're using)...