Real time clock with humidity and temperature monitor – CCS C

This topic shows how to build a real time clock with relative humidity and temperature sensing using PIC16F877A microcontroller, DS1307 RTC and DHT11 (RHT01) sensor where all data are displayed on 20×4 LCD display. The 20×4 LCD has 20 columns and 4 rows which is good enough for this project. The compiler used to program the microcontroller is CCS C.
To see how to interface PIC16F877A with DS1307 take a look at the following topic:
Real time clock using PIC16F877A microcontroller and DS1307 serial RTC

And to see how to interface PIC18F4550 with DHT22 (AM2302) take a look at this topic:
Interfacing DHT11 relative humidity and temperature sensor with PIC16F877A

The DS1307 RTC is an 8-pin integrated circuit which uses I2C communication protocol to communicate with master device which is in our case the PIC16F877A microcontroller. This small chip can count seconds, minutes, hours, day, date, month and year with leap-year up to year 2100.

The DHT11 (RHT01) sensor comes in a single row 4-pin package and operates from 3.3 to 5.5V power supply. It can measure temperature from 0-50 °C with an accuracy of ±2°C and relative humidity ranging from 20-90% with an accuracy of  ±5%. The sensor provides fully calibrated digital outputs for the two measurements. It has got its own proprietary 1-wire protocol, and therefore, the communication between the sensor and a microcontroller is not possible through a direct interface with any of its peripherals. The protocol must be implemented in the firmware of the MCU with precise timing required by the sensor.

Component list:

  • PIC16F877A microcontroller
  • DS1307 RTC
  • DHT11 (RHT01) Sensor
  • 2004 LCD
  • 3V Coin cell battery
  • 8MHz and 32.768KHz crystal oscillators
  • 2 x 22pF capacitors
  • 3 x 10K resistors
  • 4.7K resistor
  • 10K Potentiometer
  •  2 Buttons
  • +5V Power Supply
  • Protoboard
  • Jumper Wires

PIC16F877A + 2004 LCD + DS1307 RTC + DHT11 sensor circuit:
PIC16F877A DS1307 DHT11 sensor circuit

The two pushbuttons for adjusting time and date as shown in the video below.

CCS C code:
The project C code is just a combination of the C codes of the two previous projects.
The reading of relative humidity and temperature data is done every 1 second.

Project Video:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.