Temperature & Humidity Sensor With Date & Time on Arduino UNO WiFi R3 ATmega328P+Node MCU ESP8266 CH340G Compatible Board
by ohfood in Circuits > Arduino
14 Views, 0 Favorites, 0 Comments
Temperature & Humidity Sensor With Date & Time on Arduino UNO WiFi R3 ATmega328P+Node MCU ESP8266 CH340G Compatible Board

This setup uses the DHT22 Temperature & Humidity Sensor Module & DS1307 Real Time Clock Module with Arduino UNO WiFi R3 ATmega328P+Node MCU ESP8266 CH340G Compatible Board to provide Ambient Temperature & Humidity readings with time and date at 10 second intervals.
Supplies
- Arduino UNO+WiFi R3 ATmega328P+Node MCU ESP8266 CH340G Compatible Board
- DS1307 RTC
- DHT22 (AM2302) Temperature & Humidity Sensor
- M2M Jumper Wires - 04
- M2F Jumper Wires - 03
- USB Data Cable
Download and Install Libraries
Start IDE and download
- Adafruit ESP8266 by Adafruit
- DHT sensor library by Adafruit
- DS1307 library by Watterott
Install Board Manager

- Go to Settings
- Copy & Paste http://arduino.esp8266.com/stable/package_esp8266com_index.json in Additional boards manager urls
Copy & Paste Sketch
/* special thanks to codebender_cc & Utsource on instructables.com
Arduino UNO+WiFi R3 ATmega328P+Node MCU ESP8266 CH340G Compatible Board
DS1307 RTC
DHT22 (AM2302) Temperature & Humidity Sensor
Connections
DS1307
SCL - SCL
SDA - SDA
VCC - 3.5V
GND - GND
DHT22
+ - 5V
OUT - 2
- - GND
Libraries
Adafruit ESP8266 by Adafruit
DHT sensor library by Adafruit
DS1307 library by Watterott
Procedure
Make connections
Download libraries
Install Board Manager (in Settings - Additional Boards Manager urls) from http://arduino.esp8266.com/stable/package_esp8266com_index.json
Connect USB
Select Arduino Uno (Boards)
Select Port
Turn Dip Switch 3 & 4 'On'
Copy Paste sketch to IDE
Upload
*/
#include <Wire.h>
#include <DS1307.h>
#include <DHT.h>;
//Variables
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
//Constants
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
DS1307 rtc;
void setup()
{
//init Serial port
Serial.begin(9600);
//init RTC
rtc.begin();
//Serial.println("\nInit RTC..."); //optional
//init DHT
dht.begin();
//Serial.println("\nInit DHT..."); //optional
//set time and date
//rtc.set(0, 59, 17, 29, 5, 2025); //sec, min, hour, day, month, year
//only set the date time one time if using button cell on DS1307
//stop/pause RTC
//rtc.stop();
//start RTC initially
//rtc.start();
}
void loop()
{
uint8_t sec, min, hour, day, month;
uint16_t year;
//get time from RTC
rtc.get(&sec, &min, &hour, &day, &month, &year);
//Print time and date
Serial.print("\n");
Serial.print("\nDate: ");
Serial.print(day, DEC);
Serial.print(".");
Serial.print(month, DEC);
Serial.print(".");
Serial.print(year, DEC);
Serial.print(" Time: ");
Serial.print(hour, DEC);
Serial.print(":");
Serial.print(min, DEC);
Serial.print(":");
Serial.print(sec, DEC);
//get data from DHT22 and store it to variables hum and temp
hum = dht.readHumidity();
temp= dht.readTemperature();
//Print temp and humidity
Serial.print(" Humidity: ");
Serial.print(hum);
Serial.print("%");
Serial.print(" Temp: ");
Serial.print(temp);
Serial.print("° Celsius");
//wait 10 seconds
delay(10000);
}
Setup
- Connect Jumper Cables as in Step 3 - Connections
- Connect Board to Computer using USB Cable
- Turn Dip Switch 3 & 4 'On'
- Select board Arduino Uno
- Select Port
- Remove '//' from //rtc.set(0, 59, 17, 29, 5, 2025);
- Amend time & date
- Upload sketch
- Turn Dip Switch 4 'Off'
Output

Cheers!