Thursday, April 3, 2014

Concept: off-the-grid sensor module

I love the idea of home automation. I'd like to keep an eye on temperatures inside and around my house, monitor power, gas and water consumption, have smart lighting, etc. The possibilities are endless, and they are in fact feasible and affordable nowadays. If I were to get a new house, I'd make sure I'd have multiple power outlets in every wall, with LAN and 12 or 5 volt as well.

Unfortunately the house I bought was built in 1968, has very few outlets (2 per bedroom at most) and walls you really don't want to put a drill in, unless you like plastering and painting. So having temperature sensors in every room would involve lots of extension cords, wall warts and possibly LAN cables.

Going wireless

The first thing to get rid of is LAN cables. Let's go wireless instead. Since my house has only wooden floors and no thick reinforced concrete walls, there should be no problem getting coverage on all three floors. WiFi and ZigBee/XBee is a bit too expensive, so I'd rather settle with the Nordic nRF24L01+, you can get those 2.4 GHz boards with PCB antenna for as little as $1,50 a piece from eBay, whereas an XBee would cost about $20 to $30 a piece. Even though the range on the nRFs is limited, it should be enough. I don't need much bandwidth either; the lowest setting (256KBit/sec) should be plenty.
There should be a master unit somewhere in the house, the meter cupboard would be a good candidate; it already contains my switch, NAS, gas meter and power meter and fuse-box. This master unit should collect all the data from the sensor units and have an Ethernet interface to present the collected data to a web server that can host a front-end (my NAS for example).

The sensor units need power to operate obviously, but I don't like the idea of having to use a wall wart for every single sensor unit, nor do I want to have put low voltage power lines throughout my house. Having wall warts would not only occupy most of my power outlets, but also adds unnecessary power consumption. One way to get rid of that is by using batteries, but how long will those last? Well, bring out the datasheets and calculator!

Calculating power consumption

The ATmega328 used in  the Arduino Uno and Nano has a couple of low power options. First of all you can run it at a lower clock speed using the 128KHz internal oscillator, this reduces active consumption from around 10 mA to just 0.12 mA; quite a difference, and it frees up 2 IO pins :) If we reduce Vcc to 3.3V then we go down even further to about 0.06 mA. If we make it enter idle mode then power consumption drops to a measly 0.015 mA. Enter power save mode and we're down to 0.001 mA, sweet.

The nRF24L01+ doesn't exactly consume loads of power either. Full power transmission requires about 11.3 mA and receive mode at 250 Kbit/s needs 12.6 mA. Since I'm only planning on sampling data once every five minutes or so, we can just turn the nRF off for the rest of the time. Power down supply current is 0.0009 mA.

A simple temperature and humidity sensor like the DHT11 draws about 0.5mA when sampling and 0.2mA on average. We can probably power this straight from one of the ATmega's IO pins, so we can turn it off completely when we don't need it. A light sensor also draws current in the order or milliAmps, so we can use the same trick there to reduce consumption in low power mode.

I have a bunch of 120mAh Lithium Polymer batteries from a micro helicopter. LiPo's provide 4.2V when fully charged but shouldn't be drained below 3.5V. ATmega's and a lot of sensors will have no problems with this kind of supply voltage range, but the nRF requires 3.3V so we'll need a low dropout regulator (LDO) with a very low dropout voltage. A normal 7803 won't do, it needs in input voltage that is at least 1V above the desired output voltage. An MCP1700 will do the trick, it has a dropout voltage of 200 mV at full load (250 mA), perfect. The current drawn by it is extremely low as well; less than 2 micro amps at room temperature. We can use this to power everything, or just the nRF, I'm not quite sure yet.

Running the numbers

At full load the sensor setup will draw 0.06 (ATmega) + 12.6 (nRF) + 0.5 to 5 (sensor) mA of current. Add a bit for supporting hardware and our ballpark figure is 20 mA. In idle mode we end up in the micro amps range. 1 (ATmega) + 0.9 (nRF) + 2 (MCP)  = 4 uA or 0.004 mA. In order to calculate battery life we have to know the ratio between idle and active time, or the duty cycle. Say we sample and transmit data once every 5 minutes (300 seconds) and we can do this within 3 seconds, then we end up with a duty cycle of 1%. So 1% active vs 99% idle. Or average power consumption ends up being 1% x 20mA + 99% x 0.004 mA = 0.20mA (plus a few micro amps). Since my batteries have a capacity of 120mAh (meaning a 120mA device will drain it in 1 hour, or a 1 mA device can run on it for 120 hours), we end up with a battery life of 120 / 0.2 = 600 hours.

Now 600 hours sounds like a lot, but it's just 25 days. That means replacing and recharging batteries 15 times a year, probably more since you don't want to drain them completely. Having a bigger battery helps a bit, 1800mAh batteries are widely available for as little as $5, that would reduce recharging/replacement to once a year. Battery voltage can be monitored using the ADC and a 3.3V reference voltage and we can just add the voltage information to the sensor data.

Why stop there?

Why not create something that is truly off-the-grid and recharges itself? Small 6V solar panels are dirt cheap and so are small LiPo recharge controllers. A small 85 x 85 mm panel may deliver up to 150 mA at 6V and costs less that $5. A complete TP4056 charger controller board costs less than $3 and it'll accept anything between 5 and 8 volts on the input. So for less than $10 we can make the sensor unit self powered! Even if the panel gets only one hour of sunlight, that should be enough to recharge the battery with 100mAh, or 20 days of juice, that's plenty! Even something like a 50 mA panel will do the trick, as long as you can get at least 5V from it. Heck, even a couple of solar cells from those old calculators might do the trick, although you probably need a certain minimum current for the charger to work.

Efficient remote controlled switches

One last idea I'd like to pitch is a remote controlled AC switch. This kind of device would be perfect if you need to control a much larger current and already need a wall wart. The idea is to add a solid state relay between mains and a wall wart. The wall wart powers the charger and additional current hungry equipment like led strips. The ATmega can simply switch the relay on whenever current is required, or when the battery runs low. In case of automatic lights you no longer have the loss of the wall wart when the lights are off (which they are most of the time). The additional current required to recharge the battery is completely insignificant compared to a decent LED strip. The same trick can be used to create remote controlled AC switches for turning other devices on and off.

No comments:

Post a Comment