Many times, when working with a plate Arduino Uno, it is necessary to restart it without physical intervention, either because the device is in a hard-to-reach location or because we want to automate the process within the code. Fortunately, there are several methods to perform a reset Arduino Uno by software, each with its own specific advantages and applications.
In this article we will see different ways to restart a Arduino Uno through code, from using function pointers to using digital pins to generate an external reset. We will also explore how the Automatic reset when connecting via serial port and how to avoid it if it causes problems in our projects.
To reset Arduino Uno using function pointers
One of the most used methods to restart a Arduino Uno from the code is the use of a function pointerThe idea is to assign memory address 0 to a function pointer and call it to cause the processor to perform a system reset. You can learn more about related projects in the guide of Arduino Uno.
The basic code for this method is as follows:
String letra = "";
int x = 2;
void(* resetSoftware)(void) = 0;
void setup(){
Serial.begin(9600);
Serial.println("Iniciando.");
}
void loop() {
if (Serial.available() > 0) {
letra = Serial.readString();
Serial.println(letra);
if(letra.indexOf("v") > -1){
x = x + 5;
Serial.println(x);
Serial.println("Reseteado.");
delay(500);
resetSoftware();
}
}
}
In this case, when the letter "v" is sent to the Serial Monitor, the board adds 5 to the variable x, prints the new value and then executes the reset by invoking resetSoftware(). This returns the microcontroller to its initial state as if the reset button had been pressed. For other programming methods, you can refer to the Guide on using millis in Arduino.
Reset the Arduino Uno using a digital PIN
Another way to perform a soft reset is connecting a digital pin to the reset pin from the board. This is achieved by simply connecting a wire between an output pin (such as pin 10) and the Arduino's RESET pin. This method is useful if you're looking for a quick solution without modifying the bootloader.
The code for this method is as follows:
String letra = "";
int x = 2;
void setup(){
digitalWrite(10, HIGH);
Serial.begin(9600);
Serial.println("Iniciando.");
pinMode(10, OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
letra = Serial.readString();
Serial.println(letra);
if(letra.indexOf("v") > -1){
x = x + 5;
Serial.println(x);
Serial.println("Reseteado.");
delay(500);
digitalWrite(10, LOW);
}
}
}
In this case, sending the letter "v" through the Serial Monitor pulls pin 10 low, which resets the board. This is a practical alternative when you need to reboot the system from software without modifying the bootloader code. If you need more information about Arduino connectivity, we recommend reading about Arduino Nano.
Automatic reset of Arduino when connected via serial port
Plates Arduino Uno They have an automatic reset mechanism when a connection is established through the serial port. This happens because the DTR line of the ATmega8U2 chip is connected by a 100 nF capacitor to the reset line of the ATmega328 processor. When the DTR is activated, a pulse is generated on the reset line that causes the Arduino to reset. This is a useful feature in many projects, such as those involving OLED displays, which you can explore in the Guide to 0.96″ OLED displays.
This mechanism allows the boot loader It has a shorter wait time and makes it easier to load new programs without having to manually press the reset button. However, in some cases, this can be a drawback if the code depends on a constant serial connection.
How to avoid automatic reset when using USB
If the automatic reset when connecting the Arduino to a computer causes problems with the project's operation, there is a simple solution to disable it. The board includes a small track that can be cut to avoid this behavior. This modification can be easily done if you know the basics of electronics, as explained in the Guide to stepper motor drivers.
To do this, simply locate the trace on the bottom of the board near the USB connector and cut it with a utility knife or scalpel. If you need to restore the auto-reboot feature in the future, you can re-enable it by soldering a small jumper between the two points on the trace.
Knowing how to disable auto-reset provides greater control over the Arduino's behavior when receiving data from the computer. Mastering these methods for resetting an Arduino Arduino Uno It provides greater flexibility in the development of electronic projects, allowing automation, debugging, and improvement of the behavior of embedded systems without the need for manual intervention.