The DHT11 temperature-humidity sensors pt 2

Here’s the graphs from my recent experiment, and here’s the data.

Temperature from 11 DHT11 sensors over 22900 data readings for each sensor

Temperature from 11 DHT11 sensors over 22900 data readings for each sensor

Humidity from 11 DHT11 sensors over 22900 data readings for each sensor

Humidity from 11 DHT11 sensors over 22900 data readings for each sensor

min, avg, max and variance of temperature from 11 DHT11 sensors over 22900 data readings for each sensor

min, avg, max and variance of temperature from 11 DHT11 sensors over 22900 data readings for each sensor

min, avg, max and variance of humidity from 11 DHT11 sensors over 22900 data readings for each sensor

min, avg, max and variance of humidity from 11 DHT11 sensors over 22900 data readings for each sensor

and a brief video…

The DHT11 temperature-humidity sensors

So I have loads of these from an old project that you guessed it – I never got round to, but how accurate are these cheapest of cheap things?

Set up an Arduino/RasPi with all the sensors and get it to read them all back – if all in one location then they should all be the same right? Lets see how accurate they are! I’ll run the test for a week (probably longer) with various conditions and then report back.

oh and some code….

// origional code from ladyada, public domain
#include "DHT.h"

DHT dht0(2, DHT11);
DHT dht1(3, DHT11);
DHT dht2(5, DHT11);
DHT dht3(6, DHT11);
DHT dht4(7, DHT11);
DHT dht5(8, DHT11);
DHT dht6(9, DHT11);
DHT dht7(A0, DHT11);
DHT dht8(A1, DHT11);
DHT dht9(A2, DHT11);
//older sensors
DHT dht10(A4, DHT11);
DHT dht11(A5, DHT11);

float temps[12];
float hmids[12];

