Why is Arduino Auto-Resetting? Here’s What to Do


When I first started working with Arduino, one of the many errors that I encountered was auto-resetting. I couldn’t find a lot of help on the internet, so I had to figure out how to fix this error on my own. I thought I’d write this helpful article explaining how to fix an Arduino that’s resetting automatically, based on my experience.

Why is Arduino Auto-Resetting? This problem occurs because of hardware malfunctions and programming errors. The most common ones are:

  • Dip in Power
  • Using a Heavy Load
  • Programming Errors
  • Loose USB Connection
  • Computer Rebooting

While doing my projects with Arduino boards, I’ve managed to find out many reasons why Arduino auto-resets. Minor mistakes in the hardware and some coding errors are the primary culprits behind this problem. In this article, I’ll explain in detail what these issues are and how you can get rid of them in no time, based on my personal experiences.

What Is Auto-Resetting?

The reset function in Arduino starts the program from the first line of code. The usual methods of resetting Arduino are through the reset button, reset pin, reset function, or a watchdog timer. There are 5 simple ways to reset an Arduino board if what we want is to reset Arduino on purpose.

But if the auto-resetting happens randomly, without the user’s command, then this is more of a problem since nobody wants their Arduino to reset in the middle of a project that’s running successfully.

You can identify the auto-reset when the mini LEDs on your board turn off for a second and then start blinking again. Or when your project stops working for a second and starts working from the first line of code.

Why Does Arduino Auto-Reset?

Auto-reset can mess things up and destroy the purpose of your project. To stop Arduino from auto-resetting, you must first know why it happens, which might be for several reasons. Let’s take a look at them one by one.

Reason #1: Dip in Power

Arduino can auto-reset when there’s a dip in power supplied to it, which means that the energy decreases to zero and then increases back to the operating voltage, which momentarily switches the Arduino off and then switches it on again.

A dip in power can occur when using an unstable power supply in your Arduino project.

An unstable power supply can be a cheap battery, an unstable voltage from the DC adaptor, or a dip in power coming from your computer’s USB port.

A perfect power supply for Arduino is the one that provides a constant DC voltage of 5V without any dips that may cause the microcontroller to restart.

Reason #2: Using a Heavy Load

Are you using a heavy load in your Arduino project, such as a motor? Heavy loads require extra power and if the power supplied to your project is inadequate, Arduino will auto-reset and start executing the program from the beginning.

Any energy fluctuations can cause Arduino to reboot, without the user even knowing what happened.

Reason #3: Programming Error

Specific programming errors can also cause your Arduino to auto-reset.

Identifying a programming error as the reason behind Arduino auto-resetting is a challenging task because it might require you to inspect your entire Arduino code for mistakes, be it a program consisting of 2 lines of code or 200 lines.

Mini weather station project code error. Arduino IDE

One such error is to allocate a small size to an array or a memory buffer while it attempts to store more data than the memory can save. When this happens, Arduino will reset its code and start executing it from the beginning.

Reason #4: Loose USB Connection

Are you using a USB cable to power your Arduino board? Is the USB cable perfectly fitted in the USB slot?

A loosely fitted USB cable can be the culprit behind auto-reset in Arduino because the loose USB connector sometimes gets full power, and other times it receives zero power.

When Arduino receives full power from the PC, it works perfectly fine, but when the power reduces to zero, it stops working and then resumes when it receives power again, causing an auto-reset.

Similarly, if you’re using any other power source, a loosely fitted connection could be the reason behind the auto-reset.

Reason #5: Computer Rebooting

If you’re using your computer to power Arduino, then you need to watch out for rebooting and also keep an eye on the sleep timer.

Your Arduino project can reset if your computer restarts or sleeps for a while when left idle.

Powering Arduino through a PC doesn’t mean that you’ll keep an eye on the computer for the entire time your project is running, so chances are you don’t notice when your computer restarts or automatically sleep, causing Arduino to reset.

How to Stop Arduino From Auto-Resetting?

Now that you know why Arduino automatically resets let’s move on to troubleshooting the problem.

Here’s what you can do if your Arduino board is auto-resetting:

Check the Power Supply

If your Arduino board is automatically resetting because of a dip in power, then you need to check the output voltage of the power supply you’re using in the project. All you need is a multimeter with its knob set on DC voltage.

You can read more about using a multimeter to check power supplies here.

If your power supply is stable, then your multimeter would display a constant reading of around 5 Volts. Still, in case there’s an unstable power supply, you will immediately notice it on the multimeter display. The voltage reading will drop down and then rise again – showing instability.

Check Your Load’s Power Requirement

Another reason why your Arduino board is resetting is that you’re using a heavy load in your project.

To solve this issue, check your load’s power requirements from its datasheet and confirm whether your power supply meets those requirements. If not, then you should opt for a better power supply or replace your load with something that your power supply can support.

Check Your Program’s Memory Allocation

Program errors can cause Arduino to reset. Therefore, you should check the memory allocation of your Arduino program.

If you find that some arrays and variables are using more memory than what is allocated for them, then you need to increase the memory allocation of those arrays and variables.

Replace Your USB Cable

If your USB cable is the culprit behind the issue, then you need to replace it with a new one. Make sure that your new USB cable fits perfectly into the USB slot of your computer.

A good idea would be to buy the original Arduino USB cable from the Arduino website, and I bet with it, you won’t face such problems.

Increase Your PC’s Sleep Timer

If you are using your computer to power Arduino, then you must make sure that it does not sleep when left idle. The best way is to increase the sleep timer through the control panel. You can also set the timer to “never,” which means that your computer will never go into sleep mode even if it is left idle for 24 hours.

To learn more about adjusting sleep settings, click here.

An automatic reset can be a big problem if you’re using a counter or a timer in your Arduino project because resetting would restart the counter/timer from scratch, losing the count reached. It would defeat the purpose of many projects; hence, you must consider Auto-resetting as an issue and rectify it when needed.

Do you feel like digging in more on why your Arduino is auto-resetting?

Check out the following forum threads:

  1. Processing code is restarting my Arduino code (element14.com).
  2. Why does this code make my Arduino reset randomly? (reddit.com).
  3. Arduino resets periodically while being powered via an external power supply (instructables.com).
  4. What can cause Arduino to continuously restart? (stackoverflow.com).
  5. Why does Arduino auto-restart? (forum.arduino.cc)

Chris

Engineer and electronics enthusiast. Enjoys solving problems with electronics and programming.

Recent Posts