#include "SPI.
h"
#include "DHT.h"
#include "DS3231.h"
#include "SD.h"
// Arduino data logger with SD card and DHT11 humidity and temperature sensor
#define DHTPIN 7 // DHT11 data pin is connected to Arduino pin 4
#define DHTTYPE DHT11 // DHT11 sensor is used
DHT dht(DHTPIN, DHTTYPE); // Initialize DHT library
DS3231 rtc(SDA, SCL);
void setup() {
File dataFile = SD.open("LoggerCD.txt", FILE_WRITE);
if (dataFile) {
dataFile.println("Date,Time,Temperature,Humidity"); //Write the first row of
the excel file
dataFile.close();
}
rtc.begin();
rtc.setDOW(FRIDAY); // Set Day-of-Week to SUNDAY
rtc.setTime(23, 31, 45); // Set the time to 12:00:00 (24hr format)
rtc.setDate(8, 11, 2019); // Set the date to January 1st, 2014 //INITIALIZING
PLX DAQ
Serial.println("CLEARDATA"); //clears up any data left from previous projects
Serial.println("LABEL,Date,Time,Temperature"); //always write LABEL, to indicate
it as first line
}
void loop() {
delay(500);
float t = dht.readTemperature();
Serial.print("DATA"); //always write "DATA" to Indicate the following as Data
Serial.print(","); //Move to next column using a ","
Serial.print("DATE"); //Store date on Excel
Serial.print(","); //Move to next column using a ","
Serial.print("TIME"); //Store date on Excel
Serial.print(","); //Move to next column using a ","
Serial.print(t); //Store date on Excel
Serial.print(","); //Move to next column using a ","
Serial.println(); //End of Row move to next row
File dataFile = SD.open("LoggerCD.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (dataFile) {
dataFile.print(rtc.getDateStr()); //Store date on SD card
dataFile.print(","); //Move to next column using a ","
dataFile.print(rtc.getTimeStr()); //Store date on SD card
dataFile.print(","); //Move to next column using a ","
dataFile.print(t); //Store date on SD card
dataFile.print(","); //Move to next column using a ","
dataFile.println(); //End of Row move to next row
dataFile.close(); //Close the file
}
else{
Serial.println("OOPS!! SD card writing failed");
}
}