void setup() {
Serial.println("DHT test!");

void loop() {
// Wait a few seconds between measurements.

hmids[0] = dht0.readHumidity();
temps[0]= dht0.readTemperature();

hmids[1] = dht1.readHumidity();
temps[1]= dht1.readTemperature();

hmids[2] = dht2.readHumidity();
temps[2]= dht2.readTemperature();

hmids[3] = dht3.readHumidity();
temps[3]= dht3.readTemperature();

hmids[4] = dht4.readHumidity();
temps[4]= dht4.readTemperature();

hmids[5] = dht5.readHumidity();
temps[5]= dht5.readTemperature();

hmids[6] = dht6.readHumidity();
temps[6]= dht6.readTemperature();

hmids[7] = dht7.readHumidity();
temps[7]= dht7.readTemperature();

hmids[8] = dht8.readHumidity();
temps[8]= dht8.readTemperature();

hmids[9] = dht9.readHumidity();
temps[9]= dht9.readTemperature();

hmids[10] = dht10.readHumidity();
temps[10]= dht10.readTemperature();

hmids[11] = dht11.readHumidity();
temps[11]= dht11.readTemperature();

Serial.print("Temps ");
for (int i=0;i<12;i++)
Serial.print(", ");

Serial.print("humids ");
for (int i=0;i<12;i++)
Serial.print(", ");

//write data to SD card
File dataFile ="dhtdata.txt", FILE_WRITE);
if (dataFile) {
dataFile.print("Temps, ");
for(int i=0;i<11;i++)
dataFile.print(", ");

dataFile.print("Humids, ");
for(int i=0;i<11;i++)
dataFile.print(", ");



How much of a table is in use?

I’ve been working on a web based monitoring tool for a while now and it’s getting close to completion. A thought crossed my mind, and be prepared it’s a wild one.

WHAT IF: my site get’s so popular I hit the upper limits of the index or field size of the primary keys of the tables?

Well clearly – it’d break and then i’ld get am email or something telling me to fix it and I would go and change the field types to allow more… problem solved…. but it’s not very nice! and it means downtime! (ironically not something I want for a tool designed to measure downtime!)

Anyway – I’m building in monthly, weekly and daily email routines to let me know certain bits of information regularly without me having to log in, and I thought why not add something that tells me how much I have used? So I did.

Here’s my solution (but not my code):

get a list of tables,
for each table,
get table name,
get primary key,
get field type and convert to human friendly numbers,
get number of rows in use,
work out usage in %,

Half an hour using google and a bit of common sense I now have a page that shows me the stats of the primary key usage and now I can add them to the email routines.

RGB colour correction

So I’ve been playing with different colour correction techniques for my LED’s.

So here’s a simple one. Square it. Well ok, square it then divide through by the upper value (square and scale.) So:
unsigned int value = (i*i)/255;

which sort of works. But it’s a little jumpy in the lower regions, as the mapping looks like,
(23,27)->2, ect….

The next I’m trying is something called Quadratic interpolation using¬†a Lagrange Polynomial. BIG words for a curve of best fit. It works by generating a polynomial through a number of pre determined points. I have worked it out using 1->1, 255->255, and then 128->c. I can then change c, effectively changing the correction to the colour. Only problem is that it gets a little complex. So the maths formula is;

(-cx^2 +256cx -255c+128x^2 -16639x+32640)/(16129)

I attempted and failed to implement this as Arduino isn’t really the right platform for doing this kind of arithmetic. It works in excel ‘tho and produces a lovely graph.

mapping curves

A graph showing various possible curves

The Black curve in the graph is actually the square and scale method above. The other are for various choices of c.

So I quickly mapped the first 32 values i->x to the 32 LEDs I have and they are quite linear, from there on I found every bank to be quite similar. Which led me to the conclusion that for small values a one to one correspondence was ideal, then a kind of s curve would be ideal. I tried a few cubics but they were quite complex to implement and even tried a quartic.

So back to a basic square and scale I think for now.

Hyper-V and Vlans

So I’ve now got 2 identical hosts running server 2012 datacenter, with VM’s on both. Now it’s time to get them talking to one and other. Simple right, just sit them all on ‘external’ virtual switches and they can use the physical network to talk to each other. Great except… I don’t really want my test environment hooked upto my live environment, not do I want to change my existing DHCP server settings or have two on the same broadcast domain!

So, Hyper V can use VLANs to segregate traffic. This is the way forward for me.

  1. 1 create a new VLAN for the test environment,
  2. tag the ports for the VLAN,
  3. put all VMs on the new VLAN…
  4. oh and change the management VLAN in the virtual switch manager for the hosts…

Groovey now I can talk to the host over my LAN (on VLAN 1) and the VMs can talk to each other on VLAN 200, but they as VLANs are completely segregated in terms of broadcast domains (for DHCP) and packets. Now I can set up a (virtual) router to bridge between them. PFSENCE time.

Raspberry PI Time-Lapse Camera Fun.

So I’ve decided that I wanted to do some time-lapse photography for my next project, and my brother wont let me borrow his GoPro…. I could go and buy one – but that’s no fun.

Anyway, I’ve had a Raspberry PI ¬†for some time now (sitting under my bed), and a camera module for it (thanks for an awesome christmas present sis), so I thought… surely that’s possible, no?

Well – have a look at this for how to make it… super simple.

Following those instructions:
install camera, sudo raspi-config then enable camera,
using the following command to take a pic, raspistill -o cam.jpg

And to do multiple shots: raspistill -o frame%04d.jpg -tl 5000 -t 60000

This will store a series of still images in the current directory. And then to turn these into a video file you will need to do the following;
sudo apt-get update (requires network/interenet access)
sudo apt-get install libav-tools
avconv -r 10 -i frame%04d.jpg -r 10 -vcodec libx264 -crf 20 -g 15 timelapse.mp4

wahhoooo – except it didn’t work for me the first, or second time… Meh, I’ll just take the pics and worry about video assembly later.

Anyway – there’s many¬†great resources on how to call the raspistill command/function on the net.

You can re-size the images as they are captured by adding height and width to the call:
raspistill --width 1280 --height 960 -o cam.jpg
And the following link has more about the raspistill command.

Moving on, I want to be able to access my files remotely so time to install samba,
sudo apt-get install samba samba-common-bin
sudo leafpad /etc/samba/smb.conf

and add the following:
comment = the timelapse folder
browsable = yes
writable = yes
only guest = yes
create mask = 0777
directory mask = 0777
public = yes

Which will make the folder publicly available on the network (you might need to make the directory first too with mkdir). You will also need to open the file browser with root access and¬†change the permissions on the folder so that ‘other’ is read and write (otherwise you wont be able to remove the files so the PI doesn’t become full (I only have an 8GB SD card in mine!)).

Great so we have a folder and a way of capturing images… but, I want my time-lapse to be over weeks, not hours, so I’m using an interval of 4 mins between frames.

Step One Рcreate a bash script to take the picture. Create a new file called or what ever takes your fancy, but with a .sh extension.

Step Two – populate file with the following:
DATE=$(date +"%Y-%m-%d_%H%M")
raspistill -n --width 1280 --height 720 -o /home/pi/timelapse/$DATE.jpg
and SAVE IT. You can probably work out that this takes a picture, and stores it in the folder we created above (or another folder if that takes your fancy) with a date_time stamp. Once saved you will need to modify the properties so that the file is executable.

Step Three – Cron job time. Open a terminal prompt up and type “sudo crontab -e” to get to the cron job editor. Add the following:
*/4 * * * /home/pi/timelapse/ then write and close (ctrl O and ctrl X)

As you guessed this will fire the bash script we created above once every 4 mins. Search for “cron every x minutes” for more details on how to create and edit cron jobs.

Brill. Job Done… Well… Job almost done. Now I just need to make sure the PI doesn’t fill up and run out of storage and then I will need to make all of the images into a time lapse video.

And here’s the result.

Oopsie, server failure

So just turned my server on to play with Hyper V stuffage, and hummmm…. it wont pass POST. It beeps telling me there’s a RAID failure, but then dies before showing me the diagnostics page that it would normally show… HuMmM!

SO, pop the hood, thinking maybe it’s a¬†RAM failure and I knocked a CPU heat sink… which then fell off. Think I’ve found the problem then.

Oh, and then I’ve run into this again….

SLAT error :/

SLAT error :/

Time to break out Server 2012 DC edition again….Which also doesn’t like the server, time to break out the server 2008 disk, which supports SLAT, but didn’t require it. Might have better luck with it. Only problem there is that Server 2008 doesn’t support live migration and replication in the way that 2012 does :/.

*As a heads up for anyone wanting to play around – save some time and do some research on your processor. It needs to be 64bit, support Intel VT-x and Intel VT-x with Extended Page Tables (EPT). The best place to find this information is in the Intel ARK if you are using Intel proc’s. Have a look at my proc’s here.¬†*