Pages: [1]   Go Down
Author Topic: Arduino line follower  (Read 1379 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


* Main_prin.ino (13.17 KB - downloaded 13 times.)
Logged

Belgium
Offline Offline
Sr. Member
****
Karma: 1
Posts: 281
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How are you powering the Mega when it's not connected to USB?
Logged


Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25770
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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:
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".
« Last Edit: April 18, 2012, 04:32:08 am by AWOL » Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25770
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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?
« Last Edit: April 18, 2012, 04:37:35 am by AWOL » Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25770
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25770
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"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.

Pages: [1]   Go Up
Jump to: