Arduino Home Control Part 1

Background
A little background before I launch into a project I’m working on..

In the closing decades of the last century, just as the Internet age was about to start, I was one of two directors in a small company who innovated in electronics – we did it in a variety of ways, some projects were successful, some before their time and just occasionally came the odd project that was not completely thought out.

Home Control last-century style
Home control fell into the latter category. We were into using the PIC chips (from Microchip) at the time and we ended up with a bee in our bonnet about home control – wouldn’t it be nice to have little boards all over the house controlling stuff.  We developed the product before too deeply considering the market – but what a product it was for a time.

Essentially a small board with a PIC, a TRIAC output (for controlling lights and heaters – and yes we could handle compact florescent lamps without issue thanks to a VDR), a digital temperature sensor (Dallas), a couple of inputs and a simply transistor switch to control PWM sound output. The board was smaller than a pack of cigarettes, cheap, ran on 12v and had a unique ID number.  We could connect maybe 128 of these along a 4-core telephone wire (normal white twisted pair stuff commonly in use today).  We could manage maybe 100 metres.  At the end we had a little board which provided 12v power and interfaced by RS232 with a PC. A program on the PC showed a plan of the house and the boards showed as little coloured block superimposed on the map of the house. The colours changed depending on the input and output status of the boards in real time – and you could write a set of rules to control what the boards did. The 4th wire ran simple PWM sound from the PC speaker around and a transistor could be programmed on any board to turn on – hence enabling sound routing to any board.

Application Control
We called the system “Appcon” which immediately got us into trouble with someone in the apparel industry and we had to promise not sell competing products!! To give you an idea of how incredibly powerful this system was, in my home which had 40+ of these units, I had wall-mounted PIR movement sensors hooked to inputs, heating, lighting and alarm hooked to outputs as well as door magnetic sensors.

I could route cricket or bird sounds to speakers in the garden, I could detect open doors and turn the heating up depending on the time of year, with a closed switch I could enable an alarm system (all done by rules using nothing more than the basic devices and inputs – and my PC) and of course enable PIR triggered yard lighting only during certain hours of the day.

The Automated Home
A magical system and make no mistake, it  was successful in a small-business kind of way, we sold many hundreds of the units, we got in major PC magazines – for example PC-Answers May 1984 – “Wired Tales” heavily featured the system as did many others. We got the hobbyist market and that was it and really there was no way to make a fortune out of this – but we had great fun developing it, making new friends who were equally fanatical about home control – but then the problem was wires…

As I’ve found out in my cottage here in the country – with solid floors and 18-inch thick walls – you just can’t go putting wires all over the place – partners get really fidgety about this stuff.. but then the alternative, inexpensive radio doesn’t work too well through solid walls either and over-the mains control – well that tends to be limiting and expensive.

There are solutions out there today, lots of them, but they have severe limits and are relatively expensive. Somehow the idea of paying £20 to £30 for a board to control a light seems ludicrous to me and the cheaper systems are inflexible to say the least.

Moving ahead 28 years…

I’m into Arduino right now – which is merely a modern-day PIC (well, the PICs are still around and surprisingly little has changed there) and for some time I’ve been thinking of home control – the problem is that wiring just won’t work for me here… and radio modules generally are just too expensive to incorporate into boards – well, unless you want to throw away £30-40 all in just to control a lamp!!

Cheap Radio Solution
I recently discovered the NRF24L01 boards, available from China on Ebay for less than £2 (now THAT’s more like it) and if you’re into Arduino you’ll know that given the chip (the most expensive part and some suppliers really rip people off) you can put together a board for WELL under a tenner.

Line of Sight Radio
Ok, that’s a start, I looked up libraries to handle the radio chip and one, RF24, does a cracking job of one-to-one communication. Sending a small package of data from one device to another reliably is easy with these boards and the library. But we need to be realistic – the range is limited.

My pal and I did some tests a while ago – out in the open – MAYBE 60 metres on a nice day.. we tried the really cheap units and the ones costing 3 times as much with a nice stubby aerial – not that much difference amazingly so we stuck with the cheap units.  What does make a difference is speed – you can run them at up to 2Mbps – but drop that down to 256Kbps – and your range goes up to maybe 80 metres line of sight.

