Making a $15 Current Scanner for Azure IOT Hub

Recently I had a customer ask about monitoring large machines using Azure IoT.  While IoT can handle the data, the question is what devices do I use.  The price averages over $200 per monitored wire for devices like the emonPI, eGague and Sade.IO.

With Current Transformer (CT) Sensors ranging around $10 to $15, it seems like a great Arduino project.  With the inexpensive NodeMCU, based on the ESP8266, we can get this done for under $20 per unit.

Credits:

Parts needed:

  • NodeMCU
  • bread board or circuit board
  • CT Sensor YHDC SCT-013-000 (example is 30 Amps)
  • 1 @ 33 Ohm burden resistor
  • 2 @ 10k Ohm resistors (or any equal value resistor pair up to 470k Ohm)
  • 1 @ 10uF capacitor
  • usb cable

Building the circuit and wiring will match below.  Note there is only one ADC (analog to digital converter).

currentonly_nodemcu

My initial device looks like:

20170117_194104

And installed it looks like:

installed

Code:

Compile the Arduino code here: click here.  You will have to make changes in the following section:

const char* ssid      = "your SSID";
const char* password  = "your WifiPassword";
String deviceName     = "your iot device Name";        // Example: myDevice
String Key            = "your key";                    // Example: ErNBy4a6NQL/3lBfcd+UwuOcIwfDURlIaDkacWcYhWA=
String serverName     = "your Azure IoT Hub Name";     // Example: kevinsayIoT.azure-devices.net
String SASGenerator   = "your SAS generagor";          // URL to generate the SAS token.  Example: http://january2017.azurewebsites.net/api/generateSAS?deviceId=
float calibration    = 92.75;                         // default value for calibration
float calibrationchg = .025;                          // for each calibration cycle, how much to move the calibration
float calibrationmtc = .05;                           // how close the calibration should get in "calibrationCount" cycles
float minimumReading  = 2;                             // if less than 2 amps, we don't care.  sensors are not exact
float sketchVersion   = 1.0;                           // just a version of this sketch.   Used for when you OTA and to ensure the correct version is running
String configFileName = "/config.txt";                 // a config file that we store the calibrated value
int loopCounter       = 1;                             // a loop counter for sampling current
int samplesPerMsg     = 30;                            // how many samples before we send an IoT message there is a half second delay, so for a 1 minute sample set to 30
float ampAverage;                                      // used to hold the weighted average of the samples

Calibrate:

Based on many variables, the sensor and device need to be calibrated.  This is simple via the usb or by sending a message via the IoT Hub.  Anytime you make a major change (wire, source voltage, sensor), you will need to re calibrate the sensor.

Serial:

When the device is sensing a wire, use a standard tester to determine the amperage.

In the Arduino IDE, open the serial monitor and send the amperage from your meter.

calibrateserial

The code will loop until calibrated.  It is important that the amperage stay the same on the wire while calibrating.

Azure IoT Device Manager:

In Azure IoT Device Manager, send the message “Calibrate:7.33”, where 7.33 is your measured amperage.

dmcalibrate

Like serial above, as long as the amperage stays the same, the sensor will be calibrated.

Over the Air Updating (OTA):

From time to time you will need to update your code.  This is done using the Azure IoT Device Manager sending the message OTA: http://yoursite.com/yourfile.bin.

Note:  it must not be HTTPS and the device will download the code, reboot and run the code.

Leave a comment