Go Down

Topic: How to add Ping))) to this code (Read 1 time) previous topic - next topic

Tonyodonnell01

I was wondering how and where would I put the code for PING))) in the code below and how would I wire this to a L298N H-Bridge?


Code: [Select]

int PWM1  = 6;  // PWM Pin Motor 1
int PoM1  = 7;  // Polarity Pin Motor 1
int PWM2  = 5;  // PWm Pin Motor 2
int PoM2  = 4;  // Polarity Pin Motor 2

int ValM1  = 0;  // Initial Value for PWM Motor 1
int ValM2  = 0;  // Initial Value for PWM Motor 2

int i = 25;  // increment
boolean goUp = true;  // Used to detect acceleration or deceleration


void setup()
{
 pinMode(PWM1,  OUTPUT);
 pinMode(PoM1,  OUTPUT);
 pinMode(PWM2, OUTPUT);
 pinMode(PoM2, OUTPUT);
 
 digitalWrite(PoM1, LOW);  // Both motors with the sam polarity
 digitalWrite(PoM2, LOW);
 
 analogWrite(PWM1, ValM1);  // Stops both motors => ValMx = 0
 analogWrite(PWM2, ValM2);  
 Serial.begin(9600);        // Used to check value
}

// Main program

void loop()
{
 delay (500);                 // Give time to theh motor to adapt to new value
 if ((ValM1 < 250) && goUp)  // First phase of acceleration
 {
   ValM1 = ValM1 + i;  // Increase PWM value => Acceleration
   ValM1 = ValM1 + i;
 }
 else
 {
   goUp = false;        // Accerleration completed
   ValM1 = ValM1 - i;  // Decrease PWM => deceleration
   ValM2 = ValM2 - i;
   if (ValM1 < 75)
   {
     ValM1 = 0;
     ValM2 = 0;
     goUp =
     true;
   }
 }
 if ((ValM1 > 75) && ((ValM1 < 255)))
{
   analogWrite(PWM1, ValM1);
   analogWrite(PWM2, ValM2);
 }
 Serial.print(ValM1);
 Serial.print("\t");
 Serial.print(ValM2);
}

AWOL

Why do you want to wire a Ping to an H-bridge?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Nick Gammon

http://en.wikipedia.org/wiki/Ping

I doubt it can be done.
http://www.gammon.com.au/electronics

Tonyodonnell01

@AWOL

I want to attach the Ping))) and L289N to an Arduino board to control two motors.

AWOL

Have you had a look at the Playground?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

hscriber

Here's the basic code to use the PING)))  The tone is to hook up to a piezo speaker, and it changes pitch based off the distance.  I'm not entirely sure what you want to do with it, but if you needed the code, here you go.

Code: [Select]
int tone_freq=0;
  long duration, inches;
  pinMode(3, OUTPUT);
  digitalWrite(3, LOW);
  delayMicroseconds(2);
  digitalWrite(3, HIGH);
  delayMicroseconds(5);
  digitalWrite(3, LOW);
  pinMode(3, INPUT);
  duration = pulseIn(3, HIGH);
  Serial.print(148, BYTE);
  Serial.print(duration);
  inches = (duration/2)/74;
  Serial.print(137, BYTE);
  Serial.print(inches);
  delay(100);
  tone_freq= inches*100;
  tone(2,tone_freq);

doughboy


http://en.wikipedia.org/wiki/Ping

I doubt it can be done.


I think he meant this
http://arduino.cc/en/Tutorial/Ping

Ping != Ping)))

Tonyodonnell01

I have searched the internet for about four hours trying to find a good example on how to wire and Arduino Mega, L289N Motor Control, and a Parallax Ping))) all together? I was tired of searching the internet and didn't look on the forum. If you know how or know of a good/great example that shows how and with some code, could you point me in that direction?

Thank you.

P.S. I did wire every but I didn't power it up since I am afraid that I would fry my Mega and I have already did that once.

AWOL

If I have to merge another of your duplicate posts, I'm going to start deleting them.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Tonyodonnell01

I was wondering why are you merging them? My first question was about coding and the second question was about wire them altogether. 

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Nick Gammon


how to wire and Arduino Mega, L289N Motor Control, and a Parallax Ping))) all together?


How about a link to the datasheet for this Ping thing?
http://www.gammon.com.au/electronics

Go Up