WCS1800 Current Sensor Arduino Project
From Makers Local 256
Revision as of 13:04, 1 August 2019 by Enabrintain (Talk | contribs)
Creator: |
Contents
[hide]Overview
I'm hanging info on how to use the WCS1800 Current Sensor Module with an D1 Mini here.
Hall Sensors vs Current Transformers and commentary
Hall Sensors use a generated magnetic field to detect variances when conductive objects break the field lines. They can also be used to detect DC and AC current, where a Current Transformer can only be used to detect AC. (link) I decided to use this module instead of a Current Transformer (CT) because the D1 Mini only has one available analog pin, and I wanted to attach three sensors to a single module.
- Main Shop Lights
- Big Fan
- Office Air Conditioner (using the analog pin, as well as a digital pin)
More about the WCS1800 Hall Effect Base Linear Current Sensor
- The WCS1800 Module has a separate digital output pin that can be tuned to go LOW when a current threshold is detected, based on a trim pot on the board.
- This will give me simple "on/off" info for the two appliances that dont vary in their power use.
- Hall sensors require active power, the WCS1800 can use anything from 3V to 14V, and had an operating current of 3mA.
- The datasheet I found tells me that it returns 60mV/A detected for an AC range of RMS 25A at 5V input (DC range was 35A). Since I'm going to be driving it at the D1 Mini's 3v3, I need to confirm that, and expect it to be different.
- The graph showed values up to ±60A, but the curve started deviating from the simple linear after the above ranges were passed.
- It did include a graph showing a mapping of Vout for Vcc of 3v3:
- the curve was fit to the linear range of Vout = 0.0503*Ia + 1.6456, where Ia is the amperage being detected.
- This will not be as accurate past ~20A however, for example I'd guess that while the formula would give a result of 32A if the Vout is 3.3V, the sensor would actually likely to be reading a current 50A or greater.
- These values cycle at 60Hz, so it behooves us to sample our values at a high enough frequency to be able to find the peaks, and calculate the RMS of the current draw. There's a very good writeup about doing this in CT sensors (here). The logic for the WCS1800 will work in a similar way.
D1 Mini (ESP8266)
- I soldered wires for the Ground and 3V3 pins to power all the modules from a small piece of proto board. I'll be encasing it in Jeffweld for safety.
- The first WCS1800 module's AOUT and DOUT pins are attached to the D1 Mini's A0 and D0 pins respectively.
- The other two modules' DOUT pins will be soldered to the D1 Mini's D1 and D2 pins, but I haven't done it yet.
- I think the AC 60Hz cycle applies to digital outputs as well. This means some debouncing logic is necessary, even though we aren't reading voltages for current values.
- I'm not 100% sure about that claim, however tests showed that the D1 Mini D0 pin was rapidly switching from high to low.
=Arduino Sketch (pin reading, and MQTT publishing)
TO DO (right now its just flipping the BUILTIN_LED when it sees a signal on D0 and printing the value of A0)
Next Steps
- Look at the MQTT messages being sent from the light sensors to see the format that grafana wants
- bump up the serial baud rate so that the loop isn't as laggy there
- Verify the math for the analog signal makes sense
- Add code to find peaks
- Add code to debounce D0
- Add wifi connection, look for timestamp library, configure MQTT client
- Add doobler config
- Add Grafana graph