car AC thermostat

kevrus

New Member
Just a simple little project, born about due to no real temp control on my car AC. Using an 18x, DS18B20 and a 2x16 display. internal temp reading is taken 5 times and the average is used for display and control. This I may alter if it proves unsuitable. Picture of unit fitted into the car is not brilliant.

Usual caveats apply with my coding (I know it could be better..)


Code:
					#picaxe18x
'-------------------------------------------------------------------------------'

				'CAR A/C TEMP CONTROL USING 18X AND DS18B20 
				    'DISPLAYED ON 2X16 ALPHANUMERIC LCD

'-------------------------------------------------------------------------------'
			
			


symbol lcd=2
symbol temp_sens=0
symbol backlight=3
symbol car_fan=pin1			
symbol setpoint_dwn=pin2
symbol setpoint_up=pin7
symbol aircon=7
symbol setpoint=b13
symbol baud=t2400
symbol read_temp=w0
symbol counter=b6
symbol timer =b7
symbol control_temp=b0
symbol ave_temp=w2
symbol car_temp=w1
 

initialise:
pause 250				'lets start with a short delay shall we?
high lcd				'sets output high for serial display
pause 5				'just to make sure the output is high
serout lcd,baud,(254,1)		'clears the display
pause 500				'and waits for the display to settle
high backlight			'switch on lcd backlight
setpoint=20				'initial setpoint value


begin:
setint off
gosub display_clear
gosub release_setpoint_dwn_button'wait for button to be released
low aircon				'make sure aircon is off
serout lcd,baud,(254,128,"Kev's AC CONTROL")'here's the header
serout lcd,baud,(254,192,"   SYSTEM OFF   ")'and here's the status

do
loop until setpoint_up=1 or setpoint_dwn=1'press any button to start

gosub release_setpoint_up_button'wait for button to be released
gosub release_setpoint_dwn_button'wait for button to be released

if car_fan=0 then			'if car fan isn't running then
serout lcd,baud,(254,192,"  TURN ON FAN   ")'alert the driver
end if
do
if setpoint_dwn=1 then goto begin'turns system off after 2sec press
loop until car_fan=1		'and wait until it is!
serout lcd,baud,(254,192,"   SYSTEM ON    ")'and now we start checking



'-------------------------------------------------------------------------------'

				'MAIN PROGRAM SUB-ROUTINE SEQUENCE

'-------------------------------------------------------------------------------'


run:
setint %10000000,%10000000	'sets interrupt for temp adjustment
gosub temp_reading		'measure the cabin temp
gosub neg_check			'lets see if temp is negative
gosub control			'lets see if we need cooling shall we?
gosub display_values		'displays readings on lcd
goto run				'here we go again


'-------------------------------------------------------------------------------'

				'AVERAGE TEMP SAMPLING

'-------------------------------------------------------------------------------'


temp_reading:
if setpoint_dwn=1 or car_fan=0 then goto begin'turns system off after 2sec press or car fan stopping


counter=0				'resets timer to zero and
ave_temp=0				'average temp to zero for next batch of readings

do
readtemp12 0,read_temp		'reads the in car temp
ave_temp=ave_temp+read_temp	'adds latest temp reading to average temp
pause 1000				'1 second delay before next reading
inc counter				'adds 1 to the timer
loop until counter=5		'this allows 5 readings to be taken
ave_temp=ave_temp/5		'this divides total value by 5 for average
return



'-------------------------------------------------------------------------------'

				'TEMP CALCULATION ROUTINE

'-------------------------------------------------------------------------------'


neg_check:
car_temp=ave_temp			'load 'cartemp' into w1
bit15 = car_temp/32768		'isolate bit 15
if bit15 = 1 then			'check to see if bit 15 is 1
b8 = "-"				'character if temp is 'negative
car_temp=65535-car_temp+1	'2s compliment for negative temp
else 
b8 = "."
end if


temp_calc:
car_temp=car_temp*10
w2=car_temp/16				'divide by 16
b0=w2/10				'divides by 10 and leave the 'whole' number 
b1=w2//10				'divides by 10 and leave the remainder 
return


'-------------------------------------------------------------------------------'

				'TEMP CONTROL ROUTINES

'-------------------------------------------------------------------------------'


control:
if control_temp>setpoint then 'lets see if we need cooling
high aircon				'if so, turn on the aircon
b10="o"
b11="n"
b12=" "
else if control_temp<setpoint then 'and if not
low aircon				'turn off the aircon
b10="o"
b11="f"
b12="f"
end if 
return


'-------------------------------------------------------------------------------'

				'DISPLAY AND INTERRUPT ROUTINES

'-------------------------------------------------------------------------------'

