TransWikia.com

How to save data in arduino when it's power goes off

Arduino Asked by user63158 on December 1, 2020

I am doing a project ‘arduino based switch operation’. Here the user needs to set a time to turn on relay and set time to turn it off. The problem is that I want to supply power to arduino using adapter connected to the ac supply (where the relay will also be connected). When the on time is set and if power goes off for some time then this system doesn’t work. I want to save the data in arduino so that it will retain the data if power comes back.. So that my relay is operated on time..
How to do it guys???

3 Answers

Look up EEPROM. it is a memory that saves content even though power is off.

You can write data in EEPROM and when power comes back read it back.

there are safe ways to write in EEPROM without corrupting it.

Correct answer by Giorgi Tsintsadze on December 1, 2020

You Can do that by using RTC (Real Time Clock Module ) in your project.

Answered by Abdur Rahman on December 1, 2020

Beside Georgi's answer, I would like to tell you some details.

First :

a microcontroller can have a built-in EEPROM like the ATMega328 inside an Arduino UNO/Nano/mini, if not you would need to attach an external one, it can have may interfaces like SPI or IIC etc...

Second :

an EEPROM can hold only a specified amount of data, it can be 512byte like one on the ATMega328 microcontrollers, it can be only 64byte on others.

Third :

an EEPROM have addresses so for example in 8-bit EEPROM one address can hold only 8bits so values from (0-255) like on the ATMega328

Fourth : how to use it

In the beginning of your code you should first include the eeprom library

#include <EEPROM.h>

Then you would for example assign value "24" to one of the address on the EEPROM let's say address "1"

So you will use

EEPROM.write(1,24);

Of course you can power off you board and repower it again and that particular address will have the assigned 8-bit value "24".

To read back

EEPROM.read(24);

I hope that might help you or anyone else.

And as a side note an EEPROM have defined write and read cycles ~10000 maybe ~100000 after that amount it May not work.

Original documentation : here

Answered by Shams El-Deen on December 1, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP