AC Voltage Detection

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

If an electrical connection is taken from inside the appliance on the right (switched) side of the switch used to operate it, this can then be used as a signal to the smart home.

An good way to do this voltage detection is with the H11AA1 bi-directional input optically coupled isolator. These cost as little as 25p each.

Typically these would be installed in the back boxes or surface boxes with a wired connection to an Arduino. In a new build, this approach makes a lot of sense and is very cheap to do.

H11AA1 Design

You can't just connect the mains voltage to the H11AA1 IC as this will fry the internal LEDs. Suitable resistors are required and these must be able to handle the power dissipated as heat through them but also be rated to handle the voltages placed across them. I'm using two 39KΩ resistors (in series, making a total of 78KΩ) rated at 1W but testing showed that four 39KΩ resistors (in series, making a total of 156KΩ) also worked reliably.

The main problem with this simple circuit design is that the resistors are dissipating quite a lot of power. With two 39KΩ resistors this will be about 740mW. Using four resistors will halve this wasted power. Whilst this power usage is OK for detecting devices that are occasionally switched on, you wouldn't really want to waste this much power whilst detecting when a device is switched off (e.g. for mains power failure detection).

The output from the H11AA1 will be a pulse train and I want to convert this to a binary state, to feed into an Arduino input pin. This is achieved by using a small capacitor between 0.1uF and 1uF. On my PCB, I used a 0.47uF capacitor as I had a load of these to hand. This then provides a steady state output for the Arduino to detect. The response time is very good and less than 0.5 seconds.

The basic circuit to connect the IC to the Arduino. It uses a 39K 'pull up' resistor, so the input pin is active LOW. When an ac voltage is detected the Arduino input pin is pulled to ground by the transistor in the opto-coupler.

I designed a PCB using Autodesk Eagle to create a module that can be easily interfaced to my other Arduino input boards. I deliberately designed it to accept four 1W resistors but wire links can be used to if only 2 are required. The board provides 2 screw terminals for the ac supply and uses a 4-way Molex connector to connect it to other things:

  1. Input pin
  2. +12V
  3. +5V
  4. GND

I've designed the PCB to work with either a 5V supply or to connect using my 8-channel optical input board, which provides a 12V supply. There are therefore two spaces for pull-up resistors.

H11AA1 Build

Warning:  This project involves mains voltages and these can kill you. When connected to the mains power supply the PCB will be live and so it needs to be enclosed in a suitable case.

This board that I've designed and built is another of my smart home building blocks that can be used many times in my contextual smart home, for various different applications.

Software

Typically, these PCBs are used with Arduino processors to detect ac voltage being applied to a device, lamp, appliance, etc. The opto-isolator output is pulled up to the supply voltage when there is no power present and pulled to ground when power is applied.

Smart Home Integration

Over my many years doing smart home (I started in 2004), I have developed my own library of code for Arduino processors and this includes functions to integrate it into my distributed Home Control System and connect numerous types of sensors. These 'slave processors' can then do clever stuff like local control, self-monitoring of performance, local signal conditioning and rate limiting, send warnings and errors, or host some functions locally.

This maximises reuse across my many smart home projects, making it very quick and easy to develop and test new smart home capabilities. My smart home also employs the concepts of technology abstraction, meaning my smart home is also technology agnostic. This allows old technologies or broken sensors and devices to be swapped out with new ones, with minimal effort and zero reconfiguration.

Most of the Arduino processors installed in my smart home use an Ethernet IP network interface, to enable them to send and receive events with my Home Control System, using my unified communications protocol. Wired networks ensure very low latency and hence a great user experience, though occasionally I will use Wi-Fi.

Adding sensors and devices to my Home Control System is simply a matter of adding one line of JSON for each one, to the main configuration file. This defines the name, zone, object type and also the details of the slave processor it is hosted or controlled by. All the intelligence is within my Home Control System, which receives and sends encrypted events using my unified communications protocol. It sends events to update my smart home on things like the temperature, humidity, fan state, appliance and lighting state changes, occupancy, etc.

Examples

My Ender 3 Pro 3D printer is an example where my contextual smart home monitors it being switched on and off.

Summary

This little module is a handy way to detect when devices and appliances have been on and hence can be used to track usage and measure how long they have been on. Combined with my ac power monitor board, some useful things can be inferred, such as when an appliance or device has completed its function or task.