0% found this document useful (0 votes)
96 views

Data Logger 4 Sensor

This Arduino code uses a DHT11 temperature and humidity sensor to log sensor readings to an SD card and serial monitor. It initializes the DHT11 sensor, DS3231 real-time clock (RTC), and SD card. In the setup, it prints header labels and clears any previous data. In the loop, it reads the temperature, prints the data to the serial monitor and logs it to the SD card along with the date and time from the RTC.

Uploaded by

JUGI
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views

Data Logger 4 Sensor

This Arduino code uses a DHT11 temperature and humidity sensor to log sensor readings to an SD card and serial monitor. It initializes the DHT11 sensor, DS3231 real-time clock (RTC), and SD card. In the setup, it prints header labels and clears any previous data. In the loop, it reads the temperature, prints the data to the serial monitor and logs it to the SD card along with the date and time from the RTC.

Uploaded by

JUGI
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#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");
}
}

You might also like