# PINGBot - Explorer Robot

15,015

71

12

Published

## Introduction: PINGBot - Explorer Robot

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 https://www.instructables.com/id/Basic-Principles/

We will use the same chassis of the BUGBot https://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;
- "BEGIN"
- 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.

## Step 2: Hardware and Materials

In this section we will examine the needs in terms of materials and hardware used.

We will use the chassis built for BUGBot - Light Follower Robot.
See the post for more construction details...  https://www.instructables.com/id/Basic-Principles/

Material List:
1 x Arduino UNO, Mega, Duemilanove, Duecemila or Teensy + + 2.0
1 x Ultrasonic Sensor HC-SR04
1 x Dual H-BRIDGE
1 x Servo Motor HXT900 9g / 1.8 Kg
1 x Kit Tamiya Gear Box with two 3-6V DC motors
Battery pack to power the Arduino and motors (9V)
Chassis for mounting
Wires and cables for connections.

## Step 3: Layout and Schematics

The Arduino power feed, can be used from the H-Bridge.
I advise to use an independent power feed but with GNDs in common
between Arduino and H-Bridge. (due to high current drawn by the motor)

Take care to not reverse the connections of power feed ... the damage may be irreversible.

Pins Correspondence:
Arduino pins -X- External devices' pins:

0 -> N / A
1 -> N / A
2 -> N / A
3 -> PING Sensor echo pin
4 -> PING Sensor Trigger pin
5 -> H-BRIDGE port-A enable pin
6 -> H-BRIDGE in1 pin
7 -> H-BRIDGE in2 pin
8 -> H-BRIDGE in3 pin
9 -> H-BRIDGE in4 pin
10 -> to attach the servo motor
11 -> H-BRIDGE port-B enable pin
12 -> buzzer
13 -> N / A

"I had many problems with noise in the distance sensor system, which was solved by
adding 100nF capacitor between pins of the DC motors and their
carcasses (besides the capacitor which is usually added among its pins).

## Step 4: Software and Programming

Many versions were created in the construction initial phase of the PINGBot.
It were created a version to manage the DC motors (direction, speed, to turn left, to turn right and for to turn 180 degrees).

And also were created the continous rotation servo motor's version. If you need this version, contact me please and I am willing to help you.

I had a lot of work to do the final adjustments in the Robot (and I think that is not too good so far). First, because the DC motors noise as I already commented, and then for the movements adjust and batery consuption.

About 30 hours were spent in this project. I believe that for any kind of chassis, we will need spent time for the adjustments and debug.

You can download the arduino sketches and libraries directly from the GitHub below:

https://github.com/Arduinobymyself/PINGBot.git

## Step 5: Videos

I am so sorry, but the videos are in Portuguese yet.

PINGBot version 4 (video 1):
screencast: http://www.screencast.com/t/C6KN0SNhO69p

PINGBOT version 4 (video 2):
screencast: http://http://www.screencast.com/t/lMa4ZLQIAJj

PINGBot version 5:
screencast: http://www.screencast.com/t/7pmwaWJhu4dy

PINGBot - General operation of the Robot, in action - leaving a deadlock.
screencast: http://www.screencast.com/t/9Uow4fyDy

Others Projects:

https://www.instructables.com/id/LINUSBot-Line-Follower-Robot/
https://www.instructables.com/id/Basic-Principles/
https://www.instructables.com/id/3x3x3-LED-Cube-1/
https://www.instructables.com/id/LINUSBot-Line-Follower-Robot-with-PID-control/

## Step 6: Pictures and Photos

The problem of battery compartment, was solved using two plastic parts (used in carpentry and furniture making).
The parts were placed on top of the 360 degrees wheel, using the same fixing screws (or ball caster if you are using).
In this way the problem was solved and gave more stability to the chassis.

Note that the DC motor battery is rechargeable type ... it helps us to save money and give more energy to the car.
Use a 9V/900mAh Nickel Metal Hydride (NiMH) batery.

## Recommendations

• ### 3D CAM and CNC Class

599 Enrolled

• ### Planter Challenge

We have a be nice policy.

## Questions

Hi Sir!

Can you sent me the code and libraries please.

My email:asmhemu@gmail.com

Thank you!

Humm.. According Arduino specs, you should provide at least 7V to arduino.

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!

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

du you have an updated version ?

cheers

larsboi@hotmail.com

Hi Sir!
My name is Duyên, i come from Viet Nam.
Can you sent me the code, My email:tranduyenit@gmail.com
Thank you!

hello ... I want the code if u can

ramboo_77@yahoo.com

Hello my friend could you send the code to me also? fotiou5@yahoo.gr

can i get the program ...................

3 replies

Hi Preddy

Sure I can share the code with you.

Send me an email and I will be glad to send you the code and libraries.

Cheers

Marcelo Moraes
arduinobymyself@gmail.com

Hi

Send me an email and I can share the code with you.
arduinobymyself@gmail.com

hello alos can you send me codes please. ı want make that for my project of lesson. my e-mail is :

satogluibrahim@gmail.com

ı sent you an e-mail if you received to it .

preddy126@gmail.com

pls send me code to above email id....