Let's Make Robots!

When you only need one button

OddBot's picture
Use the reset button on the Arduino as an input button

Have you ever written a simple Arduino application that just needed a single button? Most Arduino's and their clones have a reset button. Depending on your application you might find you can use the reset button as an input.

Recently I set up a robot arm for a display at an exhibition. It just sits on the table and runs through a set of pre-defined moves. I wanted to be able to adjust the speed but I did not want to spend time wiring up a pot, drilling mounting holes etc.

My solution was to store the speed variable in the EEPROM. The EEPROM memory can store information when the power is off or the processor is reset. According to the datasheet it should be good for 100,000 presses of the reset button. Every time the program runs the speed is incremented by a set amount and the new value is written to the EEPROM at address 0.

Now when I press the reset button the program cycles through 4 different speeds from 10 to 40 in increments of 10. Note: If your EEPROM has never been written to before then all bytes will be set to a value of 255. Below is an extract from my code.

#include  <EEPROM.h>                           // you must include this to access your EEPROM memory
byte Speed;                                             // this is my variable for a time delay

void setup()
{
   Speed=EEPROM.read(0);                     // read the last speed setting used from the EEPROM
   if (Speed<20 || Speed>40) Speed=50;  // if it is not a valid amount then set it to 50. It will be 255 the first time
   Speed-=10;                                           // decrement my delay time by 10 every time the program runs
   EEPROM.write(0,Speed);                      // store the new value back in the EEPROM for next time
}

void loop()
{

}

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
MrAlexis44600's picture

again, thank you! I had never seen any programs using EEEPROM.

they always told me "do not touch to the eeeprom, it can only be used 1000000 times before dying!" (not sure of the number of zeros)

And as always your sketch is short and efficient :)

Uzimonkey's picture
I wouldn't really worry about wearing the EEPROM out in your arduino by doing something like this. Even if you do eventually wear it out, a new micro controller for the arduino isn't much money. Parts are for using, don't be afraid to use (and possibly use up) your hardware.
OddBot's picture
Glad to help. It is true that you should not use the EEPROM to store calculations that are being done 100's of times a second. You would kill it very quickly. That is what the SRAM is for. For this application you would wear the button and your finger out first.
bittybot's picture

As one guy put it your probably going to have fried your micro or have your project stolen by a dog before the EEPROM wears out.

so i use it regularly. Cool idea though. once though about this once just glued a button on a empty space.