Arduino

Arduino Reset by Software and by Hardware

Arduino Reset, Reset Function For Arduino, How Te Reset Arduino by Software? How To Reset Arduino by Hardware? Resetting Restarting Arduino.

There are two methods to reset the arduino board, these methods are; by software and by hardware.

Arduino Reset by Software

Let’s assume we have a Set button connected to digital pin 8 for two purposes. And think that an event occurs(led lighting) when this button is pressed for a short time, and Arduino board reseted when pressed for a long time. (please connect also a resistance 1k ohm between GND and Digital pin 8 to prevent bounces on pin 8)

void(* resetFunc) (void) = 0; // reset function declared at address 0

int pressStart=0;
int pressEnd=0;
int pressedTime=0;
# define buttonSet 8
# define LED 13

void setup() 
{
  pinMode(buttonSet, INPUT); //set button defined as input
  pinMode(LED, OUTPUT); //Arduino’s own LED declared as output
  Serial.begin(9600);
  Serial.println("reset test..every time.."); // to see if Arduino board was reseted
}

void loop()
{
  if(digitalRead(buttonSet)==HIGH) //if set button pressed
  {
    updateFunc(); // call function to run LED or RESET function
  }
}

void updateFunc()
{
  pressStart=millis(); // press start time

  Serial.println("Button press detected..");
  
  digitalWrite(LED, HIGH);
  delay(50);
  digitalWrite(LED,LOW);

  while(digitalRead(buttonSet)==HIGH)
  {
    pressEnd=millis(); // detect button press ending time
  }

  pressedTime= pressEnd - pressStart;

  if(pressedTime>=3000)
  {
    resetFunc(); //call reset function to reset Arduino if set button pressed more than 3 seconds
  }
}
Arduino Software Reset and Serial Monitor
Arduino Software Reset and Serial Monitor

Arduino Reset by Hardware

First, connect one of Arduino’s digital pins to its RESET pin as shown below image.

Then set that digital pin as HIGH output. Arduino will reset itself every time when your program runs for the time specified in the program and pull the output to LOW.

#define OUTPUT_PIN 2
void setup() 
{  
pinMode(OUTPUT_PIN, OUTPUT);       
digitalWrite(OUTPUT_PIN, HIGH);
}

void loop() 
{     
    	delay(5000);
    	digitalWrite(OUTPUT_PIN, LOW);
}

Leave a Reply

Your email address will not be published. Required fields are marked *