Pages: [1]   Go Down
Author Topic: Arduino + PING(( + MotorDriver (Quad Half HBridge)  (Read 1101 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Problem:
-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.

MAJOR PARTS USED:
-Arduino Duemilanove (ATMEGA328)
-Parallax PING Sensor
-SN754410 QUAD HALF-H DRIVER
---Sorry, unable to attach links to datasheets

The following may help; Code, Fritzing Image.

Code:
/* 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  
  +
 */

// ***** DEFINING VARIABLES to PIN NUMBERS *****
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:
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);          // HIGH PULSE for Signal
  delayMicroseconds(5);
  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


  //EVENTS FOR PING VALUE
  
  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
  }else{
    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

  delay(100);
}


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

/*----------------------------------
------- CONVERSION FUNCTIONS -------
----------------------------------*/

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 -------
-----------------------------*/

//Forward
void drive_forward(){
  digitalWrite(motor_ONE_pin_ONE,HIGH);
  digitalWrite(motor_TWO_pin_ONE,HIGH);
  return;
}

//Stop
void drive_stop() {
  digitalWrite(motor_ONE_pin_ONE,LOW);
  digitalWrite(motor_TWO_pin_ONE,LOW);
  digitalWrite(motor_ONE_pin_TWO,LOW);
  digitalWrite(motor_TWO_pin_TWO,LOW);
  return;
}

//Reverse   - Not yet being Used
/*
void drive_reverse(){
  digitalWrite(motor_ONE_pin_ONE,LOW);
  digitalWrite(motor_TWO_pin_ONE,LOW);
  digitalWrite(motor_ONE_pin_TWO,HIGH);
  digitalWrite(motor_TWO_pin_TWO,HIGH);
  return;
}
*/

Fritzing Image:
- Cant post image

Thankyou in advance smiley
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Fritzing Image

Updated


Logged

Northampton, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

G'day,

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

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

Northampton, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 508
Posts: 31416
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Assumed cause: Power

Just for reference cause was power supply decoupling - lack of

http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Sydney, Australia
Offline Offline
Full Member
***
Karma: 3
Posts: 230
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
how you wire the caps and motors.
You simply place a cap across the motor terminals - nothing fancy.


G.
Logged

Is life really that serious...??!

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello guys, this thread really help me solved my problem. Now I can get correct readings on my sensors smiley-grin Thanks!
Logged

Chicago
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley
Logged

Pages: [1]   Go Up
Jump to: