If you want to RESET Arduino from the beginning without manually pressing the RESET button, there are a few ways. Here are two ways, using minimal wiring / circuitry. 

Step 1: using 1 wire connected to the RESET pin

1. electronically, using only 1 wire connecting an OUTPUT pin (12 in this example) to the RESET pin. (see the circuit)

In this example, pin 13, connected to the internal LED pin 13 is blinking. Pin 12 gets connected to the RESET pin by one wire.
-Typically, this would be a problem because when the application starts up, all pins get pulled LOW. This would therefore disable Arduino from every running. BUT, the trick is: in setup() function, the FIRST thing that happens is we write HIGH to the pin 12, which is called our reset pin (digitalWrite(resetPin, HIGH), thereby pulling the Arduino RESET pin HIGH. 
<p>Bonjour</p><p>Comment int&eacute;grer la routine reset dans mon sketch s.v.p ? car je tourne en rond</p><p><br></p><p><br></p><p>#include &lt;Wire.h&gt;</p><p>#include &lt;lcd.c&gt;</p><p>#include &lt;LiquidCrystal_I2C.h&gt;</p><p>#define sensorPin 0</p><p>#define DELAY1 10</p><p>DELAY2 #define 5000</p><p>#define relaisPin 8</p><p>// # define seuil 750</p><p>// # define Hysterese 2</p><p>#define I2C_ADDR 0x27 // &lt;&lt; ----- Ajouter votre adresse ici. Trouver de I2C Scanner</p><p>#define BACKLIGHT_PIN 3</p><p>#define En_pin 2</p><p>#define Rw_pin 1</p><p>#define Rs_pin 0</p><p>#define D4_pin 4</p><p>#define D5_pin 5</p><p>#define D6_pin 6</p><p>#define D7_pin 7</p><p>int n = 1;</p><p>cycles const int = 20;</p><p>LiquidCrystal_I2Clcd (I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);</p><p>int potPin = A0;</p><p>int potValue = 0;</p><p>int relaisValue = 0;</p><p>void setup ()</p><p>{</p><p> Serial.begin (9600);</p><p> lcd.begin (16,2); // &lt;&lt; ----- Mon LCD &eacute;tait 16x2</p><p>// Mettez le r&eacute;tro&eacute;clairage</p><p>lcd.setBacklightPin (BACKLIGHT_PIN, positif);</p><p>lcd.setBacklight (HIGH);</p><p>}</p><p>void loop () {</p><p> potValue = analogRead (potPin);</p><p> si (analogRead (0)&gt; 720)</p><p> digitalWrite (relaisPin, LOW);</p><p> else if (analogRead (0) &lt;715)</p><p> digitalWrite (relaisPin, HIGH);</p><p> retard (1000);</p><p> // Imprimer la valeur que vous lisez:</p><p> Serial.println (potValue);</p><p> retard (1); // Retard entre deux lectures pour la stabilit&eacute;</p><p> lcd.clear ();</p><p> lcd.print (&quot;Indice:&quot;);</p><p> lcd.print (potValue);</p><p> lcd.setCursor (0, 1);</p><p> lcd.print (&quot;Relais:&quot;);</p><p> lcd.print (&laquo;EDF&raquo; digitalRead (relaisPin) == HAUT: &quot;Solaire&quot;);</p><p> retard (DELAY2);</p><p> potValue = 0;</p><p>}</p><p><br></p><p>M&ccedil;i d'avance</p><p><br></p>
Ok, so teach me, why would I need to do this / want to do this? Why wouldn't this just loop, resetting over and over?
<p>This post is EXACTLY what I needed! The software reset (Step 2 in this instructable) works perfectly for what I need to do. I am using an nRF24L01+ 2.4GHz transceiver, with the RF24 library by ManiacBug, and I used the above software reset code to make my program more robust. In certain circumstances (for example, a brown-out on the 3.3V power pin to the RF24L01+ module), the transceivers lose connection and stop working. I tried for many hours to get the 2.4GHz modules to reset themselves and reconnect, but I could not figure it out. Finally, I wrote a code that says to each device, &quot;if you haven't received a successful packet in 100ms&quot; (average time to do so is 5ms for my code), &quot;then do an Arduino software reset.&quot; This works! Finally, I can get the modules to automatically reconnect if they have an anomaly that causes them to lose connection. So...to answer your question, this is where the software reset code is useful!</p><p>~Gabriel</p><p>electricrcaircraftguy.blogspot.com</p>
<p>BTW. This is exactly the same issue I've experienced and the reason I use this code. Very useful.</p>
<p>PS. more info. on the module is here: http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo</p>
You're right. In this example it will loop indefinitely. <br> <br>It could have more useful applications in larger programs though. For example.. <br> <br>I once wrote a program when I was in geometry for a watch to extend its functionality. After every set of numbers I input I wanted it to give me an answer, wait 5 seconds and then reset itself so it was primed up for another set of numbers. <br> <br>Admittedly this was a very lazy way for me do accomplish this but it got the job done. <br> <br>Hope that helps.
<p>Great article thanks! Step 1 works like a charm. Only problem is that once I set the reset pin to OUTPUT I lose connection to the programmer and the next time i go to upload avrdude complains that it can't access the board (like RX is blocked). So if you run into this, make sure you only enable the pin right before you release the board to use. Otherwise the only way I found I can reprogram the board is to disconnect/reconnect the board and quickly push out the newer version before that pin goes to OUTPUT.</p>
So happy I found this thread! I'm building a starter project of an autonomous wheeled bot with ultrasonics that fairly frequently report a ping of 0 when I start it up for the first few tries. <br>I decided to put a simple systems check into the setup so it will check the motors and ultrasonics are functioning both on the software side (ultrasonics), and the hardware side (enough juice in the batteries to run?).<br>The second method listed here finally solved my if statement problem I was having!
<p>Does the watchdog reset affect the external RESET pin? I mean WDT resets the device, does the RESET pin go LOW(assuming RESET pin to be active LOW and is tied high always)?</p>
<p>No, both reset circuits are completly sepereate.</p><p>Check the datasheet, chapter 11 Figure 11-1 for the &quot;Reset Logic&quot;. Arrows indicate a on-way signal, similar to a simple diode.</p><p>Hope this helps :)</p>
<p>This is really helpful. Tried using software reset and it worked for my project.</p>
<p>I used</p><p>asm volatile(&quot;rjmp 3584\n\t&quot;);</p><p>Where 3584=$0E00 (bootloader address) </p><p>But is little difficult ,because bootloader address can may differ from one arduino to other!</p><p>It's equivalent with hardware reset (reset button)</p><p>reset function to address 0, is not ecquivalent with hardware reset.</p>
<p>Thanks costy35. How would one go about finding out what the $0E00 bootloader address is for any given board?</p>
<p>Any board (atmega processor) have custom bootloader address. You can see and decode fusebit of ....</p><p> your_arduino_folder_program\hardware\arduino\boards.txt</p><p>and see fusebits... but here not talk about this problem ... it's only an idea!!!</p>
<p>thanks, very helpful :-)</p><p>the method 2 seems to work for me even out of a for loop, if using it in a if statement, but only if resetFunc function is declared before setup.</p>
<p>it really helped thanks</p>
<p>I tried to apply your sketch to reset the processor as soon as a number count was larger than 33. It did not work, I wonder if you can help.</p><p>Thanks a lot</p><p>Mitch</p><p>void(* resetFunc) (void) = 0;//declare reset function at address 0<br><br>void loop() <br>{ <br> <br> <br> <br> <br> for (int i=0; i &lt;= 255; i+=3){<br> Serial.println(i);<br> delay(1);<br> } <br> resetFunc();<br><br> if (i&gt;33) { <br> resetFunc();<br> } <br><br><br>} </p>
<p>you have to call the resetFunc() in side the &quot;for&quot; loop like.</p><p>void(* resetFunc) (void) = 0;//declare reset function at address 0</p><p><br>void loop() </p><p>{ </p><p><br>for (int i=0; i &lt;= 255; i+=3){<br>Serial.println(i);</p><p>if (i&gt;33) { <br>resetFunc();<br>}</p><p>delay(1);<br>} </p><p><br>}</p>
<p>Why should resetFunc() be called inside a loop? Why does it not work if it is called outside the &quot;for&quot; loop?</p>
<p>in the cord above ........ int &quot;i&quot; variable is declared inside the FOR loop, and infarct the variable that drives the FOR loop(till &quot;i&quot; reach 255)... And it is a local variable so it can not be accessed outside the loop... also in this case if some how we could access the &quot;I&quot;, by the time FOR loop finish it would be 255 :) </p>
<p>The for loop doesn't include what you want it to do. The way you coded it, it will continue up to 255 then reset, never reaching the if statement.</p><p>void(* resetFunc) (void) = 0;//declare reset function at address 0<br>void loop() <br>{ <br> for (int i=0; i &lt;= 255; i+=3){<br> if (i&gt;33) { //needs to be within the loop<br> resetFunc(); //to check i for greater than 33<br> }<br> Serial.println(i);<br> delay(1);<br> } <br> resetFunc();</p><p>//outside of loop, will never be looked at.<br>// if (i&gt;33) { <br>// resetFunc();<br>// } <br>} </p>
Is there a way reset millis to a previous time besides zero using this function?
If you look in any Atmel AVR datasheet they will explicitly tell you that this in not an acceptable method to reset a chip. Upon reset all I/O pins are set to input mode so you lose the LOW output from pin 12 in this example. This doesn't allow the reset low pulse to met the minimum low pulse width it has to be for a valid reset process. So use at your own risk. There is a valid way to reset a AVR chip in software without even needing a wired added as here. Just enable the watch dog timer and let it time out which will generate a true reset. Then in the setup function disable the WDT. <br>Lefty.
I've used this technique before just to see if it worked and it seemed useful. One comment though is that i would recommend using a resistor in there. Sending a high signal straight to the Reset pin could cause a short circuit and fry your chip. Not sure what would work better though, a pull up resistor from the reset pin to high, and allowing the &quot;resetPin&quot; to pull it low, or just placing a resistor between the two points.
There are and the WDT method for all the micros with WDT . <br>Setup the WDT and then make an infinity loop <br> <br> WDTCSR=(1&lt; WDTCSR= (1&lt; for(;;) <br> and in the 16ms the mcros will reset and the MCUSR variable will <br>have the value WDRF <br>With your software the MCUSR will have an Unspecified value. <br>
sorry but the code has modified the correct is<br> WDTCSR=(1&lt;&lt;WDE) | (1&lt;&lt;WDCE) ;<br> <br> &nbsp;&nbsp;&nbsp; WDTCSR= (1&lt;&lt;WDE)<br> <br> for(;;)
nice, never thought about this, thanks for posting!
Neato! Thanks for the tips!

About This Instructable


105 favorites


More by gabriellalevine: two ways to reset arduino in software DJI Groundstation instructions for flying an octocopter on autopilot interfacing u.fl connectors
Tags: arduino reset
Add instructable to: