Digital humidity sensor using PIC microcontroller

Digital humidity sensor with LCD display is used to measure relative percentage  of water vapors in air. HS1101 capacitive humidity sensor is interfaced with PIC16F877A microcontroller to measure humidity and LCD is used to display percentage humidity in air.For humans there is certain limit for water vapors presence in air. Above that limit relative humidity may cause problems to human health.

Applications of digital humidity sensors

Humidity sensors have many application in industry and domestic areas. Humidity means presence of water vapors in air. Percentage of water vapors in air should be with in safety limit. Otherwise It have harmful physical and chemical effects on human beings and also in industrial products. Humidity sensors have major applications in agriculture ,chemical, oil, gas and medical industry. For example in agriculture industry humidity sensor is used to measure moisture in fields. There are also many other application of humidity sensor.You can search them om Google.

digital Humidity sensor selection

When you search on Google, you will come across many humidity sensors. All these humidity sensors have their advantage and disadvantage. But I used capacitive HS1101 humidity sensor in this project. What is meant by capacitive humidity sensor? All capactive senors give output in capacitive form.They change their capacitance with respect to change in sensing parameter like in HS1101 sensor sensing parameter is amount of water vapors in air. The reason why I used this humidity sensor?  Because

  • It can be used for highly sensitive applications.
  • less cost
  • easy to interface with microcontroller with small extra circuitry
  • No calibration is required
  • It can be easily used for home appliances and industrial control system.

How to use HS1101 digital humidity sensor

HS1101 is a  capacitive humidity sensor, so it can be used with 555 timer circuit to generate square wave of different frequency. I assume you know about 555 timer IC and its use.

humidity sensor circuit with external circuitry

humidity sensor circuit with external circuitry

As shown in above figure, variable capacitor is used in place of humidity sensor for simulation purpose. Becuase HS1101 simulation model is not available in Proteus. Above circuit is used as a signal conditioning circuit to convert one form of parameter to its other proportional parameter so that it can be easily interfaced with any digital system or microcontroller. It is not possible for any microcontroller to read change in capacitance directly. That why above circuit is used to convert changing capacitance of HS1101 into sqaure wave whose frequency changed according to change in capacitance .

I have already post a tutorial on how to measure of square wave using PIC 16F877A microcontroller. I recommend you to go through article before going further in this project.

Square wave frequency measurement using PIC16F877A microcontroller 

Now you know we can easily measure square wave frequency with microcontroller. But now the question is how we will convert frequency back into relative humidity?  There is a proper relationship between humidity and frequency. Go through data sheet of HS1101 humidity sensor to know  more about HS1101 sensor.

components list for digital humidity sensor

Category,Reference,Value,Order Code
Integrated Circuits,"U1",NE555,
Integrated Circuits,"U2",PIC16F877A,
Miscellaneous,"SENSOR",humidity sensor HS1101,
crystal 20mhz

Circuit diagram of digital humidity sensor

Complete circuit diagram of Digital humidity sensor with LCD display:

circuit diagram of digital humidity sensor

circuit diagram of digital humidity sensor

Simulation results using pulse generator in proteus:



As shown in above diagram humidity is shown in percentage. 27% humidity mean air contains 27% water vapors. so you can take control actions according to your requirement. By little bit modification in this project you can also control anything according to change in relative humidity. let me know what is your requirement I will be happy to provide you solution.

Video lecture digital humidity meter

Code of  digital humidity sensor measurement using pic

Code is written in mikro c for pic: [sociallocker]

// LCD module connections
sbit LCD_D7 at RB2_bit;
sbit LCD_D6 at RB3_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D4 at RB5_bit;
sbit LCD_EN at RB6_bit;
sbit LCD_RS at RB7_bit;

sbit LCD_D7_Direction at TRISB2_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_RS_Direction at TRISB7_bit;
// End LCD module connections
//******************************frequency meter variables*******
int value,freq,humidity;
char humid[7];
void data_converstion(void)
IntToStr(humidity, humid);
void display1(void)

lcd_out(1,1,”Humidity = “);
lcd_out(1,13, Ltrim(humid));
Lcd_Chr_Cp(‘ ‘);


void interrupt(void) // high portD
T1CON.TMR1ON=1; // turn on the timer1
INTCON.INTF = 0; // clear the interrupt flag
else if(T1CON.TMR1ON==1)
T1CON.TMR1ON=0; // turn off the timer1
INTCON.INTE = 0; //Enable RB0/INT external Interrupt
humidity = 565 – freq/13;
// freq = freq /13.18;
//freq = 100 – freq;
INTCON.INTE = 1; //Enable RB0/INT external Interrupt
INTCON.INTF = 0; // clear the interrupt flag

void main()
long count;

TMR1L=0; // intialization of timer one prescalar and internal clock
INTCON.GIE = 1; //Enable Global Interrupt
INTCON.INTE = 1; //Enable RB0/INT external Interrupt
OPTION_REG.INTEDG = 0; //Interrupt on rising edge
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
lcd_out(1,4,”GREEN HOUSE”);
Lcd_Cmd(_LCD_CLEAR); // Clear display



If you have any problem after reading this article, comment on this post with your problem and if you need complete circuit diagram, simulation and hexa file of this project, comment on this post with your email address.

If you feel this article helps you in getting some knowledge kindly don’t forget to share it with your friends on social media.

enjoy coding 🙂


  1. david shalom September 13, 2014
  2. BILAL Malik September 18, 2014
  3. ally November 19, 2014
    • MOHAMMED March 11, 2016
  4. reeza November 20, 2014
    • Ally November 22, 2014
    • Ally November 22, 2014
  5. Abdullah Zohaib Kiani November 29, 2014
  6. Raj Kumar December 19, 2014
    • ali January 5, 2015
  7. ali January 10, 2015
  8. Nur Ikhlas February 14, 2015
  9. smwal February 15, 2015
  10. smwal February 17, 2015
  11. akif March 4, 2015
  12. moheed March 5, 2015
  13. ion April 21, 2015
  14. foxc April 21, 2015
    • BILAL Malik April 21, 2015
  15. lam May 13, 2015
  16. JOBIN GEORGE May 21, 2015
  17. JOBIN GEORGE May 21, 2015
  18. omer June 16, 2015
  19. Sarmad July 28, 2015
  20. Kalaiyarasan August 20, 2015
  21. Romesh January 16, 2016
    • BILAL Malik January 17, 2016
      • Romesh January 17, 2016
        • BILAL Malik January 17, 2016
          • Romesh January 22, 2016
  22. Nav February 8, 2016
  23. emmanuel February 11, 2016
    • BILAL Malik February 11, 2016
  24. vishakha April 1, 2016
  25. adil can balçık June 8, 2016
  26. Carlo Abellera August 12, 2016
  27. Shanu Kumar September 20, 2016
  28. DatTranTat November 13, 2016
  29. ruth November 24, 2016
  30. Mishigu December 5, 2016
    • Rocky May 3, 2017
  31. Rocky May 3, 2017
  32. Umaru Yusuf May 13, 2017
  33. Romesh July 15, 2017
  34. ermias October 4, 2017
  35. Shivam Mehta January 24, 2018
  36. Aishwarya March 11, 2018
  37. adamubaid April 10, 2018

Add Comment

Learn ESP32 programming with Arduino IDE with 73% DISCOUNT