go_away

Author Topic: arduino with HC SR 04  (Read 460 times)

0 Members and 1 Guest are viewing this topic.

Offline jimTopic starter

  • Jr. Member
  • **
  • Posts: 7
  • Helpful? 0
arduino with HC SR 04
« 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)


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..



Offline obiwanjacobi

  • Full Member
  • ***
  • Posts: 57
  • Helpful? 0
  • You can PIC any micro controller - what AVR!
Re: arduino with HC SR 04
« Reply #1 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)...

 


Get Your Ad Here