Hello friends,
as i have posted a few questions about the bluetooth remote i have made which involves arduino, bluetooth and an android device...... i have completed the the project but i am a bit stuck as i am a noob.....so i wanted some help.
Load-shedding is a major problem where i live. Electricity is cut of after every 3 hr for an hr. during the day.
When i use bluetooth remote it always restarts the bootloader and restarts the program, when electricity is shut down from the grid, and then back on, even if the switches are on on the android device .
i want to know how should i program the arduino so that it can remember the state that it was in before the electricity failed and continue from where it left.
i hope u understand my problem.
first thing I would consider is to use a battery backup and power the core from a solar unit.
you can stop all external power use, but keep the program running when the power fails. can easily last a few hours between power loss.
that way, you never loose the connection.
another way is to have a temporary battery and when you lose power, your battery can dump the settings into eeprom.
thanks for the reply.....
i had the battery option in my mind but was wondering if it could be saved in the program itself.....
there must be a way as most of the appliances etc do the same...
but thanks for the reply anywoy
You don't say for sure, but it sounds like you are powering your Arduino off the mains.
One option might be a computer UPS.
You would have to look around to find the right one (here is an example):
I have absolutely no idea how long a 5v wall wart plugged into one of those things would run an Arduino, so like I say, you might need to look around for one with the right specs.
webaddic:
if it could be saved in the program itself.....
You'd have to write to storage- SD card, EEPROM.
http://arduino.cc/en/Reference/EEPROM
The program can store settings in EEPROM, say you "checkpoint" youd data every half hour or so, or if you know an outage is planned, store your settings a few minutes before that.
If you don't have much data, than a small battery backed SRAM could be used, such as the 56 bytes in an RTC chip like DS1307.
If a lot of data, more than will fit in 1K of EEPROM, than add an FRAM chip - fast access like SRAM, but non-volatile like EEPROM and with waaaaay higher durability (trillions of write cycles vs EEPROM's 10,000 or 100,000). Then you could write data I would guess as often as you want. After a reset, read the stored data back into your variable spaces/arrays/ whatever and proceed.
i am using atmega 328 by the way....... thanks for the replies. will read the eeprom option now and will ask for more help if required
thankyou all
CrossRoads:
than add an FRAM chip - fast access like SRAM, but non-volatile like EEPROM and with waaaaay higher durability (trillions of write cycles vs EEPROM's 10,000 or 100,000)
I didn't know what that was, so I looked it up.
http://www.kerrywong.com/2012/01/15/using-fram-as-nonvolatile-memory-with-arduino/
Very cool. Little surface mount buggers looks like.
There are thru hole parts also, check digikey & mouser.
Consider also structuring your code as a state machine plus a distinct "state object" that contains everything that matters. Makes checkpoint/restore to nonvolatile storage much simpler.