LCD reading data when sensor is not connected

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

LCD reading data when sensor is not connected

Postby VickyPipe » Tue Apr 16, 2013 3:39 pm

Hello, I'm kinda new here. Currently having problem with my temperature and humidity sensor reading using the SK40C. Coding is as attached below :

CODE: SELECT_ALL_CODE
//port definition
//input
#define SW1 PORTB.F0
#define SW2 PORTB.F1
//output
//LED
#define LED1 PORTB.F6
#define LED2 PORTB.F7

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D0 at RD0_bit;
sbit LCD_D1 at RD1_bit;
sbit LCD_D2 at RD2_bit;
sbit LCD_D3 at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D0_Direction at TRISD0_bit;
sbit LCD_D1_Direction at TRISD1_bit;
sbit LCD_D2_Direction at TRISD2_bit;
sbit LCD_D3_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections

char value[7];
char value2[7];
void introduction(void);
void initialization(void);
void stat_mode(void);
void main()
{
initialization();
introduction();
while(1)
{
unsigned char i;
unsigned portvalue;
unsigned portvalue2;
portvalue=Adc_Read(0);
portvalue2=Adc_Read(1);
portvalue= portvalue/2;
portvalue2=(portvalue2/2);
WordToStr(portvalue, value);
WordToStr(portvalue2,value2);
Lcd_Out(1,1,"TEMP. CEL:");
Lcd_Out(1,12,value);
Lcd_Out(1,16,"C");
Lcd_Out(2,1,"HUMI. RH :");
Lcd_Out(2,12,value2);
Lcd_Out(2,16,"%");
delay_ms(1000);
for(i=0;i<13;i++)
{
Uart1_Write(value[i]);
//Usart_Write('\n');
//Usart_Write(value2[i]);
}
Uart1_Write('\n');
for(i=0;i<13;i++)
{
//Usart_Write(value[i]);
//Usart_Write('\n');
Uart1_Write(value2[i]);
}
} }
void initialization(void)
{
PORTA = 0; // Clear Port
PORTB = 0;
TRISA=0b11111111;
TRISB=0b00000000;
TRISD=0;
ADCON1=0;
ADC_Init();
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
delay_ms(150);
Uart1_Init(9600);
}
void introduction()
{
unsigned char i;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"WELCOME");
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1," WIRELESS ");
Lcd_Out(2,1," DATALOGGER ");
delay_ms(2000);
for(i=0; i<16; i++) { // Move text to the left 16 times
Lcd_Cmd(_LCD_SHIFT_LEFT);
delay_ms(80);
}
Lcd_Cmd(_LCD_CLEAR);
}

At first in the beginning , the LCD will be showing black boxes and once reset button is pressed on the SK40C , the LCD will function as according to the coding but at the temperature and humidity reading showing some readings of random number as the sensor is not even connected to the RA0 and RA1. Im using LM35 , Cytron Humidity Sensor , SK40C and PIC16F877A. Need help in this.
VickyPipe
Greenhorn
 
Posts: 3
Joined: Tue Apr 16, 2013 3:27 pm

Re: LCD reading data when sensor is not connected

Postby robosang » Wed Apr 17, 2013 8:19 pm

If the analog pin is not connected to sensor or pull-up or pull-low, it will read noise.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: LCD reading data when sensor is not connected

Postby VickyPipe » Thu Apr 18, 2013 10:21 am

Sorry what you mean by pull up or pull down?
VickyPipe
Greenhorn
 
Posts: 3
Joined: Tue Apr 16, 2013 3:27 pm

Re: LCD reading data when sensor is not connected

Postby waiweng83 » Thu May 09, 2013 11:24 am

When the sensor is not connected, the analog pin is floating and the voltage is undetermined. It might jump up or down due to the electrical noise from the environment.

BTW, does it work correctly when your sensor is connected?
With the power of dream, nothing is impossible...
User avatar
waiweng83
Moderator
 
Posts: 208
Joined: Wed Apr 15, 2009 2:17 pm

Re: LCD reading data when sensor is not connected

Postby VickyPipe » Mon May 13, 2013 6:59 pm

finally i understood what u are trying so say..I have solved the problem..however when sending it to uart
the temperature value is reading at 25.99999 for example..
I've referred the formula from this page http://extremeelectronics.co.in/microch ... ontroller/
VickyPipe
Greenhorn
 
Posts: 3
Joined: Tue Apr 16, 2013 3:27 pm


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 19 guests