Regular readers will know of my interest in (obsession with?) the temperature and humidity here in the office. Today I took this to a whole new level with this:
That’s an Arduino wired up to a DHT22 temperature and humidity sensor ($9.95 from The Robot Shop).
Using the wiring diagram helpfully provided by Adafruit I connected the DHT22 to the Arduino, with data flowing in on pin #7.
Next I installed this DHT library for Arduino and then used this slightly adapted Arduino sketch to actually grab the data:
#define DHT11_PIN 4
#define DHT22_PIN 7
int chk = DHT.read22(DHT22_PIN);
It took a little bit of fiddling to get things to work – it turns out that I’d used the wrong resistor to bridge the data pin with the 5V pin – but once it was working, monitoring the virtual serial port on my Macbook displayed the current humidity and temperature every 2 seconds:
and so on.
Finally, to pipe this through to Cosm and the world, I set up this Python script to run in the background on my Mac (adapted from here; I needed to install python-eeml and pySerial first):
API_KEY = 'MY API KEY'
API_URL = '/v2/feeds/104026.xml'
arduino = serial.Serial('/dev/tty.usbserial-A6008jtr', 115200)
readings = arduino.readline().strip().split('\t')
pac = eeml.datastream.Cosm(API_URL, API_KEY)
pac.update([eeml.Data(0, readings, unit=eeml.unit.Celsius()),
eeml.Data(1, readings, unit=eeml.unit.RH())])
The result is this Cosm feed, showing temperature and humidity for the office:
The old analog gauge in the office agrees with the DHT22 measurement almost exactly; the humidty on the analog gauge reads about 6% higher:
I’d like this setup to be less dependent on the intermediate MacBook (it makes the MacBook far less portable, for one thing), so my next step will be to adapt the setup to either use the Raspberry Pi to gather and forward the data, or to get an Ethernet shield for the Arduino so that it can hand this by itself.