Monday, October 12, 2020

3 Ways To Reset Arduino With Schematic And Program Code

3 Ways to Arduino Reset

3 ways to reset Arduino with schematic and program code - In some cases arduino project, we will need arduino restart or a reset mode of microcontroller to position the program at 0x00000000, which will impact the reading of the program from the beginning.

There are 3 methods to reset the Arduino and this can also be applied to other AVR variant microcontrollers (reset arduino uno, reset arduino nano and other), "Hard Reset ","Soft Reset", and "Combination" 

Hard Reset means that Arduino will reset when a trigger button is pressed, like we press the reset button microcontroller directly on the physical microcontroller (hardware).

Soft Reset means resetting the microcontroller via Program Codes (arduino reset command)

Combination means We will use the program code to trigger the reset pin so that arduino will read the program from the beginning.


A. Arduino Hard Reset

In the Arduino hardware reset method, we will need a button that is directly connected to the default arduino reset button pin.

Attention! in this hard reset method we don't say arduino boards like arduino uno, nano, micro and so on but we say atmega328, raight?.

In addition to the hard reset method, we give an example using the Arduino board.

For example ATmega328. The reset pin is on the PC6 pin. This microcontroller will reset if pin PC6 is in the LOW position.

So, if the reset button is pressed, PC6 will be connected to ground and a reset will occur.

To keep PC6 going HIGH as long as the button is not pressed, we need to use a Pull-up resistor to hang up at the HIGH voltage.

Common values of resistor pull-up is 10K. for the schematic you can see in the following image.

atmega328 reset button schematic
Arduino Reset Button


B. Arduino Software Reset

In the second program this is a simpler way to reset your Arduino. we using resetFunc to declare reset to address 0. 

This method does not need a schematic.

For program code arduino software reset, please upload the following arduino reset code program to your Arduino, then open Serial Monitor.

void (* resetFunc) (void) = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("Reset Succes");
  delay(5000);
}

void loop() {
  Serial.println("Go to Reset!");
  for (int cnt = 0; cnt < 20; cnt++) {
    Serial.print(".");
    delay(50);
  }

  Serial.println("");
  delay(3000);
  resetFunc();
  
  Serial.println("Reset Failed");
}


C. Arduino Auto Reset (Combination of Software and Hardware)

This method combine hardware and software.  Pin reset arduino will triggered by other digital pin.

Let's say we using pin digital pin 2 in this tutorial. you can use other digital pins, according to your needs. Look at this image.

arduino reset software
Arduino Reset Software

connect digital pin 2 to the reset pin. Upload the following program to your Arduino board, then click Serial Monitor. You can see whether your Arduino board has successfully reset or not.

#define pinReset 2

void setup() {
  digitalWrite(pinReset, HIGH);
  Serial.begin(9600);
  Serial.println("Reset Succes");
  pinMode(pinReset, OUTPUT);
  delay(3000);
}

void loop() {
  Serial.println("Go to Reset!");

  for (int cnt = 0; cnt < 20; cnt++) {
    Serial.print(".");
    delay(50);
  }

  Serial.println("");
  delay(3000);
  digitalWrite(pinReset, LOW);

  Serial.println("Reset Failed");
}

How this method work?

We first define the reset pin used, which is digital pin 2. Then for the setup () function, at the beginning of the program we immediately apply digital pin 2 to output High logic (1).

This results in the microcontroller never being "reset", because the microcontroller will reset when given Low (0) logic.

We initialize serial to be able to display data to Serial Monito with the command Serial.begin (9600).

Then in this part of the setup () function we give the command to the Serial Monitor that the Reset was successful. Why? Because when the reset occurs, it will definitely read the setup () function first and will tell us via the serial monitor that the microcontroller has been reset.

In the loop () function, the main command that does the reset is digitalWrite (pinReset, LOW);

When the reset pin receives logic Low (0) from digital pin 2, the microcontroller will reset quickly, and will read back the setup program () then loop ();

However, when the reset does not occur, the serial monitor will provide information. Reset failed, because we have made the command Serial.println ("Reset Failed");

#tags: reset pin arduino, arduino nano reset pin, reset arduino code, software reset arduino, reset button in arduino