display_values:
if b0<10 then
serout lcd,baud,(254,192,"Temp..",b8,#b0,".",#b1,223,"C ",b10,b11,b12)
else
serout lcd,baud,(254,192,"Temp.",b8,#b0,".",#b1,223,"C ",b10,b11,b12)
end if
return


display_clear:
serout lcd,baud,(254,192,"                   ")
return

display_setpoint:
serout lcd,baud,(254,192,"S/P ADJUST..",#setpoint,223,"C")
return




interrupt:
gosub release_setpoint_up_button'wait for button to be released
gosub display_clear
serout lcd,baud,(254,192,"S/P ADJUST..",#setpoint,223,"C")
gosub display_setpoint


for timer=0 to 250		'sets value for 'return'timer
pause 2
if setpoint_up=1 then inc_temp'jumps to 'inc_temp' or
if setpoint_dwn=1 then dec_temp'dec_temp' dependent on button push
next timer				'inc timer by 1
setint %10000000,%10000000	'resets the interrupt
timer=0				'makes sure timer is set to zero
return


inc_temp:
if setpoint>26 then let setpoint=15'resets setpoint to 15 if max 26 reached
gosub release_setpoint_up_button'wait for button to be released 
end if
for timer=0 to 250		'sets value for 'return'timer
pause 3
if setpoint_up=1 then 
inc setpoint			'adds one to the setpoint value
gosub display_setpoint
gosub release_setpoint_up_button'wait for button to be released
goto inc_temp			'loop if another increase is required
end if				'adds one to the setpoint 
if setpoint_dwn=1 then dec_temp'jumps dependent on button push
next timer				'inc timer by 1
return


dec_temp:
if setpoint<15 then let setpoint=26'resets setpoint to 26 if min 14 reached
gosub release_setpoint_dwn_button'wait for button to be released 
end if
for timer=0 to 250		'sets value for 'return'timer
pause 3
if setpoint_dwn=1 then '
dec setpoint			'takes 1 away from the setpoint value
gosub display_setpoint
gosub release_setpoint_dwn_button'wait for button to be released
goto dec_temp			'loop if another decrease is required
end if				'takes 1 away from the setpoint 
if setpoint_up=1 then inc_temp'jumps dependent on button push
next timer				'inc timer by 1
return


release_setpoint_up_button: 
do
loop until setpoint_up=0	'wait for button to be released 
pause 10				'pause just to make sure
return


release_setpoint_dwn_button: 
do
loop until setpoint_dwn=0	'wait for button to be released
pause 10				'pause just to make sure
return
 

Attachments

BeanieBots

Moderator
Nice display!

As this is one of those 'controversial' CAR applications, it would be nice to see the circuit you used to tame the 12v and protect the PICAXE from the car electrics.
 

kevrus

New Member
As I used a PCB design from a previous project, I didn't take any real special precautions as such, my thinking was that if there is a problem, then I could just add a 'supply conditioning' board prior to connecting the picaxe board.

There is a MOS varistor on board across the supply terminals (wrong symbol on the diagram but the closest I had).

I have the usual diode across the relay coil, and a 4.7uf tantalum close to the 18x supply pins.

It's been working ok for two days now without a glitch so hopefully all is well.

I will add that this isn't necessarily the correct way of doing things, just the approach that I took in this instance.
 

Attachments

BeanieBots

Moderator
At least you've got a fuse, more than most remember to put in.
The varistor might like to be the other side of it though.
 

Peter M

Senior Member
Nice Finish; board and display.
Good choice of LCD, easy to read.

And should keep the crowds happy..... not mission critical in a car:D
 

fernando_g

Senior Member
The display is really nice looking!!
Where did you get the LCD and the LCD Bezel? They look very professional!

Averaging several readings is a good practice to filter noise. And since the temperature changes quite slowly, a delay of a few milliseconds has no ill effect.
 

kevrus

New Member
Peter M, fernando_g, thanks for the comments...the the bezel came from MMS Electronics...not that cheap but makes finishing off a bit easier,
and the display is white characters on a dark background, and is an e-bay listing...

item no. 190323666195

There are a large number of colours in the 16x2. I did get also red one and a blue one, both look quite nice but would be more difficult to read in bright light. Its tempting to stock up with the other colours for the future
 

mudgee73

New Member
Kevrus,

You've inspired me! I'm only new to PICAXE but I thought I'd have a go at this project to learn more about them and to keep from freezing in my toyota Hilux.
I have ordered one of the LCD displays from ebay and after reading the specifications I beleive it to be a parallel input. Is this correct or can you set it to be a serial input?

Cheers,

Mick
 

hippy

Technical Support
Staff member
I have ordered one of the LCD displays from ebay and after reading the specifications I beleive it to be a parallel input. Is this correct or can you set it to be a serial input?
No idea without knowing exactly what you bought but most LCD said to be for parallel input are only for parallel input. Details should be in its datasheet. You need to add a FRM010 or use another PICAXE to turn it into a serially controlled module.
 

mudgee73

New Member
What I was suggesting was that I purchased the same LCD as used in this project, but as I am new to PIXAXE's my question to Kevrus was how did he get it from serial to parallel. My question was answered by hippy. Cheers.
 
Top