Jdawg

Im having trouble figuring out how to write a sketch for this, Can anyone point me to a good place to start. I am using An arduino uno, a seeedstudio motor shield, a paralax ping sensor attached to a servo, and my dual motor tank chassis. So far this gent has basically the setup im after, minus the ir sensor and the temp sensor. http://errincode.blogspot.com/2013/02/arduino-autonomous-tracked-robot-build_27.html Also the sketch on this site comes up with tons of errors, which i attached a picture of.

analogWrite(speedpinA,spead);//input a simulation value to set the speedThat comment doesn't match what the code is doing - I don't see where "simulation" comes into the picture.Consistent spelling of "speed" would help understanding what is going on.

Quote

where to plug the servo

What servo?

"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.I speak for myself, not Arduino.

"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.I speak for myself, not Arduino.

"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.I speak for myself, not Arduino.

Jdawg

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Arduino powered RC tank By: Stanley Deakins // //This is a basic sketch used to power an RC tank using a Arduino and a seeedstudio ping sensor. It uses a //Parallax ping sensor to navigate. Please feel free to modify this sketch anyway you feel like. This is simply //just enough to get you started on the project. Thank and enjoy. //http://www.instructables.com/id/E2Q88MBHC9MJAFY/ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

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

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: pinMode(pingPin, OUTPUT); digitalWrite(pingPin, LOW); delayMicroseconds(2); digitalWrite(pingPin, HIGH); delayMicroseconds(5); digitalWrite(pingPin, LOW);

// The same pin is used to read the signal from the PING))): a HIGH // pulse whose duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object. pinMode(pingPin, INPUT); duration = pulseIn(pingPin, HIGH);

// convert the time into a distance inches = microsecondsToInches(duration);

// //if objects are less than 12 inches away //the robot reverses and turns to the right //for 2 seconds //

if (inches < 8){

//brake drive motor and pause 1/10 second stop();

// //setting motors backwards //

backward(); delay(700); stop();

// //setting motors to turn //

left(); delay(1100); stop(); }

// //when nothing is within 8" //the robot simply drives forwards //

else{

// //Setting drive motor //

forward(); } delay(100); } long microsecondsToInches(long microseconds) { // According to Parallax's datasheet for the PING))), there are // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per // second). This gives the distance travelled by the ping, outbound // and return, so we divide by 2 to get the distance of the obstacle. // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf return microseconds / 74 / 2; } I have an arduino uno with a seeedstudio motor shield and a ping sensor, I need to include a servo sketch to sweep a servo. But for now its as is till I progress with this sketch. All the tank does is back up, turn and repeat. The ping sensor seems to be active but its not going forward ,when nothing is clearly in its path. ( I switched my wires around so the tank goes forward now. It seems like the ping sensor Is not giving the motors any instructions on where to go. I will look at my Ping later today and see what kind of readings its getting in the serial monitor, I have not had a chance to do so yet. Its light barely blinks when everything is running, which makes me assume that it is not functioning properly)

I guess I am asking: How do I change this so it drives forward and avoids walls with the ping sensor.

It looks like the code should do that.

If it doesn't, you need to explain what it does, instead. What distance are you actually getting from the ping sensor? Is it reasonable? With no Serial.begin() and no Serial.print() statements, you don't know. The first thing to do is to correct that. You must know whether the data is accurate and reasonable before it is meaningful to use it.

Quote

The ping sensor seems to be active but its not, going forward at all, when nothing is clearly in its path.

I suspect that some of the commas in that sentence are in the wrong place, because I'm having real troubles parsing it.

The art of getting good answers lies in asking good questions.

Jdawg

I am currently still reading and trying to learn the sketch language, so im not sure how to correct the Serial.begin() and Serial.print() statements ( I see know that these statements are not in the sketch). I have not yet attempted to modify this sketch, I know it needs a little work to do what I require.

Just like about every other sketch that uses serial communications, the "Serial.begin()" goes in your "setup()", and the Serial.print()"s go wherever you want to print a significant value or event.The IDE comes with examples of how to use them, just click on "File", then "Examples" then "Communication"

"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.I speak for myself, not Arduino.

pinMode(pinI1,OUTPUT); pinMode(pinI2,OUTPUT); pinMode(speedpinA,OUTPUT); pinMode(pinI3,OUTPUT); pinMode(pinI4,OUTPUT); pinMode(speedpinB,OUTPUT);}And something similar to this at the end of the script, to tell the motors to move according to what the ping sensor reads.

All of these sketchs I did not actually type myself, Most are copied out of arduino examples someone else wrote, so I understand very little of what is going on here.

You probably need to break your project into several parts and test each until you see what is going on. Start with testing the ping sensor by having the output sent to the serial monitor to see if what you get is what you expect.

Google forum search: Use Google Search box in upper right side of this page. Why I like my 2005 Rio Yellow Honda S2000 https://www.youtube.com/watch?v=pWjMvrkUqX0

Andakwa

I know the problem he has, I have the same issue. I have a Uno, Seeed Motor Shield v 2 & the ping sensor with 3 connectors, +, - & signal. I run the code for without the motor sheld code & the ping works fine. Once I add the motor code the sensor reading goes to 0in 0 cm in the serial monitor.... be low is the code.

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

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: pinMode(pingPin, OUTPUT); digitalWrite(pingPin, LOW); delayMicroseconds(2); digitalWrite(pingPin, HIGH); delayMicroseconds(5); digitalWrite(pingPin, LOW);

// The same pin is used to read the signal from the PING))): a HIGH // pulse whose duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object. pinMode(pingPin, INPUT); duration = pulseIn(pingPin, HIGH);

// convert the time into a distance inches = microsecondsToInches(duration); cm = microsecondsToCentimeters(duration);

long microsecondsToInches(long microseconds){ // According to Parallax's datasheet for the PING))), there are // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per // second). This gives the distance travelled by the ping, outbound // and return, so we divide by 2 to get the distance of the obstacle. // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf return microseconds / 74 / 2;}

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;}

I made the variable "obsticle" because when I tried to use :inches" in the if condition the compiler nagged me about inches not being defined for this scope or something similar. I have this on a magician chassis & it was just a simple if the is an obstacle within 13 inches it turns left.......