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

IMG_0776.JPG

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

  1. Arduino UNO+WiFi R3 ATmega328P+Node MCU ESP8266 CH340G Compatible Board
  2. DS1307 RTC
  3. DHT22 (AM2302) Temperature & Humidity Sensor
  4. M2M Jumper Wires - 04
  5. M2F Jumper Wires - 03
  6. USB Data Cable

Download and Install Libraries

Start IDE and download

  1. Adafruit ESP8266 by Adafruit
  2. DHT sensor library by Adafruit
  3. DS1307 library by Watterott

Install Board Manager

Screenshot 2025-05-29 at 19.54.37.png
  1. Go to Settings
  2. 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

  1. Connect Jumper Cables as in Step 3 - Connections
  2. Connect Board to Computer using USB Cable
  3. Turn Dip Switch 3 & 4 'On'
  4. Select board Arduino Uno
  5. Select Port
  6. Remove '//' from //rtc.set(0, 59, 17, 29, 5, 2025);
  7. Amend time & date
  8. Upload sketch
  9. Turn Dip Switch 4 'Off'

Output

Screenshot 2025-05-29 at 20.20.03.png

Cheers!