## Testing the pressure sensor

Davespice
Forum Moderator
Posts: 1662
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands

### Testing the pressure sensor

Hi folks
Unfortunately it's not as easy to make the air pressure sensor values change as holding your thumb on the sensor or breathing on it. But I've come up with a neat and cheap way that you can use in the classroom with your kids.

You will need:
• A two litre plastic bottle (circular in cross section)
• A mobile phone top up battery
• A USB-A to Micro USB-b lead
• A pair of scissors
• Sticky tape, any kind
Check out this video:

Here is the code:

Code: Select all

``````from astro_pi import AstroPi

ap = AstroPi()
ap.clear()

ratio = 255 / 100.0

while True:
pressure = ap.get_pressure()
pressure = round(pressure, 1) - 1000
blue = int(ratio * pressure)
if blue > 255:
blue = 255
ap.clear((0, 0, blue))``````

Johnny5C
Posts: 82
Joined: Thu Apr 18, 2013 3:32 pm

### Re: Testing the pressure sensor

Thanks Dave! Going to try this with the kids later!

Davespice
Forum Moderator
Posts: 1662
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands

### Re: Testing the pressure sensor

Nice one. The range is 1000 to 1100 millibars. It assumes the resting air pressure is 1000 millibars or above, if it's below this it'll probably calculate the blue colour component as a negative number and then fall over. You can see it subtracts 1000 from whatever pressure is measured and then uses the ratio to calculate what the blue colour component should be.

Johnny5C
Posts: 82
Joined: Thu Apr 18, 2013 3:32 pm

### Re: Testing the pressure sensor

1027.34 Millibars this morning in sunny Gosport. Could use this to make a neat little graphical barometer..

aTao
Posts: 1086
Joined: Wed Dec 12, 2012 10:41 am
Location: Howlin Eigg

### Re: Testing the pressure sensor

If, instead of huffing and puffing into the bottle, you attach (air tight) a long piece of preferably clear hose pipe half filled with water, you can get positive and negative pressure by raising and lowering the free end of the pipe.
But do be careful not to get your astropi wet.
>)))'><'(((<

AndyD
Posts: 2330
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

### Re: Testing the pressure sensor

How about changing the Hue of the display based on the pressure, rather than the intensity. Something like this:-

Code: Select all

``````from astro_pi import AstroPi
import colorsys

ap = AstroPi()
ap.clear()

pressureRange = 200.0
basePressure = ap.get_pressure()

while True:
pressureDelta = ap.get_pressure() - basePressure + (pressureRange / 2.0)
hue = 1.0 - (pressureDelta / pressureRange)
rgb = colorsys.hsv_to_rgb(hue, 1.0, 1.0)

red = int(rgb[0] * 255)
green = int(rgb[1] * 255)
blue = int(rgb[2] * 255)

ap.clear(red, green, blue)``````
Note: I don't have an Astro Pi, so I can't test the code. I don't write very much Python.

JarJarGeek
Posts: 48
Joined: Tue Mar 18, 2014 11:32 am

### Re: Testing the pressure sensor

Yes , tested that Hue script , very cool ; http://fb.me/4uD4GHz9Z
Great work !!
@jarjargeek

syntax-err0r.com