EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / humidity

humidity

|

Microcontroller › 8051 › humidity

  • This topic has 1 reply, 2 voices, and was last updated 7 years, 11 months ago by GANEEV SINGH.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • October 5, 2011 at 8:56 am #1297
    bharat
    Participant

    wat r the basic used ..of using microcontroller for sensing humidity?

     

     

    can any simplified that following code or tel me wat these is all about…

     

     

    / Program to Interface Humidity sensor with 8051 Microcontroller
    #include<reg51.h>
    sfr lcd_data_pin=0x80;//p0 port
    sbit 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 port
    unsigned 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 LCD 
    delay(50);
    lcd_command(0x0F);        // for display on cursor blinking
    delay(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();
    }
    }
    March 31, 2018 at 7:04 am #14822
    GANEEV SINGH
    Participant

    Hi

    This code is written in order to read a sensor value (must be a humidity sensor here) and display "Rel.Humidity" on a LCD. 

    In this code average of 11 consecutive sensor readings is made and then it is converted to relative humidity value by means of some sort of a formula. This all is happening inside display() function.

    Since 8051's don't have inbuilt ADCs therefore an 8 bit ADC IC must be connected to it with PORT1.

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • What branch of electronics has easy spare parts sourcing in north africa ? March 6, 2026
  • USING EASYEDA BUT SOMETHING ISN'T RIGHT? March 6, 2026
  • ESP32 Sub Forum March 6, 2026
  • Hello & a Request: Recommendations for obsolete Panasonic filter Capacitors. March 6, 2026
  • Pnp transistor query March 6, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise