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
}
}
}
0

1 Answer 1

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.

8
  • i read about both these methods and they won't allow me to reset using IR
    – Mostafa
    Oct 24, 2015 at 22:10
  • @mostafa And what gives you that impression?
    – Majenko
    Oct 24, 2015 at 22:13
  • well the first one is a pre-set timer right?? no matter what when the timer run out the board will reset I can't see using IR here
    – Mostafa
    Oct 24, 2015 at 22:20
  • @mostafa You only enable the timer when it is time to do the reset. The rest of the time it's disabled so absolutely nothing happens.
    – Majenko
    Oct 24, 2015 at 22:21
  • oh the second method you want me to connect an IO pin to the reset pin now I get it but won't that contain soldering ????
    – Mostafa
    Oct 24, 2015 at 22:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.