Instructables

Arduino starts up automatically

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?

fujiapple (author) 2 years ago
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!
Moral: post ALL your code......
ELectrical noise from your motors is making the chip behave oddly.

Steve
fujiapple (author)  steveastrouk2 years ago
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
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 ?
fujiapple (author)  steveastrouk2 years ago
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)
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
fujiapple (author)  steveastrouk2 years ago
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.
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
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
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!