SN-HMD-MOD Humidity sensor

Digital Fiber, Photoelectric, Laser Range, Optical, Temperature, Rotary Encoder, Ultrasonic, Gas, Gyro, Accelerometer, FlexiBend, Flexiforce, Compass......

SN-HMD-MOD Humidity sensor

Postby veira » Sun Oct 27, 2013 12:32 am

Hi.
I want ask, why the value of sensor that I used to measure humidity level in air is drop when displayed in the LCD?
is this related to the formula that i have used?
below is the coding of the humidity sensor
CODE: SELECT_ALL_CODE
#include <pic.h>          //include PIC microcontroller library
__CONFIG ( 0x3F32 );      //PIC microcontroller configuration


#define   rs         RB3         //RS pin of LCD display
#define   rw         RB2         //R/W pin of the LCD display
#define   e         RB1         //E pin of the LCD display
#define   b_light      RB0         //Backlight of LCD display (high to on)
#define   button1      RB5         //button 1 (active low)
#define   button2      RB4         //button 2 (active low)
#define   lcd_data   PORTC      //LCD display data PORT (8-bit)


void delay(unsigned long data);
void send_config(unsigned char data);
void send_char(unsigned char data);
void lcd_goto(unsigned char data);
void lcd_clr(void);
void send_string(const char *s);
void send_num(unsigned short data);
unsigned char usart_rec(void);
void beep_short(void);
void beep_short2(void);
void beep_long(void);
unsigned char read_ad(unsigned char channel);

void main(void)
{
   //assign variable
   unsigned char temp;               //declare a temporary variable for reading ADC
   unsigned char mode;               //declare a variable to represent current mode
   unsigned int a;

   
   //set I/O input output
   TRISB = 0b11110000;               //configure PORT B I/O direction
   TRISA = 0b11011011;               //configure PORT A I/O direction
   TRISC = 0b00000000;               //configure PORT C I/O direction
   
   //configure lcd
   send_config(0b00000001);         //clear display at lcd
   send_config(0b00000010);         //Lcd Return to home
   send_config(0b00000110);         //entry mode-cursor increase 1
   send_config(0b00001100);         //diplay on, cursor off and cursor blink off
   send_config(0b00111000);         //function set
            
   //configure ADC
   ADCON0=0b10000001;               //enable ADC converter module
   ADCON1=0b01000100;               //configure ADC and ANx pin

   //initial condition
   b_light=1;                     //on backlight
   lcd_clr();                     //clear lcd
   lcd_goto(0);                  //set the lcd cursor to location 0   

                  
         
   while(1)                     //infinity loop
   {
   
      {                  
         lcd_goto(0);                  //set lcd cursor to location 0
         send_string("Humidity Sensor ");   //display "Humidity Sensor"
         a=read_ad(1);               //read AN1 (Humidity Sensor)
         temp=a*100/255;
         lcd_goto(20);                  //set lcd cursor to location 20
         send_num(temp);                  //display the analog value of the humidity sensor
      
   }   
}
}

void delay(unsigned long data)            //delay function, the delay time
{                                 //depend on the given value
   for( ;data>0;data-=1);
}

void send_config(unsigned char data)      //send lcd configuration
{
   rw=0;                           //set lcd to write mode
   rs=0;                           //set lcd to configuration mode
   lcd_data=data;                     //lcd data port = data
   e=1;                           //pulse e to confirm the data
   delay(50);
   e=0;
   delay(50);
}

void send_char(unsigned char data)      //send lcd character
{
    rw=0;                        //set lcd to write mode
   rs=1;                        //set lcd to display mode
   lcd_data=data;                  //lcd data port = data
   e=1;                        //pulse e to confirm the data
   delay(10);
   e=0;
   delay(10);
}

void lcd_goto(unsigned char data)      //set the location of the lcd cursor
{                              //if the given value is (0-15) the
    if(data<16)                     //cursor will be at the upper line
   {                           //if the given value is (20-35) the
       send_config(0x80+data);         //cursor will be at the lower line
   }                           //location of the lcd cursor(2X16):
   else                        // -----------------------------------------------------
   {                           // | |00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15| |
       data=data-20;               // | |20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35| |
      send_config(0xc0+data);         // -----------------------------------------------------   
   }
}

void lcd_clr(void)                  //clear the lcd
{
    send_config(0x01);
   delay(600);   
}

void send_string(const char *s)         //send a string to display in the lcd
{         
   unsigned char i=0;
     while (s && *s)send_char (*s++);

}


void send_num(unsigned short data)         //function to display a value on lcd display
{
   unsigned char tenthou,thou,hund,tenth;
   

   hund=data/100;                     //get hundred value
   data=data%100;      
   tenth=data/10;                     //get tenth value
   data=data%10;                     //get unit value
   
   send_char(0x30+hund);               //display the hundred value
   send_char(0x30+tenth);               //display the tenth value
   send_char(0x30+data);               //display the unit value
}

unsigned char read_ad(unsigned char channel)   //fucntion read analog input according to the given channel
{
   unsigned char result;                  //declare a variable call result
   switch(channel)               
   {
      case 0:                           //if channel = 0
         CHS2=0;                        //CHS2=0
         CHS1=0;                        //CHS1=0
         CHS0=0;                        //CHS0=0
         break;
      case 1:                           //if channel = 1
         CHS2=0;                        //CHS=0
         CHS1=0;                        //CHS=0
         CHS0=1;                        //CHS=1
         break;
   }
   ADGO=1;                              //start ADC convertion
   while(ADGO);                        //wait for ADC convertion to complete
   result=ADRESH;                        //read the result
   return result;                        //return the result
}
veira
Greenhorn
 
Posts: 2
Joined: Fri Oct 25, 2013 3:21 pm

Re: SN-HMD-MOD Humidity sensor

Postby robosang » Mon Oct 28, 2013 11:26 pm

There is no rules stated that reading should rise if the humidity is higher :)
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: SN-HMD-MOD Humidity sensor

Postby veira » Thu Nov 07, 2013 7:02 pm

Okay thanks. :)
But for the sensor that i used, what actually means by pin DO and AO?
I have read some pages, it state that the pin DO is only show high/low and AO is AD converter. It's mean that I can get the value when only using AO pin?
In my circuit design, I ignored the pin DO and only used AO pin connect direct to the microcontroller. The measurement that I get is around 88 and when I give some heat to the sensor, the value will drop.
veira
Greenhorn
 
Posts: 2
Joined: Fri Oct 25, 2013 3:21 pm


Return to Sensor

Who is online

Users browsing this forum: No registered users and 14 guests

cron