PINGBot is the Explorer Robot that uses an ultrasonic sensor to be able to dodge objects present in its path.

The ultrasonic sensor emits pulses at a frequency of 40KHz (imperceptible to the human ear and animals), these pulses when hitting an object, they are reflected and return to the sensor after a certain time; knowing the total time round the wrists and the speed of sound in the medium (the air), it is easy to calculate the distance traveled by the wrists and thus determine the distance of the object relative to the sensor.
See the post about PING sensor for details in http://www.instructables.com/id/Basic-Principles/ 

We will use the same chassis of the BUGBot http://www.instructables.com/id/Basic-Principles/ ... but currently with a dual H-BRIDGE / L298H to control two DC motors (control direction and speed), which will give greater flexibility to our prototype.

The basic operation is as follows:

When booting the robot will remain stopped and the sensor calculates the distance FRONT, RIGHT and LEFT, he will compare these distance with a threshold distance (i.e.20 cm) so it can decide which is the best way to forward (the longest path will always be the best option! ).
After that the Robot will begin to running forward until the moment they will find an object interfering with your progress (it should approach the maximum limit up to a distance, in inches, of the object), when it happens: it will stop and analise again distances: FRONT, RIGHT and LEFT, so he could again decide which is the best way to forward - returning again to the operating cycle.

Step 1: Programming Logic

Speaking in terms of logic of programming, we have:

- including libraries;
- initialize variables and constants;
- define and initialize the pins;
- initialize serial communication;
- call routine to stop motors;
- positioning servo to 90 degrees;
- read FRONT distance and store;
- servo position at 0 degrees;
- read LEFT distance and to store;
- positioning servo to 180 degrees;
- read RIGHT distance and to store;
- comparison (1): FRONT is greater than LEFT?;
- yes: - comparison (2): FRONT is greater than RIGHT?;
- yes: - call routine to move forward;
- no: - call routinel to turn right;
- no: - (comparison (1) is less than: - call routine to turn left;
- If any condition is possible (all distances are exactly equals: - move forward and stop for a while, and so begin the cycle again.
- walking distance to detect less than 20 cm;
- loop to the "BEGIN";

Note - 1:
The motors must be connected in order to have the same rotation speed and  direction, so that to take the robot forward - high value on pin 2 of each motor and pin 1 maintained at a low level.

The flowchart show us, how to perform these programming functions (only as example):

Note - 2:
Using the same hardware, a second version with a simpler code was created. Where the operation is as below:

Initially the robot walks forward until he encounter an obstacle at a distance less than the distance limit;
Then he analyzes the "Right" distance - If the "Right" distance is greater than the limit distance - he chooses to turn "Right" and move forward;
If the "Right" distance is smaller than the limit distance - he analyses the "Left"  distance - if the "Left" distance is greater than the limit distance - he chooses to turn "Left" and move forward;
If none of the distances, both "Right" and "Left" is not satisfactory - he turn 180 degrees and move forward.
Starting a new cycle.

In the Software and Programming section, you will find both versions for download.

<p>Hi Sir!</p><p>My name is Himu,from Bangladesh.</p><p>Can you sent me the code and libraries please.</p><p>My email:asmhemu@gmail.com</p><p>Thank you!</p>
<p>Humm.. According Arduino specs, you should provide at least 7V to arduino.</p><p>So, the connection from the +5V on the bridge to the arduino Vin PIN will provide less input that required for stable operation. Certainly better to use external power source for arduino!</p>
<p>I have build the bot based on the chineese knockoff, I have tested all subsystems to veryfi they run, but when i load the sw it misses the ping and wprogram. i just have updated to ide 1,60</p><p>du you have an updated version ?</p><p>cheers</p><p>larsboi@hotmail.com</p>
<p>Hi Sir!<br>My name is Duy&ecirc;n, i come from Viet Nam.<br>Can you sent me the code, My email:tranduyenit@gmail.com<br>Thank you! </p>
<p>hello ... I want the code if u can </p><p>ramboo_77@yahoo.com</p>
<p>Hello my friend could you send the code to me also? fotiou5@yahoo.gr</p>
can i get the program ...................
Hi Preddy<br><br>Sure I can share the code with you.<br><br>Send me an email and I will be glad to send you the code and libraries.<br><br><br>Cheers<br><br>Marcelo Moraes<br>arduinobymyself@gmail.com
Hi<br><br>Send me an email and I can share the code with you.<br>arduinobymyself@gmail.com<br><br>
<p>hello alos can you send me codes please. ı want make that for my project of lesson. my e-mail is :</p><p>satogluibrahim@gmail.com</p><p>ı sent you an e-mail if you received to it .</p>
<p>preddy126@gmail.com</p><p>pls send me code to above email id....</p>
Hi Preddy126<br><br>For sure. I am sending the code to your email.<br><br>Regards<br><br>Marcelo Moraes<br>arduinobymyself.blogspot.com.br<br>arduinobymyself@gmail.com

About This Instructable


66 favorites


Bio: I am 43 years old and I live in Brazil. I am a Telecommunication / Electronics Engineer. Sixteen years acting in the industry of "Telecommunication and ... More »
More by BIGDOG1971: ROVER Bot - The Arduino Bluetooth Controlled Tank WATERING SYSTEM - INTRODUCTION 16x8 LED dot matrix with MAX7219 module
Add instructable to: