Arduino automatically restarts
My Arduino automatically reboots unexpectedly. I do not open Seriam Monitor, I also do not touch the reset button. How to prevent Arduino from restarting unexpectedly?
Answer
There are some reasons cause Arduino reset automatically:
- Our of memory: ⇒ You need to re-write your code to reduce the memory usage. See how to reduce Arduino memory usage. You also need to check whether there is memory leek or not.
- Using String incorrectly: This can cause memory fragmentation, leading to the out of memory after long run. In this case, you should use String.reserve() function
- Wrong memory access: You wire data to memory that is not allow to write. For example, your array has only four elements, but you access beyond the boundary of the array. More detail in the below example code:
int myArray[4] = {1, 2, 3, 4};
void setup() {
Serial.begin(9600);
Serial.println("#### ARDUINO STARTED ####");
delay(500);
for (int i = 0; i <= 100; i++) {
myArray[i] = 5;
}
for (int i = 0; i <= 100; i++) {
Serial.println(myArray[i]);
}
}
void loop() {
Serial.println("NOT REBOOT");
}
- The output on Serial Monitor
COM6
#### ARDUINO STARTED ####
#### ARDUINO STARTED ####
#### ARDUINO STARTED ####
#### ARDUINO STARTED ####
Autoscroll
Clear output
9600 baud
Newline
- To avoid the restart, please make sure that your code does not access beyond your arrays.
- Power is not enough: If You connect the power pins of sensors/actuators directly to Arduino's 5V pin, and if your sensors/actuators consume much power, Arduino board may be restarted. In this case you can use external power supply for the sensors/actuators.
Buy Arduino
1 × Arduino UNO Buy on Amazon | |
1 × USB 2.0 cable type A/B Buy on Amazon | |
1 × Jumper Wires Buy on Amazon |
Disclosure: Some links in this section are Amazon affiliate links. If you make a purchase through these links, we may earn a commission at no extra cost to you.
Additionally, some links direct to products from our own brand, DIYables.
Additionally, some links direct to products from our own brand, DIYables.