Introduction: Obstacle Avoiding RC - Ultrasonic Sensor on a Servo

About: If you want to do people to build ships,... All you need to do them to crave greatness and the vastness of the sea Antoine de Saint-Exupery

There are numerous instructables of RCs capable of avoiding obstacles. In this project I'm trying to show a simple way, not only to avoid any kind of obstacles, but also to make the decision to take the best way out!

Instead of having a fixed ultrasonic sensor directed forward, the sensor is placed on a servo which turns from 15 to 165 degrees (where the angle of 90 degrees is supposed to be the forward direction). The sensor takes a measurement of an obstacle's distance every 6 degs (this means 25 measurements for the total angle of 150 degs) and compares with one another to find the actual angle where the distance is maximum (this happens in look_around routine).

Then the RC is supposed to turn to that direction. While are DC motors in use, it is not easy to be precise in that aim. So with some trials I found out that for a particular motor speed the RC turns 90 degs in 500 ms. So with the introduction of a simple analogy in the sketch, the RC can turn in every angle only by setting the time and direction of motors activation (lines 180 and 194 of the code).

I have also implemented in the code, the code of my older instructable (Arduino based RC with two switches - mustache like- for avoiding obstacles) for having some extra sensors on. The LED use is only meant to help realizing the part of the code that runs every second. Maybe some show off too! The routine-type architecture of my code aims to help you implementing any of the routines in your own code! I hope it does!