Go Down

### Topic: Arduino line follower (Read 2076 times)previous topic - next topic

#### carme

##### Apr 18, 2012, 11:16 am
Hi,

I'm doing a little line follower robot, and I'm having problems when uploading the code to the arduino mega2560.
Everything is working find while I have de usb wire connecte to my computer but when I disconnect it from arduino board, the robots starts doing crazy things, somebody can help me?
It's my first robot and I'm a bit lost.

Thanks

I have attached the code used

#### Bajdi

#1
##### Apr 18, 2012, 11:22 am
How are you powering the Mega when it's not connected to USB?
www.bajdi.com

#### AWOL

#2
##### Apr 18, 2012, 11:27 amLast Edit: Apr 18, 2012, 11:32 am by AWOL Reason: 1
Code: [Select]
`long readPing1(){  // establish variables for duration of the ping,  // and the distance result in centimeters:  long duration1, cm1;  // 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(pingPin1, OUTPUT);  digitalWrite(pingPin1, LOW);  delayMicroseconds(2);  digitalWrite(pingPin1, HIGH);  delayMicroseconds(15);  digitalWrite(pingPin1, LOW);  delayMicroseconds(20);  // 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(pingPin1, INPUT);  duration1 = pulseIn(pingPin1, HIGH);  // convert the time into a distance  cm1 = microsecondsToCentimeters(duration1);  Serial.print(cm1);  Serial.print("cm");  Serial.println();  delay(10);  return(cm1);  }`
You've got three near-identical functions - why?

Code: [Select]
`positionOpto=(o1*0+o2*1000+o3*2000+o4*3000+o5*4000+o6*5000+o7*6000+o8*7000)/28000;`
I can think of simpler ways of ignoring "o1".
"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.

#### carme

#3
##### Apr 18, 2012, 11:31 am
When the usb is not connected I'm using a battery to supply voltage to the engines and the arduino board and sensors.

I have three similar functions because I'm using three ultrasonics sensors.

#### AWOL

#4
##### Apr 18, 2012, 11:33 amLast Edit: Apr 18, 2012, 11:37 am by AWOL Reason: 1
Quote
I have three similar functions because I'm using three ultrasonics sensors.

But it is the same code, the only difference is the Ping interface pin.
Code: [Select]
`long readPing(const int pingPin){  // 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(15);  digitalWrite(pingPin, LOW);  delayMicroseconds(20);  // 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);  long duration = pulseIn(pingPin, HIGH);  // convert the time into a distance  long cm = microsecondsToCentimeters(duration);  Serial.print(cm);  Serial.println("cm");  delay(10);  return cm;  }`

Quote
When the usb is not connected I'm using a battery

What sort of battery?
"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.

#### carme

#5
##### Apr 18, 2012, 12:21 pm
Yes, the only difference is the pin. Can I ready three ultrasonic sensors with just one function?
The battery I'm using is a valve regulated lead acid battery about 12V, and for arduino and sensors I'm using a L7805 to provide 5 V.

#### AWOL

#6
##### Apr 18, 2012, 12:25 pm
Quote
Yes, the only difference is the pin. Can I ready three ultrasonic sensors with just one function?

Yes, you can, and unless you want to type and debug three functions instead of just one, you should.

Where are you feeding the 5V from the regulator to?
"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.

#### carme

#7
##### Apr 18, 2012, 01:06 pm
To the power supply connector on arduino board, and to the ultrasonic sensors. I have measured and all voltage values are correct. Do you this could be the problem that the program just work when it is the usb wire connected to my PC?

#### AWOL

#8
##### Apr 18, 2012, 01:55 pm
Difficult to say; just stating:
Quote
the robots starts doing crazy things
could mean lots of things - is the robot quoting Edwin Lear, or Jack Kerouac?
Performing a pas-de-deux?

I'd probably prop the robot up on blocks, run it off the battery and try to measure the 5V rail whilst it is operating.
"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.

Go Up

Please enter a valid email to subscribe