PDA

View Full Version : 16f876 microchip temperature sensor 1 wire with 16x2 lcd



macx75
03-14-2009, 10:47 PM
just wanted to make a temperature sensor for summer to show the diffrent temperatures in a day.
so to compare have given 2 switches each switch stores its reading and displays on the lcd.
so in the morning at 8 when switched on if its 34deg and it beeps means it is constant 34 then press one switch and it displays on screen , at noon if it is 40 and constant it would beep store it and by evening u can compare .
you can modify it with ur use.

acutally this is a test phase but the uses will be as follows
when it senses a range of temp like from 30 and above it would start the exhaust fan and stop the fan till the temp reading is cooler,

i actually built this testing as a probe to find the temperature in the ground from 1 feet to 5 feet , inserting the probe to the ground and sensing the temperature when it beeps that is the temp that is maintained. then press switch 1 to store that value and push the probe till 2 feet and repeat till 4-5 ,
at after 3 feet the soil temp remains the same. (this is for a room cooling unit undergound pipes about 60 feet to be layed at that cool level of ground and cold air is circulated in the room , by a 4inch exhaust .)

my next robot will use this sensor to monitor room temp and decide to switch on/off exhaust fans or open / close windows.

'************************************************* ***************
'* Name : temperature.BAS *
'* Author : [set under view...options] *
'* Notice : Copyright (c) 2006 [set under view...options] *
'* : All Rights Reserved *
'* Date : 21/03/2006 *
'* Version : 1.0 *
'* Notes :using 16x2 lcd to display temperature.
it has 2 switches to store and display the temperature on screen. *
'* : *
'************************************************* ***************
' One-wire temperature for 16f876 by www.robotz.in by macx for experimental room temperature in summer with comparsion

' use sharp ds1820 and pin 1 is ground pin 2 is portc.0 and pin 3 is + 4.7 k between pin 3 and pin2



temperature VAR WORD ' Temperature storage
count_remain VAR BYTE ' Count remaining
count_per_c VAR BYTE ' Count per degree C

DQ VAR PORTC.0 ' One-wire data pin


' Define LCD registers and bits
Define LCD_DREG PORTb
Define LCD_DBIT 4
Define LCD_RSREG PORTb
Define LCD_RSBIT 3
Define LCD_EREG PORTb
Define LCD_EBIT 0
define lcd_line 2'define 2 line lcd
define lcd_commandus 2000 ' defince delay between sending lcd commands
define lcd_dataus 50
aa var byte
bb var word
cc var word
dd var byte
gg var byte
x var byte
sw1 var portc.5
sw2 var portc.6
a1 var word
a2 var byte
a3 var byte
a4 var byte
a5 var byte




input sw1
input sw2

ADCON1 = 7 ' Set PORTA and PORTE to digital
' Low PORTE.2 ' LCD R/W line low (W)

buzzer var portc.7

a1 = 0
a2 = 0
a3 = 0
a4 = 0

mainloop: OWOut DQ, 1, [$CC, $44] ' Start temperature conversion

waitloop: OWIn DQ, 4, [count_remain] ' Check for still busy converting
IF count_remain = 0 Then waitloop

OWOut DQ, 1, [$CC, $BE] ' Read the temperature
OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]


temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
aa = (temperature / 100)
bb = (temperature)


if bb = cc then buzz

lcdout $fe,1, dec aa,".", dec1 bb, " C"
lcdout $fe, $c0, dec a1,".",dec1 a2, " C" , " " ,dec a3,".",dec1 a4, " C"
'lcdout $fe, $c0, dec cc , " ", dec bb , " ", dec gg
cc = bb
if sw1 = 0 then calc
if sw2 = 0 then calc2
Pause 100 ' Display about once a second

GoTo mainloop ' Do it forever

buzz:
lcdout $fe,1, dec aa,".", dec1 bb, " C"
lcdout $fe, $c0, dec a1,".",dec1 a2, " C" , " " ,dec a3,".",dec1 a4, " C"

high buzzer
pause 50
low buzzer
pause 50
high buzzer
pause 50
low buzzer
if sw1 = 0 then calc
if sw2 = 0 then calc2
pause 100
if sw1 = 0 then calc
if sw2 = 0 then calc2
goto mainloop

calc:
sound buzzer, [100,30]
low buzzer
pause 10
a1 = aa
a2 = bb
goto mainloop

calc2:
sound buzzer, [125,30]
low buzzer
pause 10
a3 = aa
a4 = bb
goto mainloop

' Calculate temperature in degrees C to 2 decimal places (not valid for negative temperature)

'LCDOut $fe, 1, DEC (temperature / 100), ".", DEC2 temperature, " C"

'if aa = 30 then buzz
'high buzzer
'pause 100
'low buzzer

' Calculate temperature in degrees F to 2 decimal places (not valid for negative temperature)
'temperature = (temperature */ 461) + 3200
'LCDOut $fe, $c0, DEC (temperature / 100), ".", DEC2 temperature, " F"