I have lost count of the times I have forget to turn on the workshop vacuum cleaner before turning on dust making wood working equipment. Recently I decided that I needed to compensate for my distraction with an automatic Smart Switch. However, all the switches find either did not do what I wanted or were way beyond my budget. So I decided to make my own.
The relatively straightforward function of the device is to detect a current on the primary outlet and manage switching the 240vAC secondary to follow the on/off status of the primary.
As I was making my own, I also wanted some level of intelligence to be built-in to give me:
- A delay between the start of primary and the start of secondary circuits. As the main application is switching motors on and off, this avoids overwhelming the household wiring with transients from both devices starting simultaneously.
- A delay between when primary and the secondary turn off. In this application, dust collection, this ‘run-on’ allows the surrounding air and vacuum cleaner tubes to be cleared of residual dust.
- An override function to turn on the secondary outlet independently of the primary. Sometimes I want to run the vacuum cleaner without the primary device working!
To implement the smarts for the system, I use an Arduino Mini Pro. The core function for the Mini Pro is to detect an AC current. There are 2 major ways I found to do this:
- Using a sensor like the the readily available and inexpensive ACS712, which I discussed in this past blog.
- Using a Current Transformer (CT). Interfacing a CT to an Arduino is well described at the OpenEnergyMonitor web site.
The ACS712 seems like a good solution for DC and AC applications, but I was left a bit uncertain about how it would perform with high AC currents flowing through the PCB traces, as under load power tools can use up to to 10A at 240VAC. The traces just looked too flimsy for comfort.
I therefore settled on using a CT together with a small burden circuit described at the OpenEnergyMonitor site. The CT used is commonly available on eBay. Its specification is 20A/10mA – 10mA is induced in the CT for 20A measured current, or 2000/1 – and it is tolerant of up to 120A measured. As I expect to measure around 10A, these parameters work.
I was also intending the device to be on the floor, so I needed to build a robust box to house it and the override switch needed ‘ste-on’ rugged. In the end I opted for a guitar ‘stomp’ switch which is designed for this type of application (being stomped on, that is!). Mine was sourced from Tayda Electronics.
The Arduino Mini Pro needs a 5V power supply to work. This needs to be a robust design as it is working near the source of high voltage spikes created by the workshop equipment. During testing, I managed to quickly blow up a couple of lesser models before finding that this one from ICStation seems to fit the bill (so far, so good …).
The secondary is switch using a Solid State Relay (SSR) specifically designed for switching AC voltages off a digital signal. This type of SSR is commonly available on eBay. The SSR rating needs to match the current to be switched. In this case my device can handle 25A at 250VAC, giving me plenty of headroom.
NOTE: Assembly require wiring mains AC circuits. Please ensure you have the appropriate knowledge and implement appropriate safety precautions.
The hardware was assembled in a home-made wooden box. The system block diagram for the Smart Switch is shown in the figure below.
The AC input active line goes in two directions. One side passes through the CT and goes to the active pin of the Primary AC outlet. The other side is switched through the SSR to the active pin of the Secondary AC outlet. The neutral and earth lines are passed through and paralleled between the Primary and Secondary outlets.
A couple of practical considerations also come into play:
- The DC ground is connected to the AC earth. I have read arguments for and against this practice, but I think in this application the system is more reliable with the ground/earth connection.
- A line filtering capacitor is attached to the AC input (this is optional but recommended). As noted earlier, switching motors on and off causes large voltage spikes and the line filter attenuates voltage peaks. These types of capacitors are specially rated for this application (see this capacitor guide). My capacitor was sourced from a broken electric drill I dismantled.
The assembled Smart Switch is shown below (click to enlarge).
The software for this application is relatively straightforward and can be found on my code repository site. The code is implemented as a Finite State Machine (FSM) and the state transition diagram is shown below.
The INIT state is used to reset the status LEDs before moving to the IDLE state.
IDLE waits to detect a current passing through the primary circuit, using the CT. The current just needs to be above a configured minimum threshold for the detection state to be triggered. As soon as this happens, it enters the START_DELAY state. This implements a simple non-blocking delay for the configured number of milliseconds.
Once the start delay expires, the secondary circuit is turned on and SETTLE state started. This is a short delay to allow the voltages and currents to settle before we read the CT again, as I found in practice that sometimes the fluctuations were affecting the reading from the CT.
From SETTLE the code moves to RUN. This is similar to IDLE, except the code is waiting for the primary to turn off. Once this happens, STOP_DELAY is triggered, working similarly to START_DELAY.
At the expiry of the stop delay, the secondary is turned off and the code moves back to the INIT state.
As its name implies, the override switch can be pressed at any time. As soon as that switch is detected, the code enters the OVERRIDE state. In this state it just waits for the override switch to be pressed again. If this happens while the primary circuit is on, the code transitions to RUN state. On the other hand, if the the primary is off, the code transitions to INIT state.
I initially thought it was overkill to implement this simple type of device with a micro controller. It has proved to be very cost effective and it provides me with the flexibility to implement additional functionality (for example, an adjustable delay time using a potentiometer) in future versions of this Smart Switch.