EOS

Instruments

Humidity Sensor

Programming Exercise in PicAxe

The output of the Philip Harris Humidity Sensor is directly proportional to the relative humidity of the surrounding air.  The capacitive sensor is at the end of the external probe which is connected to the Blue Box.  The output voltage of the Blue Box ranges from 0 to +1.0 V, corresponding to a relative humidity of 0 to 100%. 

Note on relative humidity

 

The humidity of a parcel of air refers to the mass of water vapor contained within the mass of a certain volume of air at a given temperature.  The measure of humidity would be in, say, grams of water per kilogram of air.  This so-called absolute humidity would have units g/kg.

 

Relative humidity is the absolute humidity of the air at the given temperature divided by the absolute humidity of the air if it were completely saturated with water vapor.  This ratio is expressed as a percentage.  A parcel of air with a relative humidity of one hundred is completely saturated with water vapor.

The Assignment

 

Write a program to read the analog input of the PicAxe microprocessor 08M2 at the pin C.1, convert that to relative humidity, continuously update and display the result on the OLED.  The OLED display must include the word “Humidity” centered on the first line and the second line must display – centered – the current value of relative humidity and the percent sign. 

Basic commands which might be useful for the solution

First, define some variables such as these:

symbol variablename = pinC.2                         ‘ no space between “pin” and “C.2”

symbol  Vinput = w0

symbol  Pressure = w1                          ‘w0 and w1 are word variables, i.e., 16 bit variables.

 

Commands related to reading the analog input:

             fvrsetup FVR2048

             adcconfig %011

             readadc10 C.2

 

Commands related to displaying the output:

             bintoascii

             serout C.1, N2400_4,(254, 128,”                “) 

             serout C.1, N2400_4,(254, 192, “   “,b9,b10,b11,”          “)

                          Note that whatever is within the parenthesis is displayed on the OLED.

                          Make sure that there are exactly 16 characters or spaces within parenthesis.

                          128 is the leftmost position on line 1 of the OLED

                          192 is the leftmost position of line 2 of the OLED

                          bintoascii converts a binary number to a display character.

 

Commands related to logic and math:

             if   variablename = 0     then . . .

                          endif

             goto (linename)

             VariableA = VariableB * 2 + 800 / 7   ‘math protocol strictly left to right;  integers   only

Power Supply on PicAxe Circuit Board

Power Input:                +7.0 V to +35.0V; connector is center positive; nominally +9.0V dc power adaptor is used (+9.0 V battery for portable use, but avoid if possible since current drain is high - battery won’t last long).

Power Output:            +5.0 V, regulated

                                       200mA maximum current

                                       Red LED “on” indicator.

This power supply is hardwired to both the PicAxe and the OLED display; red lead positive/black lead ground, 0V.

 

Philip Harris Barometer Sensor                    Blue Box

Use only the red and black banana jack connectors on the Blue Box.  Never use the blue banana jack.

Power requirements:                 +6.0 V; separate external battery pack

             Battery pack red lead positive/Black lead ground, 0V

Output (red/black banana jacks):

Output ranges from 0 Volts to +1 Volt, and is linear in relative humidity,     from 0 to 100%, sensed by the probe’

Red jack, voltage out; Black jack, ground, 0V.

Switch in “BATT” position:

The Blue Box output will be +1.0 V if the battery voltage is +6.0 V.   Replace batteries if this output is below +0.75 V (corresponding to a battery voltage of +4.5 V).

NOTE: Do not use blue banana jack – negative voltage on the PicaAxe input may damage the microprocessor.

 

Blue Box Manual

The simplest solution is to write a Flowchart in Logicator, convert the Flowchart into Basic language and modify the program as needed, for example, by naming the variables appropriately.  The Flowchart might look something like this:

Solution

Text Box: 01	'BASIC converted from flowchart; altered:
02	
03	{ ;Symbols
04	symbol RelHum = w7
05	symbol BlueBoxVoltage = w2
06	symbol Digit1 = w3
07	symbol Digit2 = w4
08	symbol Digit3 = w5
09	}
10	
11	fvrsetup FVR2048  		'set adc voltage reference to +2.048 Volts (not +5)
12	adcconfig %011    		'first bit (=0) means: adc low reference point is 
13						'Vref- (=0)
14						'next two bits (11) mean: use fvrsetup command to
15						'set adc high reference point Vref+ (2.084 V)
16	main:
17		let dirsB = 255
18	Cell_7_4:
19		fvrsetup FVR2048
20		adcconfig %011
21		readadc10 C.2, BlueBoxVoltage       			'read adc 10-bit
22		if BlueBoxVoltage >= 0 and BlueBoxVoltage <= 500 then     'test whether humidity is on scale
23			goto Cell_7_8     					'if so, go to cell 7_8
24		end if								'if not, "off scale"
25		serout C.1, N2400, (254, 128, "   Humidity     ")
26		serout C.1, N2400, (254, 192, "  (off scale)   ")
27	
28		goto Cell_7_4
29	
30	Cell_7_8:
31		readadc10 C.2, BlueBoxVoltage       			'10-bit adc 
32		let RelHum = BlueBoxVoltage / 5           		'convert to Relative Humidity
33		serout C.1, N2400, (254, 128, "   Humidity     ")
34		bintoascii RelHum, Digit3, Digit2, Digit1       	'convert to ascii numbers
35			if RelHum = 100 then    				'if 100%, say so
36				serout C.1, N2400, (254, 192, "     100 %      ")
37				goto Cell_7_4
38			endif 							'if < 100%, display only two digits
39		serout C.1, N2400, (254, 192, "      ",Digit2,Digit1," %      ")
40	
41		goto Cell_7_4
42	
43	
44	#no_data    'reduce download time
45	
46	'conversion: 2.048 volts correspond to 100% humidity and to (2^10 / 2.048 volts) = 1024/2.048V = 500
47	'500 bits corresponds to 100% humidity, so divide the input by 5 
48	'input C.2 = readadc10 binary value = BlueBoxVoltage
49	'then the conversion is RelHum = BlueBoxVoltage /5