Go Down

Topic: Arduino + PING(( + MotorDriver (Quad Half HBridge) (Read 2133 times) previous topic - next topic


G'day all,

Currently experimenting with Motor Drivers and PING(( together and new to the self experimentation. Have hit a problem and wondering if anybody knows where.

-PING and MOTOR drivers work fine, until a second motor is added to the motor driver.
-Once 2nd motor added to circuit, The PING sensor starts to give false readings, and the motors do not run even if directly told to.
-Once removing the 2nd motor, circuit starts functioning correctly again.

Assumed cause: Power

How to fix:

-This is where i am stuck. Any suggestions or recommendations would be very helpful.

-Arduino Duemilanove (ATMEGA328)
-Parallax PING Sensor
---Sorry, unable to attach links to datasheets

The following may help; Code, Fritzing Image.

Code: [Select]
/* Autonomous Robot - Created By Carlin (Jiggles)

Last Modified 24/06/2010

-Coding Credits (Why re-invent the wheel?)
 +Ping))) Sensor - David A. Mellis & Tom Igoe  

const int pingPin = 7;            // This constant won't change.  It's the pin number of the sensor's output:
int ledpin_ok = 3;                // Green Led to visually display returned value of ping sensor.
int ledpin_close = 2;             // Red Led to display if PING Value is "Too Close" to an object.
int motor_ONE_pin_ONE=6;          // Defines Arduino pin#6 to the pin connected to Motor Driver (PWM Pin)
int motor_ONE_pin_TWO=5;          // Defines Arduino pin#5 to the pin connected to Motor Driver (PWM Pin)
int motor_TWO_pin_ONE=9;          // Defines Arduino pin#9 to the pin connected to Motor Driver (PWM Pin)
int motor_TWO_pin_TWO=10;         // Defines Arduino pin#10 to the pin connected to Motor Driver (PWM Pin)

// ***** VOID SETUP - Self Explanitory *****

void setup() {
 Serial.begin(9600);                    // Initialize serial communication:
 pinMode(ledpin_ok, OUTPUT);            // Define Green Led as OUTPUT
 pinMode(ledpin_close, OUTPUT);         // Define Red Led as OUTPUT
 pinMode(motor_ONE_pin_ONE,OUTPUT);     // Define Motor1pin1 as OUTPUT
 pinMode(motor_ONE_pin_TWO,OUTPUT);     // Define Motor1pin2 as OUTPUT
 pinMode(motor_TWO_pin_ONE,OUTPUT);     // Define Motor2pin1 as OUTPUT
 pinMode(motor_TWO_pin_TWO,OUTPUT);     // Define Motor2pin2 as OUTPUT

// ***** VOID LOOP - Self Exlpanitory *****

void loop()
 long duration, cm; // Define variables for duration of the ping and the distance result in centimeters:

 // *** PING CODE***
 // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
 pinMode(pingPin, OUTPUT);             //PING Pinmode has
 digitalWrite(pingPin, LOW);           // LOW pulse beforehand to ensure a clean HIGH pulse:
 digitalWrite(pingPin, HIGH);          // HIGH PULSE for Signal
 digitalWrite(pingPin, LOW);           // Low pulse Afterwards

 pinMode(pingPin, INPUT);                    // Reconfigure PING Pin as INPUT to recieve Pulse already sent.
 duration = pulseIn(pingPin, HIGH);          // Give PING value to Duration Variable of result
 cm = microsecondsToCentimeters(duration);   // convert the time into a distance

 Serial.print(cm);       //Serial Monitor shows/prints value of variable "cm"
 Serial.print("cm");     //Serial Monitor shows/prints words "cm"
 Serial.println();       //Serial Monitor goes to next line

 if (cm <= 10) {                       //Determines if sensor is too close to object
   digitalWrite(ledpin_close,HIGH);    //Red Led on - Visual Status of Reading
   digitalWrite(ledpin_ok,LOW);        //Green Led off - Visual Status of Reading
   drive_stop();                       //*FUNCTION CALL - DRIVE STOP
   digitalWrite(ledpin_close,LOW);     //Red Led off - Visual Status of Reading
   digitalWrite(ledpin_ok,HIGH);       //Green Led on - Visual Status of Reading
   drive_forward();                    //*FUNCTION CALL - DRIVE FORWARD
 } //END OF IF (cm<=10) STATEMENT


//***************************FUNCTIONS / SUB ROUTINES********************************


long microsecondsToCentimeters(long microseconds)
 // The speed of sound is 340 m/s or 29 microseconds per centimeter.
 // The ping travels out and back, so to find the distance of the
 // object we take half of the distance travelled.
 return microseconds / 29 / 2;

------- DRIVE FUNCTIONS -------

void drive_forward(){

void drive_stop() {

//Reverse   - Not yet being Used
void drive_reverse(){

Fritzing Image:
- Cant post image

Thankyou in advance :)



Hi I am having a similar issue with Ping giving false readings, have you tried putting supression capacitors across your motors + and - terminals to avoid noise getting back into your circuit?



Thanks for reply. Fixed this one a couple of days ago.

-Independent motor power source added (Into PIN8 - [Vcc2] ), solved motor issue
-Caps across the DC motors solved the PING incorrect readings.


No worries.  Glad the capacitors sorted your PING issue out, that was one was driving me nuts! :)


Assumed cause: Power

Just for reference cause was power supply decoupling - lack of



Hi Jiggles, I have similar project also have problem at ping reading. Can you post the fixed fritzing image, how you wire the caps and motors.


how you wire the caps and motors.

You simply place a cap across the motor terminals - nothing fancy.

Is life really that serious...??!


Hello guys, this thread really help me solved my problem. Now I can get correct readings on my sensors :D Thanks!


I'm working on basically the same thing right now, I was wondering where you hooked up the power source for the motors? Mine can't seem to draw enough power from the arduino to turn the wheels and the treads. A revised fritzing would be great :)

Go Up