Ultrasound sensor/Obstance Avoidance

Obstacle Avoidance:

  • Utilize ultrasound sensor (the cat face sensor) to sense how far away an object is
  • The basic gist is that it sends sound waves and receives them back, and use the code to calculate how far away the object is
  • Distance limit for detection of obstacles is 30cm
  • 0.01657 (microseconds/cm) is the speed of sound
  • Periodically, the car will stop and send pulses of sound to 5 different directions (front, mid left and right, sharp left and right), and receives those pulses back once they hit an obstacle, within a time interval, it will multiply that by the speed of sound to get how far away the obstacle is, if it is within 30cm, then the car will perform the following:
    • Go back if the obstacle is in front
    • Turn left/right if the obstacle is on its right/left

Note:

  • The car can only periodically scan for obstacles left and right, but will, at all times, scan in front of it, since it is the direction the ultrasound sensor is facing, so it can react to an object in front of it in real time

Download this code and open it in your Arduino IDE, connect it to your Arduino and upload it https://gist.github.com/minhviet0308/6223919c969a1a06bae4f357c130df7d (opens in a new tab)

For fun:

  • Change the code and let the car react spontaneously when in front of an object!