Remote Power Management using Arduino

2016-03-04 21.20.07

2016-03-07 Update: Git Repo available

Recently I’ve been involved with building a hardware device consisting of a cluster of low-power PC servers. The boards chosen for this particular project aren’t enterprise or embedded -style boards with specialist features like out of band (power) management (like Dell’s iDRAC or Intel’s AMT) so I started thinking about how to approximate something similar.

It’s also a little reminiscent of STONITH (Shoot The Other Node In The Head), used for aspects of the Linux-HA (High Availability) services.

I dug around in a box of goodies and found a couple of handy parts:

  1. Arduino Duemilanove
  2. Seeedstudio Arduino Relay Shield v3

The relays are rated for switching up to 35V at 8A – easily handling the 19V @ 2A for the mini server boards I’m remote managing.

The other handy thing to notice is that the Arduino by its nature is serial-enabled, meaning you can control it very simply using a USB connection to the management system without needing any more shields or adapters.

Lastly it’s worth mentioning that the relays are effectively SPDT switches so have connections for circuit open and closed. In my case this is useful as most of the time I don’t want the relays to be energised, saving power and prolonging the life of the relay.

The example Arduino code below opens a serial port and collects characters in a string variable until a carriage-return (0x0D) before acting, accepting commands “on”, “off” and “reset”. When a command is completed, the code clears the command buffer and flips voltages on the digital pins controlling the relays. Works a treat – all I need to do now is splice the power cables for the cluster compute units and run them through the right connectors on the relay boards. With the draw the cluster nodes pull being well within the specs of the relays it might even be possible to happily run two nodes through each relay.

There’s no reason why this sort of thing couldn’t be used for many other purposes too – home automation or other types of remote management, and could obviously be activated over ethernet, wifi or bluetooth instead of serial – goes without saying for a relay board -duh!

int MotorControl1 = 4;
int MotorControl2 = 5;
int MotorControl3 = 6;
int MotorControl4 = 7;
int incomingByte = 0; // for incoming serial data
String input = ""; // for command message

void action (String cmd) {
  if(cmd == "off") {
    digitalWrite(MotorControl1, HIGH); // NO1 + COM1
    digitalWrite(MotorControl2, HIGH); // NO2 + COM2
    digitalWrite(MotorControl3, HIGH); // NO3 + COM3
    digitalWrite(MotorControl4, HIGH); // NO4 + COM4
    return;
  }

  if(cmd == "on") {
    digitalWrite(MotorControl1, LOW); // NC1 + COM1
    digitalWrite(MotorControl2, LOW); // NC2 + COM2
    digitalWrite(MotorControl3, LOW); // NC3 + COM3
    digitalWrite(MotorControl4, LOW); // NC4 + COM4
    return;
  }

  if(cmd == "reset") {
    action("off");
    delay(1000);
    action("on");
    return;
  }

  Serial.println("unknown action");
}

// the setup routine runs once when you press reset:
void setup() {
  pinMode(MotorControl1, OUTPUT);
  pinMode(MotorControl2, OUTPUT);
  pinMode(MotorControl3, OUTPUT);
  pinMode(MotorControl4, OUTPUT);
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  Serial.println("relay controller v0.1 rmp@psyphi.net actions are on|off|reset");
  input = "";
} 

// the loop routine runs over and over again forever:
void loop() {
  if (Serial.available() > 0) {
    incomingByte = Serial.read();

    if(incomingByte == 0x0D) {
      Serial.println("action:" + input);
      action(input);
      input = "";
    } else {
      input.concat(char(incomingByte));
    }
  } else {
    delay(1000); // no need to go crazy
  }
}



Going Green / The Iceman Cometh

Well it’s turning cold again. Doesn’t say too much for this country but we’ve definitely seen the last of summer. The fog’s setting in and it won’t be long before I’m scraping the ice off my car in the mornings.

So it’s cold, and I want myself, my family and my house to be comfortably warm as cheaply as possible. I’ve always tried to be fairly green but it turns out it’s not particularly cheap in terms of initial outlay although it tends to pay for itself in the longer term.

It turns out of course that it’s not just more heat but also more light you need come winter. So when we moved into the new house I set about replacing the lightbulbs with the disproportionately-priced energy-saving lightbulbs (the folded fluorescent-tube variety). Unfortunately the kitchen and bathroom are each fitted with a series of 50-watt mains-voltage spotlights, GU10 if memory serves. Energy-saving (7-watt) equivalents are nigh-on £10 each from Homebase , and not particularly common, either.

That’s really not a particularly enticing price when simply compared to the full-on regular bulbs for well under £2 each. But, like I say long-term they will pay for themselves pretty quickly, depending on how much you pay your power provider.

So switching out these bulbs got me thinking about how to cut out the electricity supplier all together. Where my place is located, it’s not directly near any sources of water or constant wind (of the renewable-energy-source variety). I figured solar panels were my only option. Not bad when you find out you can have some of the installation paid for by the government, but not so great when you find out that the total cost of an average installation is of the order of £10,000. Hmm – we’ll be saving up for a while!

Well, then I widened my criteria – a lot of my searching for energy efficiency is actually driven by the need to lower expenses and outgoings. Obviously finding the lowest-cost service provider is a good start – I tried out Uswitch to move from Powergen to EDF (but not before I’;d claimed my free energy-saving lightbulbs as a “new” Powergen customer!).

So I realised a large chunk of my outgoings are car-related. With the current, wallet-shattering prices of diesel it’s a good place to look for economies. Biodiesel definitely seems to be the way forward. From a little scouting around I see that there are two common types of useful fuel, 100% biodiesel and 95/5% petroleum diesel and biodiesel mix. A little more digging and you can find lists of cars and which approved mix their warranties allow. Sadly it was at this point I found my Peugeot 306 seems to only accept the 95/5 mix (I forget which standard code this is) so it’ll only save me 5 pence in the pound. Next time I change my car I’ll be sure to make this one of my criteria.

Of course there’s a thriving cottage industry in recycling frying oil from vans, chip shops and the like. Making your own biodiesel seems to be relatively easy given a simply chemistry kit and the right license. Only a little more surfing and it turns out one pretty neat thing to do is to couple the electricity supply problem with the biodiesel phenomenon. Buy a little generator and either run it straight on home-brew biodiesel or modify it to convert plain old vegetable oil on-the-fly. Fantastic idea but my wife doesn’t want the “pleasant aroma of french-fries or popcorn” in a cloud sat in the back-garden. We’re sufficiently close to the neighbours that I suspect it wouldn’t go down too well with them either.

Oh well, back to the drawing-board.

Back, at least to the energy saving… The right windows and doors are obviously important and that’s next on the big list of home-improvements. I think it’ll wait until next summer or so, when we’ve saved up quite a few pennies. I reckon we should be able to fit the place out (a moderate-sized 3-bedroom semi-detached) for around £4000-£4500 . Not insignificant, but again worth it in the long term.

Until then I’ll have to make do with simply replacing the loft-insulation. It’s gone from around 1cm thick ancient rubbish to shiny, new, pink, 17cm thick over the half I’ve done. The only problem now is I’d like to add loft floorboards without popping out the plasterboard ceilings below. Doh! Maybe I’ll go with 10cm thick stuff for the rest. It’s all currently 3 for the price of 2 rolls, again from Homebase.