For this project, I'm using an ACS712 module, which features a hall effect sensor.
There are several variants of this sensor (5A, 10A, 20A, 30A) and to get the best accuracy, you need to pick the lowest value one for your intended application. For this project my plan is to measure my 3D printer's usage and my toaster's usage, so my contextual smart home will now when both are in use. I've chosen the 5A version for the 3D pinter and the 20A version for my toaster which uses about 1100W (with 2 slots in use) or 2200W (with 4 slots in use).
The ACS712 module is a hall effect sensor that uses "the production of a voltage difference (the Hall voltage) across an electrical conductor, transverse to an electric current in the conductor and to an applied magnetic field perpendicular to the current".
This simply means that it outputs an ac voltage proportional to the current seen by the sensor and we can measure this voltage using an analogue input pin on an Arduino micro processor.
The UK mains power is an alternating current supply with a sinusoidal voltage. Knowing this, it is possible to calculate the root mean square current flow. If the voltage shape was changed in any way, for example by using a lighting dimmer, it would no longer be sinusoidal and the current measurements would be inaccurate. We would then need to calculate the true RMS current, which is more complex and requires a library of code to achieve.
The ACS712 needs to be placed in series with the appliance in order for the current flow to be sensed. The circuit is therefore quite simple.
To enable this circuit to be built without cutting into any wiring, I've simply used a mains socket connected to a mains plug with the sensor in line. This can then simply be placed between the appliance and a power socket. The reference meter is not connected here but will be for setup and testing.
The code samples the voltage coming from the ACS712 and measures the peak values (highest and lowest) seen. I must take enough samples to see more than a complete ac cycle or I will not see the lowest and highest peak values. Since the UK mains voltage is at 50Hz, this means I must sample over at least 0.02 seconds or 20mS. I started with 300 samples and this took about 36mS.
From this peak-to-peak voltage I then calculate the RMS current but, this needs to be calibrated against a multimeter to get accurate readings. This is achieved by using a calibration factor multiplier.
I'm not going to go into the specifics of my own smart home code and interfacing here because it is specific to my smart home. In simple terms, the Arduino is sending an encrypted event to my Home Control System using my unified communications protocol and it looks something like this:
{"type":"Appliance","zone":"Kitchen","object":"Ender 3 Pro","value":"On","usage":"110.7"}
Testing with a 500W photographic light bulb enabled me to calibrate the 5A version of the ACS712. The calibration factor worked out at 0.273 and this meant the measured bulb current was 2.1A as measured by my multimeter and the ACS712.
With no supply or load the ACS712 measured less than 0.1A or less. With a 3W LED bulb connected the sensor reported 0.1A when the meter was saying 0.03A. It is clearly less accurate at lower current levels but it does show that we can reliably detect the presence of these lower power loads.
With the Ender 3 Pro 3D printer connected current usage measured was just 0.1A when on. With the nozzle and bed heaters on this varied between 2.6A and 3.6A. Whilst printing the current measured was around 0.6A.
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.
There is little use in reporting ac current to more than one decimal place as the accuracy of these devices is less than this.
The responsiveness of the current usage is obviously going to depend on how often the ACS712 is used to collect a set of samples. Typically it makes sense to do this about every 5 seconds but depending on the specific application, it could be longer.
When combined with voltage presence detection, it would be possible to pause the current usage sensing when no power is being supplied to the appliance. I have another project to do ac voltage detection.
I have also developed an AC current trasnsformer sensor, which allows my smart home to track energy generation and usage.