Humidity sensor works on the principle of relative humidity and gives the output in the form of voltage. This analog voltage provides the information about the percentage relative humidity present in the environment.
The relative humidity is defined as:
The analog output of sensor is connected to ADC to get its corresponding digital value. For calibration of digital values, the reference voltage of ADC is set to 1.5 volts. The digital values are received at port P0 of microcontroller. These digital values are used to calculate percentage relative humidity of environment. The calculated data is sent to LCD to display the percentage relative humidity. The connections of ADC0804 and LCD with the 8051 microcontroller (AT89C51) are shown in circuit diagram.
Algorithm
{C. Define the input and output port of microcontroller.
{2. Initialize LCD.
{C}. Monitor the value of ADC 0804.
{C}{ Calculate the relative humidity
{C5. Convert the calculated value in their corresponding ASCII codes.
6. Display the converted value on the LCD.
{C}{7. Repeat steps 4 to 7 in an infinite loop.
Project Source Code
###
// Program to Interface Humidity sensor with 8051 Microcontroller#include<reg51.h>sfr lcd_data_pin=0x80;//p0 portsbit rs=P3^0;sbit rw=P3^1;sbit en=P3^2;sbit wr= P3^3;sbit rd= P3^4;sbit intr= P3^5;sfr input_port=0x90; //p1 portunsigned int number=0;unsigned char humidity,lcd,key=0;void delay(unsigned char count){unsigned char i;unsigned int j;for(i=0;i<count;i++)for(j=0;j<1275;j++);}void lcd_command(unsigned char comm){lcd_data_pin=comm;en=1;rs=0;rw=0;delay(1);en=0;}void lcd_data(unsigned char disp){lcd_data_pin=disp;en=1;rs=1;rw=0;delay(1);en=0;}lcd_dataa(unsigned char *disp){unsigned char x;for(x=0;disp[x]!=0;x++){lcd_data(disp[x]);}}void lcd_ini(){lcd_command(0x38); // for using 8-bit 2 row LCDdelay(50);lcd_command(0x0F); // for display on cursor blinkingdelay(50);lcd_command(0x0C);delay(50);lcd_command(0x80);delay(50);}void lcd_display(unsigned int val){unsigned char flg=0;lcd_command(0xC7);if(val==0)lcd_data('0');while(val>0){lcd=val%10;val=val/10;lcd_command(0xC7-flg);lcd_data(lcd+'0');flg++;}}void display(){key++;number=number+input_port;if(key==11){number=number/key;number=number*10;number=number/25;humidity=number-3;lcd_display(humidity);key=0;number=0;}}void adc(){rd=1;wr=0;delay(2);wr=1;while(intr==1);rd=0;display();delay(2);intr=1;}void main(){lcd_ini();lcd_dataa("%Rel.Humidity:");while(1){adc();}}###
Circuit Diagrams
Project Components
Project Video
Filed Under: 8051 Microcontroller
Filed Under: 8051 Microcontroller
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.