That’s open air – what about indoors? – OH DEAR ME… thick stone walls just about cripple the signal  – in my cottage I can just about manage to get through an 18” thick stone wall, you’re talking 20ft IF YOU ARE LUCKY. In other homes with thin internal walls  I’ve seen 40ft or more. It all depends on wall thickness and materials, on what other radio devices are operating etc. I was about to give up – but then started to think about networking – what if you could bounce the signal around as in networks – cellnet, Internet etc.. I thought I was asking too much of a small, cheap radio but the chips do have the basics of networking in them – they can LISTEN to up to 6 channels at once (but can’t listen AND send at the same time)  – maybe there was a future in this?

Networked NRF24L01?
I scoured the web, lots of half-arsed projects that went no-where and ONE project that looked like a starting point – it’s called RF24NETWORK.  It’s not a true network in so far as plugging in arbitrary units and having them relay stuff all over the place – but it’s a start and enough to make a practical system albeit for those who didn’t utterly fail maths.

I started playing with the library and with examples and had some teething problems – some of the examples would not work on the latest Arduino development environment (IDE) and some of the stuff was not too clear. I wrote to the developer. Nothing. I went to his website and wrote there – nothing. He’s either on holiday, or busy or dead – either way it looks like for now the one and only simple network is unsupported – but the good thing is – it works (there’s a caveat later). I wrote an article on the NRF24L01 and the RF24 library here originally.

Limited Network
I need to clarify… the NRF24L01 chips can listen to 5 other devices at once… that’s it. So how do you make use of that? The way RF24NETWORK code does this is to ask you to regularly call a function on all of your boards – this function transparently handles the networking. You have to number your boards. The boards are numbered in Octal (don’t let that put you off – the designer has used this to make best use of the 5-byte addressing) and Octal in Arduino is expressed with a leading 0. So, to express the Octal “222” you simply preface it with a zero – 0222.

This incredibly easy online convertor makes it all clear. 0222 is 146 in decimal for example. This is irrelevant of course but as this caught me out at first I thought I’d better explain why I’m prefacing numbers with zeros!!

There are numbers, then there are numbers
So, given that the boards can talk to 5 others – it makes sense to build a tree structure – any device can talk to a device further up the tree – and 5 devices below it. Device 1,2,3,4,5 can all talk to device zero (0) – and 0 can talk back to them – directly.  Moving outwards from there involves some hopping – BUT FEAR NOT as the software does that for you automatically – you just have to think about your numbering. In theory such a simple network should be easy to build but I can’t get my head around the acknowledge signals travelling up and down (how can you have unique packet numbering to ensure packets get there – when you can’t talk directly to the root!)… so for now, RF24NETWORK gets the job until someone comes up with a better solution.

It’s getting too complicated
The numbering system is well described in the RF24NETWORK pages so we’ll not go into that here. Suffice it to say you can attach thousands of units together – but I was thinking more of 2-100! I’m sitting here with device 0 talking to device 02 which is acting as a gateway to device 022.

Relax – you don’t need to know any more
So we’re talking hundreds of potential devices. Now it’s important to realise you just need to understand the numbers – nothing else as the networking software handles the rest.

If course all of this is ok but as units can’t talk and listen at the same time – I figured a controller was needed… and then what – you need to DO something with all of this… and I started a series of brainwaves which brings us to where I am now – developing a working home control system based on nothing more than cheap Arduino-type boards.

And that is the end of part 1 – in part 2 we’ll look at putting some meat on the bones – and yes, I’m sitting in front of a basic working system here, this isn’t going to be merely an academic effort – but there are some issues – read on.

See part 2.

Advertisements

4 thoughts on “Arduino Home Control Part 1

  1. Pingback: Arduino Home Control Part 2 | Scargill's Tech Weblog

  2. Pingback: Networking the NRF24L01+ | Scargill's Tech Weblog

  3. Pingback: Home Control over the Internet | Scargill's Tech Weblog

  4. Pingback: Home Control over the Internet | Scargill's Tech Weblog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s