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
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.