SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By jped
#147635
Ok I have this arduino powered autonomes car. It uses a Sharp proximity sensor. It runs well when it does not sense anyting but when i put my hand near it sometimes is turns but other times it stops and the motor moves a tiny bit and then it stops.

Here is a video ..... http://www.youtube.com/watch?v=qrxh59XD ... e=youtu.be

Side comments

when it stops the tx and rx lights on the arduino are flashing (simmilar to when it finds an object). After a while (a minute or two... or sometimes never - have to restart it) when it continues going strait it stops blinking.



this is my code





int d1a=13;

int d2a= 12;

int s1= 10;

int d1b=11;

int d2b=8;

int sb=9;

int sensorPin = 5;

void setup () {

Serial.begin(9600);

pinMode (d1a, OUTPUT);

pinMode (d2a, OUTPUT);

pinMode (s1, OUTPUT);

pinMode (d1b, OUTPUT);

pinMode (d2b, OUTPUT);

pinMode (sb, OUTPUT);

}

void loop () {

int val= analogRead (sensorPin);

Serial.println (val);

if (val > 520) {

analogWrite (10, 255);

digitalWrite (13 , HIGH);

digitalWrite (12, LOW);

analogWrite (9, 255);

digitalWrite (11 , HIGH);

digitalWrite (8, LOW);

delay (1500);

analogWrite (10, 190);

digitalWrite (13 , HIGH);

digitalWrite (12, LOW);

analogWrite (9, 190);

digitalWrite (11 , LOW);

digitalWrite (8, HIGH);

delay (1000);



}

else {

analogWrite (10, 200);

digitalWrite (13 ,LOW);

digitalWrite (12, HIGH);

analogWrite (9, 200);

digitalWrite (11 , LOW);

digitalWrite (8, HIGH);

}

}
User avatar
By shimniok
#147652
Sometimes it's best to take tiny steps and test each. When troubleshooting it helps to isolate the cause of the problem as best you can.

Make sure everything is wired correctly, battery charged, all the basic things.

Now, try removing the code related to sensing something. Remove the analogRead the if-else statement. Leave behind only the code that it would normally run with no sensed object. This stuff:

analogWrite (10, 255);
digitalWrite (13 , HIGH);
digitalWrite (12, LOW);
analogWrite (9, 255);
digitalWrite (11 , HIGH);
digitalWrite (8, LOW);
delay (1500);
analogWrite (10, 190);
digitalWrite (13 , HIGH);
digitalWrite (12, LOW);
analogWrite (9, 190);
digitalWrite (11 , LOW);
digitalWrite (8, HIGH);
delay (1000);

Does it work? What if you put your hand in front of the sensor while it is running? If it fails then the problem relates to the sensor and it's in hardware not software.

Sharp sensors are notorious for generating electrical noise so it is conceivable that this is an issue. Most folks solder a 10µF cap across the power leads of the sensor. This helps to isolate current draw spikes which are the source of noise.

If it works fine, then possibly there's a bug in the original software you posted. Next try running the else {} code

analogWrite (10, 200);
digitalWrite (13 ,LOW);
digitalWrite (12, HIGH);
analogWrite (9, 200);
digitalWrite (11 , LOW);
digitalWrite (8, HIGH);

Does it do what you expected it to do? What is it that you expected it to do? If it's not doing what you expected, then there's a problem with this section of the code.

That's a start at least.
By jped
#147670
good advice... I tried that and it seems to go strait well but when i program it to turn, it doesnt go. Could it possibly be that it is not getting enough current?