Arduino Reset Hack

Something I’ve been meaning to share with the world is this nifty hack I discovered while prototyping the Weather Tunnel sensor modules.

If you’ve ever needed to, you’ve discovered that there is in fact no way to RESET an Arduino board through code. If you truly want your Arduino to RESET entirely you have two options: pull the RESET to LOW using a physical connection, or remove the power supply and then connect it again (turn it on and off).

For the Weather Tunnel modules, I used the Arduino Ethernet Shield. It’s very well designed, and has worked perfectly for our needs. However, when it’s on and connecting perfectly to the internet, it tends to timeout after 2 or 3 days. Our sensor modules need to be plugged in and connecting for months on end (they were deployed in April, will be running through August minimum).  When this timeout occurs, there is no cure other than to reset the board.  I couldn’t ask our partner institutions to constantly monitor the module and disconnect/reconnect the box every 3 days, so I needed to find a way to RESET the board through code (ie one of the digital pins).

I’m sure you’re thinking to yourself — well fine, let’s use a little transistor and have a digital pin toggle GND to the RESET pin when we want. Yes, this definitely works, and is absolutely a better solution than my hack. However, this board is already crowded as it is, and I wanted to use minimal wiring. So i found a way to do it with a single wire connected to the RESET pin.

Check it out.  By connecting any digital pin directly to the RESET pin on the Arduino will not work because upon start up, the Arduino automatically pulls those pins low when they are declared OUTPUT in the setup() loop. The hack here is extremely simple: Pull that digitalPin HIGH before ANYTHING ELSE.

//digitalPin 7 is connected to the RESET pin on Arduino
//NOTE: you CANNOT program the board while they are connected
//by default digitalPin 13 will blink upon reset, so stick an LED in there

int interval = 5000;
long int time = 0;

void setup(){
  digitalWrite(7, HIGH); //We need to set it HIGH immediately on boot
  pinMode(7,OUTPUT);     //We can declare it an output ONLY AFTER it's HIGH
                         // (( HACKHACKHACKHACK ))
  Serial.begin(9600);    //So you can watch the time printed
}


void loop(){

  time = millis();
  
  Serial.println(time);
  
  if(time > interval){
    Serial.println("RESET!");
    digitalWrite(7, LOW); //Pulling the RESET pin LOW triggers the reset.
  }
}
 

And that’s it. Tested on ArduinoMega2560 and Uno. Hopefully this is useful for someone out there.

There is a caveat, however. When programming your board, you must remove this connection, because upon programming digitalPins are pulled low. Your board will just try to reset itself while programming and you’ll taste failure. hmm delicious.

posted in development, hardware | tagged , , , | Comments (0)