94. Translucence

The birthday present 2: Electronics

Pressure sensor

I had an idea. I wanted the backlight to change colour, and in an interesting way, so it occurred to me to change the colour according to the weather outside – red for bad, green for ok, blue for good. Air pressure is a good indicator of weather (low for bad, high for good) and I found a pressure sensor for about £3 on eBay (BMP280).

It communicates using either I2C or SPI. I used the former, with the ready-made Arduino libraries (the Adafruit ones need to be downloaded from Github as zip files and added to the Arduino IDE) and help from the tutorial at ArduinoAutoMotive:

#include <Wire.h>
#include "SPI.h"
#include <Adafruit_Sensor.h>
#include "Adafruit_BMP280.h"

The only problem was that the sensor runs at 3 Volts and I was using a 5 Volt Arduino. There is a 3V output on the Arduino board which I used to power the sensor, but the I/O pins are also 3 Volt, not 5. The spec. for the sensor does say that this is ok, but I didn’t trust it, so I built a level converter I found at Hobby Electronics. It only requires one transistor and two resistors, and I used the same sort of MOSFET I use for switching the lights. (There’s one converter for each of the clock and data wires.)

Main PCB

Using the sensor is easy. Once it’s initialised you just call the .readPressure() function and it returns the air pressure in millibars as an unsigned long (note that there’s one implied decimal point, so 1012 millibars will return 10120).

There’s just one complication. When they show a weather map on TV or on the internet, the pressures are sea-level equivalents. So, for example, if the TV says the pressure is 1012 millibars where you are, but you are at, say, 200 metres above sea level, then the sensor will give a reading lower than 1012. Both are correct! If you dug a 200 metre deep hole in the ground and took the sensor down to the bottom it would match the number given on the TV.

To get a reading that matches all the weather maps you need to adjust the sensor’s reading by its height above sea level. I worked it out as follows:

Sea level pressure = Sensor reading * (Metres above sea level * 0.1325)

External boxRather than hard-code my current height above sea level, I added an external box with a small potentiometer that I calibrated to the frame, so that if I move I can easily recalibrate it. The software checks it once on power-up.

The other thing I decided to add was a motion sensor. I thought it might be nice if the backlighting went off when there’s nobody in the room. I used a passive infrared sensor. It’s very easy to use. You just give it 5-20 Volts and when it detects movement the output goes high (3.3 Volts) which counts as high on both 3V and 5V Arduinos.

Here’s the finished electronics.

Assembling

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s