Mains Power Sensor

The objective of this project is to allow our contextual smart home to know if the mains power has failed, so that it can raise an alarm and take appropriate action. Our smart home can work without power because we use a UPS to keep all the essential elements of our smart home going in the event of a power cut.

Warning:  This project involves mains voltages and these can kill.

Design

There are lots of ways to detect mains power and translate its presence or absence into a safe and meaningful voltage level, to feed into a device like and Arduino. Optical isolation is essential, because you don't want to risk putting 240V ac onto a computer circuit board or yourself!

The design involves using the mains supply to power a neon lamp (which typically have a current limiting resistor) and the generated light shines on to a Light Dependent Resistor (LDR).

A Light Dependent Resistor (LDR) is a very cheap and readily available sensor and its resistance varies depending on how much light is incident on its surface. There are numerous LDR devices with varying specifications. The ones we are using vary in resistance from about 150Ω in direct sunlight, to more than 1.2MΩ in complete darkness.

We use the LDR as half of a voltage divider and a 10KΩ resistor as the other half. The output of this sensor is the centre point of the voltage divider and when 5V dc is applied to it, the output essentially switches between 0V and 5V dc as the LDR is switched on and off.

There is a large air gap between the neon and the LDR (>15mm) providing a very high level of electrical isolation. The components are mounted inside a sealed enclosure, to ensure no external or ambient light gets in.

Build

Connection to the mains is achieved using an old power lead with the figure-8 plug cut off to expose the live and neutral wires. We use a terminal block to connect the cable ends to the neon bulb. It is best to add strain relief on the mains cable entry to the enclosure, to ensure it can't be pulled out by accident. The fuse in the cable plug has been replaced with a 1A fuse and it is simply plugged in to a suitable, local power socket.

The above sensor exposes the LDR output (a varying resitance) via one of our standard smart home connectors and we then connect it to an Arduino processor via our Arduino smart home shield. Because the output resistance varies by such a large amount, this sensor works with both an analogue or digital input on an Arduino.

Insight & Learning

This solution works really well and is extremely responsive. When the mains power fails or is restored in our house, we get a voice announcement and a notification.