Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is Lab2-2 portion of the PICBasic Pro lab. Read the LM35 temperature sensor

ID: 2082832 • Letter: T

Question

This is Lab2-2 portion of the PICBasic Pro lab. Read the LM35 temperature sensor datasheet. Figure out how the output of the temperature sensor voltage corresponds to the actual temperature in Centigrade.

Using the program written in Lab 2_1, add the PICBasic Pro statements need to do the following:

If the temperature sensor output voltage V0 3.33V, blink the Red LED.

If the temperature sensor output voltage is 1.67V < V0 <3.33V, blink the Green LED.

If the temperature sensor output voltage is V0 <1.67V, blink the Blue LED.

Lab 2-1 program

DEFINE         LCD_DREG          PORTC                                  ; Set LCD Data Port C

DEFINE         LCD_DBIT            4                                              ; Set starting bit 4

DEFINE         LCD_RSREG        PORTC                                  ; Set Register Select Port C

DEFINE         LCD_RSBIT          0                                              ; Set Register Select bit 0

DEFINE         LCD_EREG          PORTC                                  ; Set Enable Port C

DEFINE         LCD_EBIT               1                                              ; Set Enable bit 1

DEFINE         LCD_LINES          2                                              ; Set to 2 line display

DEFINE         LCD_COMMANDUS    1640                               ; Set command delay time 1.64ms

DEFINE         LCD_DATAUS     44                                           ; Set data delay time 44us

DEFINE         ADC_BITS               10                                           ; Set number of bits in digital value

ADCON0.7=1                                                                                  ; Right justify digital value

ADCON0.6=0                                                                                  ; 5V is reference

TRISC=%00001100                                                                    ; Set up bit of Port C for outputs

ANSEL=%11001111                                                                   ; Set up bits for digital I/O

ANSELH=0                                                                                      ; Set up bits for digital I/O

adcval

VAR

WORD

adcint

VAR

WORD

adcdec

VAR

WORD

; Declare 16-bit variables

PAUSE 500

; Wait for LCD to warm up

loop:

ADCIN 2,adcval

; Read A/D channel 2

adcval=adcval*49/10

; Correct for resolution

adcint=adcval/1000

; Get integer value

adcdec=adcval//1000

; Get decimal value

LCDOUT $FE,1

; Clear LCD screen

LCDOUT DEC adcint, “.”, DEC adcdec, “ V”

; Display voltage

END

PAUSE 1000

GOTO loop

adcval

VAR

WORD

adcint

VAR

WORD

adcdec

VAR

WORD

OSC2 OUT DIG 10 U/DIG 54 00T 11U 11E +OABC_+ P IC 16F690 DCCT C-D OORFEDGDU 456789

Explanation / Answer

I'm working on a project which I was required to use several temperature sensors (LM35DZ) to measure the temperature inside each room and another temperature sensor to measure the atmospheric temperature. When there is huge difference of reading between atmospheric temperature with any of the temperature sensor inside, PIC16F877A will turn on a buzzer.

Since I am new, so I started by doing the simple thing, which is to show the temperature reading of single LM35DZ using a LCD. Here's my PICBasic code below:

DEFINE osc 20

Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1

define ADC_BITS 10
define ADC_CLOCK 3
define ADC_SAMPLEUS 50

lmtemp var word
temp var word

TRISA = %11111111
ADCON1 = 0

Start:

ADCIN 0, lmtemp
temp = (lmtemp*5)/10
Lcdout $fe, 1
Lcdout "Temp = ", dec temp,"C"

pause 100

goto start

LCD is working fine, by showing the word "Temp =", but the reading of temperature is wrong, which is "417C"!

The output of LM35DZ is direct input to AN0, when I measured the output voltage of LM35DZ, it is 4.06V. I decided to remove the output of LM35DZ from PIC and measure the output voltage again, which is the correct now, 0.28V (28 deg C). I was wondering what was the problem cos the code looks OK for me.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote