Step 3Program the PICAXE
Second you have to assemble your PICAXE programming board or whatever you choose to use to program the pic. Refer to http://www.rev-ed.co.uk/ for details on starting out with the PIC.
The code is very simple. It samples the sensor output, and if it's below, within or above certain thresholds, it turns the LED green, yellow or red. Each sensor might have slightly different thresholds. Here are the values I used, based on collecting data around my city:
main:
'w5 = 270 'DIESEL GREEN'
'w6 = 295 'DIESEL RED'
'w5 = 448 'VOC GREEN'
'w6 = 470 'VOC RED'
w5 = 360 'EXHAUST GREEN'
w6 = 380 'EXHAUST RED'
goto runsensor
runsensor:
readadc10 4, w3 'SENSOR VALUE'
if w3 < w5 then 'GREEN'
high 1
low 2
endif
if w3 >= w5 and w3 < w6 then 'YELLOW'
high 1
high 2
endif
if w3 >= w6 then 'RED'
low 1
high 2
endif
pause 500
goto runsensor
An easy way to guess what the green, yellow and red values might be after you already wired up the circuit is by using a voltmeter. You can see what voltage the sensor is giving off at different locations and translate that into analog values:
1023 * sensor voltage / your battery voltage
| « Previous Step | Download PDFView All Steps | Next Step » |
3
comments
|
Add Comment
|
![]() |
Add Comment
|

















































