Hi guys i'm new on the world of arduino...
so I have a problem with my project, i created datalogger with rtc and power sensor. I already created the system and it works, but i want to make the writing to sd card only happen on the 1st date every month. I can only think to set the delay, but not all of month consist 30 days so i kind of stuck right here. Hope somebody can help me with this problem. Here's my code so far
#include <SD.h>
#include <SPI.h>
#include <DS3231.h>
#include <PZEM004T.h>
PZEM004T* pzem;
IPAddress ip(192,168,1,1);
File myFile;
DS3231 rtc(SDA, SCL);
int pinCS = 53; // Pin 10 on Arduino Uno
void setup() {
Serial.begin(9600);
pinMode(pinCS, OUTPUT);
while(!Serial) { }
Serial.begin(9600);
while(!Serial3) { }
pzem = new PZEM004T(&Serial3);
pzem->setAddress(ip);
// SD Card Initialization
if (SD.begin())
{
Serial.println("SD card is ready to use.");
} else
{
Serial.println("SD card initialization failed");
return;
}
rtc.begin();
}
void loop() {
float e = pzem->energy(ip);
Serial.print(rtc.getDateStr());
Serial.print(",");
if(e >= 0.0){ Serial.print(e);Serial.println("Wh; "); }
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) {
myFile.print(rtc.getDateStr());
myFile.print(",");
myFile.println(float(e));
myFile.close(); // close the file
delay(3000);
}
}