I just finished a new project, which is called Always-On. This project is a simple bidirectional bridge between the mains-voltage installation and an Adafruit Feather board as a controller.
The idea is to have a device integrated into the electric installation. It works as a smart light switch, monitors power lines or works as a timer for a device.
In this post, I describe a minimal version of the project I used as a prototype, which has one power sensor and one solid-state relay. It may be a good starting point if you plan to create a similar device.
In contrast to other projects, I will do only a superficial overview in this post. It is no project to be copied as shown. This post is meant as inspiration providing a working base to start.
Overview
Let’s have a look at the different sections and components of the device.

Mains-Voltage Side
The left side of the board is connected to mains power and the right side is the low power side with the controller. There is a large air gap between the two sides as extra protection.

There are three fuses (A) and two over-voltage protections (B) as an extra safety measure. A power module (C) IRM-03-5 from Mean Well converts mains-voltage to the required 5V DC for the controller part. The traces on the top and bottom side are covered with insulating silicone.
On the upper side is the solid-state relay (D) IXYS CPC1966YX6, which can switch a load up to 3A. On the lower side is the optocoupler (Lite-On LTV-8141) for sensing line power. I use two 100kΩ 3/4W resistors to reduce the voltage for the optocoupler to the required value.
Controller Side
The right side of the board is built around a socket for any Adafruit Feather board. The shown minimal version has 5V as main power supply, the Adafruit Feather provides the 3.3V power from this source.

I use an Adafruit Feather M0 Adalogger (A) in this example, any other Feather will work too. You can add boards with WiFi, Bluetooth or LoRa and use Feather Wings on top.
On the lower side is a small debounce circuit (B) for the optocoupler signal and on the upper side, two LEDs (C) for displaying the current state of the power sensing circuit and solid-state relay.
There is a footprint for a DS3132M RTC chip (E) and a super capacitor (D) as backup power. The footprint (F) is for an optional FRAM chip to store settings or logs.
Extension / Sensor Connector
The connector on the very right side of the board is for connecting sensors and extensions. It provides 5V and 3.3V power, connection to three microcontroller pins and a separate I2C bus.
Circuit Schema
The following schema is for the shown version of the device.

Specific part numbers are only noted if they are important and the result of calculations, otherwise, common components for resistors, capacitors and LEDs will do.
Testing
I designed the device to do tests without connection to mains-voltage. The mains-voltage part is disconnected and the controller side is powered using the USB connector on the Feather board.
Now just the controller side is powered and you can use the test button to simulate the power sensing via optocoupler and monitor the state of the solid-state relay using the LEDs.
This is a very safe way to develop a firmware for the controller, without all the risks of mains electricity connected.
For deployed devices, you simply remove the Feather board and work on the firmware with the test board, not connected to mains-voltage. After finalising the new firmware version, you put the feather back into the device.
Housing
Housing is very important. I designed the board to fit into an IP65 sealed case using two cable glands on both sides. There has to be enough space in the housing for free air circulation.
If you are unsure about the heat dissipation, just add a temperature sensor to your device and use it to monitor the temperature rise in some extreme situations. E.g. use a hairdryer to simulate a hot summer day. 😁
Conclusion
A controller as shown provides a permanent solution for home automation. With your custom firmware, you control lighting or other devices in complex ways, without WiFi, Bluetooth and smartphone required (aka. IoT).
If you have any questions, missed any information, or simply want to provide feedback, feel free to comment below. 😄
More Posts

New Version 2 of the Pattern Generator

Stronger 3D Printed Parts with Vertical Perimeter Linking

The 3D Printed Modular Lantern

The Hinges and its Secrets for Perfect PETG Print

Better Bridging with Slicer Guides

Cool, I was looking for a device that uses 5vdc solar and battery as normal power and when battery reaches low level it would switch to mains power as a backup
What is the air gap clearance distance? What tools are available to calculate this?
I did choose a large gap distance of 4mm, but the width of the gap is not that important. In most devices, you only find an air gap of 1-2mm. Because air is so much better at insulating than the PCB, even a small gap has a great effect. As soon you add such a gap, the distance between the high-voltage and low-voltage areas, on the PCB is increased, because the shortest path has to curve around the gap. It makes an unwanted connection between these parts more unlikely.
There are many online calculators, where you can calculate the PCB trace spacing for certain voltages, like this one: https://www.smps.us/pcbtracespacing.html. The shown calculator gives you the minimum distance according to the standard IPC-9592 (Requirements for Power Conversion Devices for the Computer and Telecommunications Industries). This is a good value for the distances on the high-voltage side and also a good starting point to get minimum distances for overvoltage situations. This is called “creepage“, which is the reason why one likes to add an air gap.
If you e.g. use a value of 250V (AC) you will get a value of 1.8mm distance between traces on the PCB. For an overvoltage situation, with e.g. 3000V you need at least ~15mm distance. This is the distance measured between the nearest high-voltage and low-voltage contacts connected by the PCB material.
These distances are small, compared with the insulation effect of air, which is approximate 1(worst)-3(avg)kV/mm (depends on the geometry of the electrodes and humidity). Therefore an air gap of 2mm between two electrodes already insulates 2kV. The shortest air path in my device is the legs below the optocoupler which are 8mm apart. It would need more than 8kV(worst case) to create a spark between these legs.
For my project, the nearest tracepoints are ~8mm apart, below the optocoupler. If they were just separated on the PCB, an overvoltage situation >~1.5kV, could allow a path to the low-voltage section. By adding the air gap, the path has to go around this gap, which increases the length to 17mm – into a safer zone (>=3.2kV).
I used 3000V for my calculations because this is the maximum insulation voltage for the parts I used (except the optocoupler which can handle 5000Vrms). So even if my air gap would increase the distances to be safe for 10kV – the used components would probably fail and pass some of the voltage to the low-voltage part.
For this reason, I also added additional overvoltage protection components (varistors), at the high-voltage inputs. If there are any peak voltages above 300V, the varistor will create a short and hopefully prevent the worst case.
Lightning strikes can easily create voltages over 10kV by induced transients into the mains installation. The outcome of such events is unpredictable. E.g. the voltage spike could come through a sensor cable of the low-voltage side.
For this reason, the physical insulation of all cables is very important for all devices like this. There should be no point in the whole setup, where a human gets into contact with any part. You should e.g. never use an exposed capacitive touch panel as input on the low-voltage side, because of the worst-case scenario.
I hope this answered your question. 😄