how to sleep arduino atmega328p so that the memory can not be erased

will anyone tell me how to save energy in arduino atmega328p?
I want to do a temperature sensor that will write it on the card every 1min
and when I use:
#include <JeeLib.h>
#include <avr / sleep.h>
but they both deleted me

#include <JeeLib.h>
#include <SoftwareSerial.h>
#include <SD.h>
#include <SPI.h>
#include "DHT.h"
#define DHTPIN 8
#define DHTTYPE DHT11

long seconds=00;
long minutes=00;
long hours=00;
int CS_pin = 10;

DHT dht(DHTPIN, DHTTYPE);
SoftwareSerial EEBlue(0, 1); // RX | TX
File sd_file;

void setup() {
pinMode(9, OUTPUT);
digitalWrite(9, HIGH);
delay(10000);
Serial.begin(9600);
pinMode(CS_pin, OUTPUT);
dht.begin();

while (!Serial) { ; }
Serial.print("Initializing SD card...");
if (!SD.begin(10)) {
Serial.println("initialization failed!");
while (1);
}
// Serial.println("done");

sd_file = SD.open("data.txt", FILE_READ);
EEBlue.begin(9600); //Default Baud for comm, it may be different for your Module.
// Serial.println("The bluetooth gates are open.\n Connect to HC-05 from any other bluetooth device with 1234 as pairing key!.");

sd_file = SD.open("data2.txt", FILE_READ);
if (sd_file) {
Serial.println("data.txt:");
while (sd_file.available()) {
Serial.write(sd_file.read());
} sd_file.close();
} else {
Serial.println("error opening file");
}

sd_file = SD.open("data.txt", FILE_WRITE);
Serial.println("initialization done.");

if (sd_file) {
}
sd_file.close(); //closing the file
}
void loop(){
sd_file = SD.open("data.txt", FILE_WRITE);
if (sd_file) {
delay(100);
digitalWrite(9, LOW);
senddata();
sd_file.close();}
else {
Serial.println("error opening file");
}
delay(1000);
}

void senddata() {
for(long seconds = 00; seconds < 60; seconds=seconds+5) {
float temp = dht.readTemperature(); //Reading the temperature as Celsius and storing in temp
float hum = dht.readHumidity(); //Reading the humidity and storing in hum
float heat_index = dht.computeHeatIndex(temp, hum);

sd_file.print(hours);
sd_file.print(":");
sd_file.print(minutes);
sd_file.print(":");
sd_file.print(seconds);
sd_file.print(", ");
sd_file.print(hum);
sd_file.print(", ");
sd_file.print(temp);
sd_file.print(", ");
sd_file.println(heat_index);

Serial.print(hours);
Serial.print(":");
Serial.print(minutes);
Serial.print(":");
Serial.print(seconds);
Serial.print(", ");
Serial.print(hum);
Serial.print(", ");
Serial.print(temp);
Serial.print(", ");
Serial.println(heat_index);

if(seconds>=55) {
minutes= minutes + 1;
}

if (minutes>59) {
hours = hours + 1;
minutes = 0;
}

sd_file.flush(); //saving the file
//delay(5000);
Sleepy::loseSomeTime(5000);

//delay(5000);
}
}

knows how to change it
long seconds
long minutes
long hours
they did not delete?

What does deleted me mean?
Where does Sleepy::loseSomeTime(5000); come from?
Please get you code inside code tags.

What do you intend to do to sleep the SD card ?

It will (or most do) go into a low power mode when inactive, but this could be 200uA or more depending on the type.

DKWatson:
What does deleted me mean?
Where does Sleepy::loseSomeTime(5000); come from?
Please get you code inside code tags.

from this library #include <JeeLib.h> is being used
Sleepy :: loseSomeTime (5000); to sleep 5 seconds for testing

srnet:
What do you intend to do to sleep the SD card ?

It will (or most do) go into a low power mode when inactive, but this could be 200uA or more depending on the type.

I was thinking about making a button which I will control on / off hc-05
but so far I am looking to save my batteries
because it will probably be powered by some AA or accumulator and have to last several days

As long as power is maintained, even in deep sleep, you will not lose the values of static or global variables.

1 Like

DKWatson:
As long as power is maintained, even in deep sleep, you will not lose the values of static or global variables.

just how I am in

Sleepy :: loseSomeTime (5000);

does not save me seconds all the time is 00
and if it is in a dream, the clock works
do you have any tutorial for this?

Excellent tutorial on sleep modes.

Please use code tags ("</>" button) when posting code.