58Views10Replies

Author Options:

Arduino starts up automatically Answered

Hello instructables,

i ran the code below in the arduino uno, (4 motors, 2 L293D driver chips)

void loop()
{

  digitalWrite(motor_pin1,LOW);    //forward back
  digitalWrite(motor_pin2,HIGH);
  digitalWrite(motor_pin3,HIGH);   
  digitalWrite(motor_pin4,LOW);
  digitalWrite(motor_pin5,LOW);    //forward front
  digitalWrite(motor_pin6,HIGH);
  digitalWrite(motor_pin7,HIGH);   
  digitalWrite(motor_pin8,LOW);
  delay (5000);
 
  digitalWrite(motor_pin1,HIGH);   //turn right 
  digitalWrite(motor_pin2,LOW);
  digitalWrite(motor_pin3,HIGH);  
  digitalWrite(motor_pin4,LOW);
  digitalWrite(motor_pin5,HIGH);   //turn right 
  digitalWrite(motor_pin6,LOW);
  digitalWrite(motor_pin7,HIGH);  
  digitalWrite(motor_pin8,LOW);
  delay (2000);
 
  digitalWrite(motor_pin1,LOW);    //stop moving
  digitalWrite(motor_pin2,LOW);
  digitalWrite(motor_pin3,LOW);   
  digitalWrite(motor_pin4,LOW);
  digitalWrite(motor_pin5,LOW);    //stop moving
  digitalWrite(motor_pin6,LOW);
  digitalWrite(motor_pin7,LOW);   
  digitalWrite(motor_pin8,LOW);
 
  while (1);
}

by right, the motors should stop infinitely due to the while(1), but this is what happens instead :

initial                 : loop1
12 secs later   : loop 2
1 sec later        : loop 3
1 sec later        : loop 4 ....

why is it running more than once?

10 Replies

user
fujiapple (author)2012-04-14

i think i found out whats wrong!

i initialized an unused pin.

(i covered some parts of the code for the trial run, but i didnt remove the pin initialization, didnt think that would cause any problem..)

thanks a lot for the help steveastrouk!

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)fujiapple2012-04-15

Moral: post ALL your code......

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)2012-04-14

ELectrical noise from your motors is making the chip behave oddly.

Steve

Select as Best AnswerUndo Best Answer

user
fujiapple (author)steveastrouk2012-04-14

how should i go about removing these noise?

also, i did accidentally put the motor output in the groud pin, would that have affected the arduino in anyway ? (the chip was alright, for i swapped it with a new chip, and the problem persisted. )

thanks for the reply

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)fujiapple2012-04-14

Show me a photo of your layout, and your circuit. A poor quality PSU may also be causing the problem. And I am presuming you are using DC motors ? Have you put any suppression on them ?

Select as Best AnswerUndo Best Answer

user
fujiapple (author)steveastrouk2012-04-14

Erm they are all on the breadboard, no pcbs.

basically 2 L293D's, pins are plugged in according to the datasheet,
Vs of IC 1 is connected to Vs of IC 2. (+ve terminal of the power source goes right to the Vs)

2 DC motors powered by 6V (4 AA's).

do you need a picture of the breadboard ? though i doubt if its gonna be of any help, rather messy with all the wires going around.

(Initially with 2 motors there was no prob, but when i added 2 more motors, this started to happen)

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)fujiapple2012-04-14

do you need a picture of the breadboard ? though i doubt if its gonna be of any help, rather messy with all the wires going around.

There my friend lies your problem....

Steve

Select as Best AnswerUndo Best Answer

user
fujiapple (author)steveastrouk2012-04-14

hahah yea i know, but i did check through all the connections...
(the motors run fine, but they repeat the cycle after sometime)

could the hardware affect the program? i thought this was more of a software problem.

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)fujiapple2012-04-14

No, the program has an unquivocal infinite loop at the end.

Take the motors out, put an LED in instead (with a suitable resistor !!!) and try again.

I'll bet it works.

Steve

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)fujiapple2012-04-14

Messy. Take the power to the motor section from separate feeds from the battery. Don't connect the grounds at the computer, connect them at the battery ALONE.

What's current are the motors pulling when they are switched on ? ANswer: about 10x the normal running current.....

Steve

Select as Best AnswerUndo Best Answer