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 DHT11long 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?