0

I am a big noob I know that

but can this code be used to reset arduino board (instead of pressing the usual reset button on the board)

I want to reset the board as If am pressing the reset button using IR

int receiverpin = 2; // pin 1 of IR receiver to Arduino digital pin 2
#include <IRremote.h>
IRrecv irrecv(receiverpin); // create instance of irrecv
decode_results results;
void setup()
{
irrecv.enableIRIn(); // start the receiver
}
void(* resetFunc) (void) = 0; //declare reset function @ address 0

void loop()
{
 if (irrecv.decode(&results)) // have we received an IR signal?
{
if(results.value == 0x2FD847B) //if the button press equals the hex 
{
  resetFunc();
}
{
irrecv.resume(); // receive the next value
}
}
}
Mostafa
  • 3
  • 2

1 Answers1

1

Kind of, yes. That doesn't actually reset the Arduino, it just sends the program to address 0.

There are two other ways of performing the reset that do a proper full reset:

  1. Enable the watchdog timer and let it time out to reset the CPU.
  2. Connect an IO pin to the RESET pin - keep it in INPUT most of the time but set it to OUTPUT and LOW when you want to reset.

By just jumping to address 0 you aren't resetting the internal peripherals and registers to their reset state, so things like timers and such will still be running when they shouldn't be, etc. It's better by far to do a real reset instead of just jumping to 0 like that.

Majenko
  • 105,851
  • 5
  • 82
  • 139