Automatic Load (Vacuum) Switch With ACS712 and Arduino

by taste_the_code in Circuits > Arduino

7622 Views, 24 Favorites, 0 Comments

Automatic Load (Vacuum) Switch With ACS712 and Arduino

Automatic Vacuum Switch with ACS712 and Arduino (Attiny 85)
IMG_20200318_223349.jpg
IMG_20200319_073051.jpg

Hi Everyone,

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.

Supplies

Sensing the Current With ACS712

MOV_0093.00_01_03_24.Still003.jpg
MOV_0093.00_01_05_28.Still002.jpg
MOV_0093.00_01_14_10.Still004.jpg
MOV_0093.00_01_33_23.Still005.jpg
MOV_0093.00_03_08_22.Still011.jpg
MOV_0093.00_01_58_21.Still008.jpg
MOV_0093.00_01_35_28.Still006.jpg
MOV_0093.00_01_43_25.Still007.jpg

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.

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.

Proper Measuring of AC Current

MOV_0093.00_03_02_29.Still010.jpg
rms-voltage-calculation-and-formulas.png

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 in the images, 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.

Build a Prototype Circuit

MOV_0093.00_03_13_16.Still012.jpg
MOV_0093.00_03_21_09.Still013.jpg
MOV_0093.00_04_05_13.Still014.jpg

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.

Code Explanation and Features

MOV_0093.00_04_30_25.Still015.jpg
MOV_0093.00_05_14_15.Still016.jpg

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 and the download link is below
https://github.com/bkolicoski/automated-vacuum-swi...

Minify the Electronics (optional)

MOV_0093.00_06_12_01.Still022.jpg
MOV_0093.00_06_19_07.Still023.jpg
MOV_0093.00_06_31_00.Still024.jpg
MOV_0093.00_06_01_08.Still020.jpg
MOV_0093.00_05_44_28.Still017.jpg
MOV_0093.00_05_50_07.Still018.jpg
MOV_0093.00_06_36_08.Still025.jpg
MOV_0093.00_06_41_16.Still026.jpg
MOV_0093.00_06_50_12.Still027.jpg

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. In 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 and the link to it can be found below.
https://easyeda.com/bkolicoski/Automated-Vacuum-Sw...

Pack the Electronics in a Case

MOV_0093.00_06_58_17.Still028.jpg
MOV_0093.00_07_05_09.Still029.jpg
MOV_0079.MP4.00_05_08_12.Still001.jpg
MOV_0079.MP4.00_12_57_16.Still002.jpg
MOV_0085.MP4.00_01_42_17.Still001.jpg
MOV_0085.MP4.00_06_07_17.Still002.jpg
MOV_0093.00_00_53_07.Still001.jpg
MOV_0085.MP4.00_15_45_22.Still003.jpg
MOV_0085.MP4.00_16_21_13.Still004.jpg
MOV_0093.00_08_43_11.Still033.jpg

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.

Enjoy Using It!

Automatic Vacuum Switch with ACS712 and Arduino (Attiny 85)
MOV_0093.00_02_07_17.Still009.jpg
MOV_0093.00_06_06_16.Still021.jpg
MOV_0093.00_08_08_04.Still030.jpg
MOV_0093.00_08_31_04.Still031.jpg
MOV_0093.00_08_35_06.Still032.jpg
MOV_0093.00_08_52_14.Still034.jpg

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 Instructable so please hit that favorite button if you do like it. I have many other projects that you can check out and don’t forget to subscribe to my YouTube channel so you don’t miss out on my next videos.

Cheers and thanks for reading!