Which sleep mode is the most suitable

Hi there, I am doing research on choosing sleep mode for my Arduino in each cycle, which all the flash memory it has stored will be removed as well. And also, is that any function or commands can make the Arduino to restart from the very beginning after sleep mode..? Thanks!

Correction: I mean RAM, not flash memory..

It probably depends on which Arduino you are using ?

Are you confused between flash memory (where the program is stored) and RAM where the variables are stored ?

Clearing 'flash memory' at every sleep would require the Arduino to be re-programmed every time .............

1 Like

I am using Arduino Mega.. ohh , so I was talking about RAM,sry.. I don't mean to require it to be re-programmed every time

Tutorial about sleep modes: https://www.gammon.com.au/power.
The Arduino Mega 2560 is the same AVR family microcontrollers as the Arduino Uno. Most of the tutorial is for the Mega as well.

No, you can not clear the SRAM.
You can test that with unused SRAM. Store some data between the top of the heap and the bottom of the stack, press the reset button, and that data is still there.

The SRAM does not lose its data during a sleep-mode. All the variables keep their value. The clock signals uses energy, but keeping data in static ram does almost not use energy.

Some Arduino users jump to "vector 0" to restart an Arduino. That is not safe, since the microcontroller puts all the hardware in a off-state at powerup.

The WatchDog can be used to issue a real reset, just like pressing the reset button.

Can you tell more ? Why is the SRAM so important ? Do you want to clear it or do you not want to clear it ?

(maybe you noticed that I'm confused)

Thanks for providing reference..
FYI, I want it to clear all data it "collected" every time after passing sleep mode, which means it has no history data at all everytime it wakes up. And it will run the code from the very beginning until the sleep mode. The cycle keeps repeating.. I think is like reset..? but in software will do..

When a question seems strange, then it might be a XY-problem.

If you want to start without history data, then you can write your sketch to do that. You don't need to reset something.

Can you show your sketch ?

I suggest to solve it in software and write a sketch that does what you want.
What wakes up the Arduino ?
Is it running on batteries ? If not, then you don't need a sleep mode. Just let it run. It is not a computer.

The Arduino Mega 2560 is a large board. If the ATmega2560 microcontroller is put into a sleep-mode, then the others thing on that board still draw current. The Arduino Mega 2560 might be the worst choice when running an Arduino on batteries.

Yup.. it is running on batteries..
Basically how my sketch run is, communication between arduino and they are exchanging some data.. I know it still draws current even in sleep mode, but I just want to minimize the current drawn as little as possible.

woah.. first time knowing that,, do you mind to explain further?

Everything is open source, so you can check the schematic of the Arduino Mega 2560.
It has resistors for a voltage divider, a LED that is always on, two voltage regulators, some logic and a usb-serial chip which does not go into sleep mode. The ATmega2560 is also a older chip, that needs more current in sleep mode than the modern processors.

The Arduino MKR Zero is made to be run on batteries.

What about a hardware solution ?
Suppose the Mega board does its task and turns itself off by cutting the battery power with a mosfet or transistor. You need something to turn it on, for example a button.

It is not applicable in my case.. Imagining I have put all the Arduino to monitor the temperature in a farm,, it is bringing me trouble if I am using hardware to reset it everytime.

What wakes up the Arduino ?

hmm I thought of waking up Arduino programmatically.. is it

possible..?

You want to put it in sleep mode and then repeat the cycle.
So how does it know that it has to wake up to do a cycle ? Who or what does the Mega wake up from sleep-mode ?

My idea is to set a time for the sleep mode, after passing the time, the cycle repeats again

Why ?

A Pro Mini with the regulator removed is a far better choice.

You can use a RTC (Real Time Clock) to wake up via a interrupt, or the internal WatchDog.

The internal WatchDog can be used, for example, to sleep for 15 minutes.
A RTC can be used to wake up every Thursday at 15:03 or something like that.

It really is the worst board to run on batteries. Any other board is better. Can you change to an other board ?
The amount of wasted energy also depends on the voltages and the voltage regulator or DC/DC-converters.

1 Like

I have two choices : Arduino Mega and Uno, the latter does not have enough memory for my sketch. so I have to go with Mega..

An example using a Pro Mini;

"March 2021: Sometime in the last month the sensor stopped working, so the 155mAhr battery lasted around 14 months."

so there will be the two possible way to implement..?

I have no choice but proceed with Mega btw..

Why ?

budget issue..