# Calibrating the Modern Device Current Sensor

Modern Device sells a handy Current Sensor that can measure the amount of AC / alternating current flowing through a cord attached to it with the miniature zip ties we include with the sensors. While the sensor has an analog output and is extremely easy to use to check if an appliance is ON or OFF, we thought we would both validate the sensor and write a tutorial to allow users to put some hard numbers to the analog output. This would allow users to confirm the actual amount of power being drawn by a device.

A Brief Bit of Math
The chips on our sensor actually measure the amount of current flowing through the wire, which is why it’s called a Current Sensor (technically though they measure the magnetic field that is created by the current flowing in the wire, but the magnetic field is also proportional to current).

Luckily there’s an easy formula that equates power (P) to current (I) multiplied by voltage (V). Furthermore, we know that the voltage coming from the wall is constant (around 120 in the United States and 230 in the EU), which makes power proportional to current. In other words,

P = V * I, therefore P  is proportional to I (current) for constant V (voltage)

Perhaps to make things more confusing, the output of the sensor is itself a voltage, although it represents (is proportional to) the sampled current.

Got it? Good, moving on.

The Setup
A standard power strip is a convenient way to test and calibrate the Current Sensor. To start, make sure there are no active loads attached to the power strip (you might as well unplug everything from the power strip, just in case). To set up the test, attach the Current Sensor to the surge protector’s cord as shown above and tighten the zip ties snugly (the sensor should not be able to rotate around the cord unless you physically touch it). For our test, we also set the gain potentiometer on the sensor to its lowest possible setting (all the way counter-clockwise). Connect VIN and GND on the Current Sensor to +5V and GND respectively on an Arduino (we used one of our 3-wire cables as a connector). Finally, attach a voltmeter to the VOUT pin on the Current Sensor and another GND pin on your Arduino. Even though nothing’s plugged in, you should still see some small voltage. This is noise from the sensor, because the sensor is so highly amplified. This low voltage represents the noise floor or the zero current level of the sensor.

Arduino Leonardo, Multimeter, and a surge protector with loads

Now plug in a medium level load (anything between 100 and 400 watts will do) so you get an actual reading. If the voltage doesn’t increase, check your connections and power supply. If you rotate the sensor around the cord, you’ll notice that the voltage changes as the angle of the sensor on the cord changes. If you are more concerned with sensing small to medium loads – say 5 to 600 watts – you will probably wish to set the sensor angle to its most sensitive angle (highest voltage) so the sensor is more sensitive to smaller changes in current.

If you expect to be sensing large loads – we’re talking 600 to 1500 watts or higher – you may wish to use a sensor angle corresponding to a lower voltage so the sensor will not saturate (hit its maximum value – which is around 4.4 volts)  before you reach the maximum desired load to sense. In this case, you may wish to plug in your maximum load now, and rotate the sensor until you observe an output value somewhat below 4.4 volts.

Note the angle of the current sensor relative to the cord

Gathering Data
Once you have decided on a sensor angle, it’s time to collect data. You’ll need a few loads with known power ratings that span the range of power you expect to encounter. Look on the labels of the appliances your are using; in the United States, appliances are required to have their power draw printed on the label. For our test, we used the following loads (you don’t really need this many):

Lamp 18
Lamp 43
Lamp 100
Heat Lamp 125

Our motley crew of loads, three lamps (different bulbs), heat lamp, and the radiator we used to calibrate our current sensor.

Start gathering data by recording the voltage level with no loads at all. Then, record the voltage when each individual load is turned ON by itself. If you want more data, try measuring the voltage when different combinations of loads are turned on (the power ratings simply add together). We took a variety of measurements to prove our point in this tutorial; you should only need 5 or 10 total. That said, the more data you collect, the more accurate your calibration will be. There is an assumption in this that the nameplate ratings of the loads that you test are also fairly accurate.

Be careful NOT to move the current sensor during this step or your measurements will be off.

Finding the Formula
The next step is to enter the data into a spreadsheet program as shown below. We used LibreOffice, which is open source and free, feel free to use Excel, if you own the program and like it better.

A portion of the data we gathered while calibrating our current sensor

Now create a Scatter chart from your data. If you don’t know how to do this, search Google for the instructions; it’s only a couple of mouse clicks. Right click on the data points in the chart (make sure they’re all selected; not just one) and select “Insert Trend Line…” on the drop down menu. A dialog box like the one below will pop up, and under “Type” you should select “Linear” (the exact process might be a bit different for different programs). You should also check the boxes next to “Show equation” and “Show coefficient of determination (R2)”. The R2 value is a statistical measurement of how close an approximation comes to matching the data its approximating. For our purposes, the closer it is to 1, the better the trend line fits the data.

After clicking “OK”, your chart should look something like the one below but without the axis labels (added for clarity). As you can see, our trend line has an R2 value of 0.998, which tells us that the output of the sensor is definitely linearly proportional to the current, and by extension, power.

A graph showing the relationship between voltage and power draw for our current sensor

As cool as the chart is, what you’re really after is that formula, which describes how to take an input voltage and translate it into a measurement of power.

Creating the Arduino Sketch
Now that you have your equation, it’s time to put it to use. Luckily, there’s an example sketch called ReadAnalogValue (it’s under File -> Examples -> 01.Basics) that requires only minor modifications to work for the Current Sensor. The original sketch is as follows:

All we need to do now is enter the formula that will convert the voltage variable into a power variable!

Remember to change the variable name in that last line, otherwise your beautiful formula won’t actually report anything.

Congratulations! Your Current Sensor is now calibrated to measure power draw!

One last thing: now that your calibration is complete and seems to work for the power draws that you expect to see, you might want to lock the sensor to the cord with a spot of hot glue to keep it from rotating and changing your calibration.

Saturation Warning
If you wrote down the saturation voltage when you were testing, you may wish to add code to warn the user if the sensor is saturated (hit its maximum output), so the power draw is probably not proportional to the output voltage any more. Due to the topology of the sensor’s schematic, the sensor’s saturation point (max output) will be about a .6 volts (“a diode drop”) below the supply voltage. If you are using a 5 volt supply, inserting the line below should do the trick.

The sensor is in the shop here: https://moderndevice.com/product/current-sensor/
Happy sensing and let us know if there is anything in the tutorial that needs to be clarified.