Automatic Load Switch with ACS712 and Arduino

This switch turns on a vacuum when it detects a tool running.
Mar 21, 2020 — 7 mins read — Arduino

Automatic Load Switch with ACS712 and Arduino

Running a power tool in a closed space is a hustle, because of all of the dust created in the air and dust in the air, means dust in your lungs. Running your shop vac can eliminate some of that risk but turning it on and off every time you use a tool is a pain.

To alleviate this pain, I’ve built this automatic switch that houses an Arduino with a current sensor to sense when a power tool is running and turn on the vacuum cleaner automatically. Five seconds after the tool stops, the vacuum stops as well.

ACS712 - 20A current sensor

ACS712 - 20A current sensor

The star of the project is this ACS712 current sensor that works on the Hall effect principle. The current that flows through the chip generates a magnetic field that a hall effect sensor then reads and outputs a voltage that is proportional to the current that flows through it. 

When no current flows, the output voltage is at half of the input voltage and since it measures AC current as well as DC when the current flows in one direction, the voltage gets higher while when the current changes direction, the voltage gets lower. 

Plotting AC current with the Arduino

Plotting AC current with the Arduino

If we connect the sensor to an Arduino and plot the output of the sensor we can follow this behavior when measuring the current that flows through a light bulb. 

If we take a closer look at the values plotted on the screen we can notice that the sensor is really sensitive to noise so even though it gives quite good readings, it can’t be used in situations where precision is required. 

In our case, we need just general information if a significant current is flowing or not so we are not affected by the noise it picks up. 

The switch that we are building will sense AC appliances so we need to measure AC current. If we are to simply measure the current value of the current flowing, we can measure at any given point in time and that might give us a wrong indication. For example, if we measure at the peak of the sine wave, we will register high current flow and then we will turn on the vacuum. However, if we measure at the zero-crossing point, we won’t register any current and mistakenly assume that the tool is not on. 

To mitigate this issue, we need to measure the values multiple times during a certain period of time and identify the highest and lowest values for the current. We can then calculate the difference in between and with the help of the formula below, calculate the true RMS value for the current. 

The true RMS value is the equivalent DC current that should flow in the same circuit to provide the same power output. 

To start measuring with the sensor, we need to break one of the connections to the load and place the two terminals of the ACS712 sensor in series with the load. The sensor is then powered from 5V from the Arduino and its output pin is connected to an analog input on the Uno. 

For the control of the shop vac, we need a relay to control the output plug. You can either use a solid-state relay or a mechanical one as I’m using, but make sure that it is rated for the power of your shop vac. I did not have a single channel relay at the moment so I will use this 2 channel relay module for now and replace it later. 

The output plug for the shop vac will be connected through the relay and its normally opened contact. Once the relay is ON, the circuit will be closed and the shop vac will be turned on automatically. 

The relay is controlled through pin 7 on the Arduino at the moment so whenever we detect that a current is flowing through the sensor we can pull that pin low and that will turn on the vacuum. 

The finished prototype circuit of the load switch

The finished prototype circuit of the load switch

A really nice feature that I’ve also added to the code of the project is a slight delay to keep the vacuum running for 5 seconds more after the tool is stopped. This will really help with any residual dust that is created while the tool stops completely. 

To achieve that in the code, I use two variables where I first get the current millies time when the switch is turned on and I then update that value on each iteration of the code while the tool is on. 

When the tool turns off, we now get the current millies value once again and then we check if the difference between those two is greater than our specified interval. If that is true, then we turn off the relay and we update the previous value with the current one. 

The main measurement function in the code is called measure and in it, we first assume the minimum and maximum values for the peaks but in order for them to be definitely changed we assume inverted values where 0 is the high peak and 1024 is the low peak. 

Over the course of the entire interval period defined by the iterations variable, we read the value of the input signal and we update the actual minimum and maximum values for the peaks. 

In the end, we calculate the difference and this value is then used with the RMS formula from before. This formula can be simplified by simply multiplying the peak difference with 0.3536 to get the RMS value. 

Each of the versions of the sensor for different amperage has different sensibility so this value needs to again be multiplied with a coefficient that is calculated out of the amperage rating of the sensor. 

The full code is available on my GitHub page

At this point, the electronics and code part of the project is basically done but they are not very practical yet. The Arduino Uno is great for prototyping like this but practically it is really bulky so we will need a larger enclosure. 

I wanted to fit all of the electronics in this plastic fitting that has some nice caps for the ends and in order to do that, I’ll need to minify the electronics. At the end I had to resort to using a larger enclosure for now but once I get the smaller relay board I’ll switch them. 

The Arduino Uno will be replaced with an Attiny85 chip that can be programmed with the Uno. The process is straightforward and I’ll try to provide a separate tutorial for it. 

To remove the need for external power, I’ll use this HLK-PM01 module that converts AC to 5V and has a really small footprint. All of the electronics will be placed on a double-sided prototype PCB and connected up with wires.

The final schematic is available on EasyEDA

The final board is definitely not my best work so far as it turned out a bit messier than I wanted. I’m sure that if I spend some more time on it it will be nicer but the main thing is that it worked and it is substantially smaller than what it was with the Uno. 

To pack it all up, I first installed some cables to the input and output plugs that are about 20cm in length. As an enclosure, I gave up on the fitting as it was too small in the end but I managed to fit everything inside a junction box.

The input cable is then fed through the hole and connected on the input terminal on the board and the same is done on the other side where the two cables are now connected. The one output is for the shop vac and the other for the tool. 

With everything connected, I made sure to test the switch before putting everything in the enclosure and closing it all with the cover. The fitting would have been a nicer enclosure as it will protect the electronics from any liquids or dust that might end up on them in my workshop so once I have the new relay board I’ll move everything there. 

To use this automated switch, you first need to connect the input plug to a wall outlet or an extension cable as in my case and then the tool and the shop vac are connected in their appropriate plugs. 

When the tool is started, the vacuum is turned on automatically and will then continue to run for another 5 seconds before it automatically turns off. 

I hope that you managed to learn something out of this video so please hit that like button if you do like it. I have many other projects that you can check out and don’t forget to subscribe so you don’t miss out on my next videos. 

Cheers and thanks for reading! 

For making of this switch I used the following components and materials:

workshop acs712 attiny tools tutorial
Read next

Exploding hot glue gun

The other day, my wife was making some Easter decorations for the house and as usual, she had her hot glue gun turned on. The gun was...

You might also enojy this

Android TV Box power supply repair

I was given this Android TV Box to repair it and the complaint was that it won’t turn on. As an additional symptom, I was told that sev...