Arduino Constantly Restarting

We have an ATMEGA328 that keeps turning on and off. The power LED blinks. Because of this, it loops through setup() infinitely. Is this a problem with the board, the power source, any other ideas?

What sketch are you running? How frequently is it rerunning setup()? What are you using to power your arduino?

The following thread has useful information on the best method to format a question to maximize your likelihood of getting a solution.

http://arduino.cc/forum/index.php/topic,97455.0.html

We are using a 9.6 volt battery pack and it is running setup about every second. We have 2 servos hooked up to it right now.

Navigation_of_Autonomous_Vehicles.ino (15.9 KB)

barnaby:
We are using a 9.6 volt battery pack and it is running setup about every second. We have 2 servos hooked up to it right now.

Hold the reset button, click upload, release reset button.
Hope that helps!

barnaby:
We are using a 9.6 volt battery pack and it is running setup about every second. We have 2 servos hooked up to it right now.

  • How do you know it is re-running setup() every second? What behavior is occurring?
  • What type of arduino are you using?
  • A circuit description would help
  • A review of the previous link on how to ask questions would help us help you

Thanks @Elitism, but unfortunately that didn't solve the problem :frowning:

@wanderson:
I added a series of println in the setup and loop and watched the serial monitor. It repeats the setup loop despite there not being any continuous loop in it.

We have an Arduino atmeag326 duemilanove.

The sketched previously worked a few years ago for a different person. It compiles but the Arduino power LED keeps flashing. Unfortunately, the past person did not post a schematic. To describe the circuit the Arduino has an AF Motor shield that routes power to 2 servo motors, a ping(((, and a CMUCam4, and RC car motor. We are trying to create an autonomous vehicle using color tracking.

I hope that this information is enough. Thanks for your help.

With the information you have provided, I suspect that the most likely cause of the problem is electrical noise being caused by the motor shield, or possibly, a problem with the power supply being unable to meet the demands of the motor and causing a brown out.

First I would try a more stable, higher power supply, rather than the batteries your using.
Second, if available I would use an oscilliscope to probe the power rails for electrical noise, barring that, additional decoupling capacitors on the power pins, and possibly the reset pin as well.

What kind of routines do you have in your setup() function? Are you trying to move the servos or motors from within setup at all?

Does it stop if you disconnect the servos and/or motors?

Do you see the same problem with a blank sketch?

Disconnect the motors. If the ATmega continues to reset, it would suggest a software problem.

The most likely cause is the motors are drawing more current than your batteries can supply. Put a Multimeter on Vin and/or the 5V node and what watch happens to the voltage.

Are the motors connected through the Arduino's 5V, directly to the battery, or through Vin?

If they are connected to the Arduino's 5V, there is no doubt in my mind, that the regulator is going into thermal shutdown.

In the motors section Sparkfun guide for the Arduino Starter Kit, they say that if your Arduino keeps resetting, it is because the motors are producing noise. They say that you should put a 220uF capacitor between GND and power source of the motor to minimize any noise.

Hi everyone. We looked at all of the problems you suggested. We ended up realizing that the error is not in hardware, but is in the code somewhere in the function posted below. The arduino resets without completing the line "strcpy(Tarray,ptr);" It is C++ reference code. Let us know if you have any ideas! Thanks again.

char *ptr, Tarray[7][4];

/** Converts the character array found in the data function to integers that the program can easily use. */
void convert() 
{
int i=0;
ptr=strtok(x," "); // pointing to first number
while (ptr!=NULL)
{
strcpy(Tarray,ptr); // load number into Tarray
ptr=strtok(NULL," "); // set ptr to next number in string
i++; // repeat loop and add 1 to i
}
mx = atoi(Tarray[0]);
my = atoi(Tarray[1]);
x1 = atoi(Tarray[2]);
y1 = atoi(Tarray[3]);
x2 = atoi(Tarray[4]);
y2 = atoi(Tarray[5]);
}

NOTE: x is a array here is the code that writes data to it:

void data()
{
  byte inbyte;

	for (int i=0; i <= 35; i++)
	{
               
		inbyte = camera.read();
		x[i] = inbyte;

	}
	x[35] = 0;
}

Moderator edit: COde tags added to remove italics.

You need to post ALL the code.

The code is posted in the third post as an attachment and it is too long for me to post. Sorry.

As far as I know the only thing (software based) that can cause the avr to restart is the watch dog reset. It is possible that misdone pointer code can accidentally turn that on, but to have such behavior routinely repeated is very unlikely. Your sketch is fairly lengthy, so my suggestion is to gradually remove sections of the code until the problem goes away, then post that information here and perhaps we can help.

Before doing that I would disconnect all motors and see if the problem continues to occur with the same code.