maxresdefault

Data Logging with DS3231 RTC – Program and Testing

Getting Ready

The first step is to download the Arduino IDE software. The software is attainable at https://www.arduino.cc/en/software

After accepting the terms and conditions and confirming an email, the software is ready to use. If preferred, the web-editor can be used.

Next, it is required to download the DHT11 and DS3231 libraries. Once the libraries are downloaded, I included the libraries by going to the menu bar, sketch, include library, and add .ZIP library.

Sensor Testing

After downloading the DHT11 sensor library, I was able to run the code and gather/display the data (temperature, time, humidity, and heat index). The results should be similar as shown.

Code

#include “DHT.h”

#define DHTPIN 7 //Digital pin connected to the DHT sensor

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE); //Initialize DHT sensor

void setup() {
Serial.begin(9600);
Serial.println(F(“Printing Data”));

dht.begin();
}

void loop() {
delay(2000); //waits 2 seconds between measurements

float h = dht.readHumidity(); //Read temperature as Celsius (the default)
float t = dht.readTemperature(); //Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);

// Check if any reads fail
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F(“Failed to read from DHT sensor!”));
return;
}

float hif = dht.computeHeatIndex(f, h); //Compute heat index in Fahrenheit
float hic = dht.computeHeatIndex(t, h, false); //Compute heat index in Celsius (fahrenheit = false)

Serial.print(F(“Humidity: “));
Serial.print(h);
Serial.print(F(“% Temperature: “));
Serial.print(t);
Serial.print(F(“°C “));
Serial.print(f);
Serial.print(F(“°F Heat index: “));
Serial.print(hic);
Serial.print(F(“°C “));
Serial.print(hif);
Serial.println(F(“°F”));
}

Results: Web-Editor

Results: IDE

Screen Shot 2021-02-23 at 7.32.23 PM

Logging Data to SD Card

This part of the code initializes the SD card and checks if the SD card is present. 

This code writes into the text file the date and time from the RTC, and the temperature and humidity from the DHT11 sensor.

Results

The code creates a text file name “LoggerCD.txt” and writes all the data gathered from the sensor and RTC.  In the text file, a comma is used to separate the different data.

Leave a Reply

Your email address will not be published. Required fields are marked *

Latest Posts

Conclusion

Conclusion In conclusion, the goal for this project was met. The device was able to monitor and record data while appending and saving the data

Read More »

Future Work

Schedule The project concept began in August 2020. The design of the Nano Data Logger started in January 2021 and was completed in February 2021.

Read More »

Thank you for your message!

We will contact you soon!