Controlling a central heating boiler using an arduino
To control my central heating, I needed some way of turning my boiler onand off.
First Attempt
Initially I thought I would have a direct connection to the boiler. So I managed to find the manuals on the Worcester Bosch web site and proceeded to dismantle my boiler to find out where I would need to make the conections. My boiler requires mains voltage signals to request heat so I built a relay to allow me to use 5V signals from my arduino to control the boiler.
I wasn't feeling masively positive about this approach since it would require me to have an arduino next to my boiler. Since I only had one arduino, this would mean I'd have to buy another for monitoring my gas usage - not ideal.
Second Attempt
Which brings me to my second attempt at designing this. I have a standard British Gas wireless thermostat.
The display on the front usually shows the current temperature, but when the dial on the front is rotated, it shows the desired temperature.
Inside, there's a small thermistor and a couple of switches. The dial on the front is had ridges on the back that trigger the switches as it turns. The two switches are out of phase with each other compared to the ridges, so turning the dial causes one switch to trigger before the other. The order of the triggering determines the direction of the dial.
With some help from GarethDEdwards I soldered some tidy wires to the back of the circuit board. I hen connected those to 3.5 mm audio jack on the bottom so I could easily plug it into my arduino.
Sample (simple?) code for control by arduino is below
////////////////////////////////////////////////
// Thermostat control section
////////////////////////////////////////////////
int delayTime = 10;
void setTemp(int desiredTemp)
{
if (desiredTemp == currentTemp)
{
// Do Nothing
// Serial.println("Doing nothing");
}
else if (desiredTemp <=5)
{
// Requested a minimum temp, make sure we're really on the min temp...
int numberOfDowns = 30;
while (numberOfDowns > 0)
{
down();
numberOfDowns--;
}
currentTemp = 5;
}
else if (desiredTemp >=30)
{
// Requested a maximum temp, make sure we're really on the max temp...
int numberOfUps = 30;
while (numberOfUps > 0)
{
up();
numberOfUps--;
}
currentTemp = 30;
}
else
{
while (desiredTemp != currentTemp)
{
if (desiredTemp > currentTemp)
{
up();
currentTemp++;
}
else
{
down();
currentTemp--;
}
}
}
}
void down()
{
//Serial.println("DOWN");
leftDown();
rightDown();
leftUp();
rightUp();
}
void up()
{
// Serial.println("UP");
rightDown();
leftDown();
rightUp();
leftUp();
}
void leftUp()
{
//Serial.println("LU");
pinMode(leftPin, INPUT);
delay(delayTime);
}
void leftDown()
{
//Serial.println("LD");
pinMode(leftPin, OUTPUT);
digitalWrite(leftPin, LOW);
delay(delayTime);
}
void rightUp()
{
//Serial.println("RU");
pinMode(rightPin, INPUT);
delay(delayTime);
}
void rightDown()
{
//Serial.println("RD");
pinMode(rightPin, OUTPUT);
digitalWrite(rightPin, LOW);
delay(delayTime);
}
Monitoring and controlling central heating
Just before Christmas I decided that I should dust off my neglected Arduino and do something with it. Ever keen to jump on the green bandwagon I decided that monitoring and controlling my central heating would be a good idea.
This is going to be the first in a series of posts decribing my adventures.
The plan was to give me control of my boiler so I could turn it on or off over the internet. This was to allow me to ensure the boiler wasn't on when I was out, or to turn it on before I got home.
There are a few parts to this project
- Controlling the boiler
- Monitoring how much gas I'm using
- Monitoring the temperature
Here's what I had to work with:
- A standard arduino MEGA
- A Worcester Bosch 28i Junior boiler
- A British Gas Wireless Thermometer
- A Buffalo Linkstation Live NAS (running linux)
Next post is going to be how I'm controlling the boiler.
Creating a timelapse from a Foscam IP Camera
After purchasing a cheap Foscam FI8918W off eBay I couldn't resist creating a few simple timelapse videos. I created a simple perl script to help with the process. It allows me to specify
- how many seconds I want the timelapse to last for
- how long to wait between each shot
After its finished it uses ffmpeg to combine the jpegs into a timelapse movie.
Overall, I'm pretty happy with the results. The camera performs exceptionally well in low light conditions but seems unable to reliable pictures of outside during daylight - image are always washed out.
Anyhow, without further ado, the code is below:
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
my $spacing = 5;
my $captureLength = 30;
my $verbose = 0;
my $result = GetOptions(
"length=i" => \$captureLength, # numeric
"spacing=i" => \$spacing, # string
"verbose" => \$verbose
);
print "Capture every $spacing for a total of $captureLength\n\n";
my $startTime = time;
`mkdir -p $startTime`;
my $endTime = time + $captureLength;
$verbose && print "Started at $startTime and will finish at $endTime\n";
my $index = 0;
while (time < $endTime)
{
$verbose && print "Time is " . time . "\n";
my $output = sprintf("%s/image-%s-%05d.jpg", $startTime, $startTime, $index);
`curl http://192.168.1.115/snapshot.cgi -u root:password -s -o $output`;
$verbose && print "Saved $output\n";
$index++;
sleep($spacing);
}
# Now encode a video, naming it after the starttime.
`ffmpeg -r 30 -i $startTime/image-$startTime-%05d.jpg -b 4000k $startTime.mpeg`;

