Current Sensor – A Quick Calibration Method

Modern Device >>

Our last post concerned the Current Sensor and how to calibrate it to measure the amount of power being drawn through an AC line. That process involved gathering data and plugging it into a spreadsheet program, validated the sensor and showed that the voltage output of the sensor was very proportional to the power draw in the wire it was sensing. It occurred to us that if the output is linear, then only two points are really required to define a straight line. Thus, it would be fairly easy to develop a quick (but perhaps a bit less accurate) calibration by entering only two data points total.

So we developed a second current sensor program, shown below. To make this one work, all you need is two appliances with different power draws, ideally one around 20 to 200 watts and the other closer to 1000 watts. Measure the voltage generated by the current sensor for those two loads individually then substitute your data points in for V1, P1, V2, and P2, and you are done. The sensor is calibrated. As long as it doesn’t get bumped on its line cord, it should maintain very faithful calibration.

The one caveat is that you should make sure that the sensor is not saturating (hitting its maximum) on your higher current draw, so make sure the output voltage is under 4.3 volts (if powered from 5 volts). The analogous value (highest voltage without saturation) when powering from 3.3 volts is 2.6 volts.

That’s it! The program takes care of finding the equation for you really quickly at the expense of only using two data points, which means less accuracy. But as I said earlier, that might just be enough for you. Enjoy!

  Reads a Modern Device Current Sensor on pin 0, converts it to voltage,
  calculates the power, and prints the result to the serial monitor.
  Attach the V_OUT pin of the Current Sensor to pin A0, and V_IN and GND
  to +5V and ground respectively.

  This example code is in the public domain.

//You'll have your own values for these constants

#define V1 0.577  // voltage of first data point
#define P1 225    // power of first data point
#define V2 2.91   // voltage of second data point
#define P2 1000   // power of second data point
float SLOPE;
float Y_AXIS_CROSS ;

void setup() {
  //Find SLOPE and Y_AXIS_CROSS for quick calibration
  SLOPE = (P2 - P1) / (V2 - V1);
  // initialize serial communication at 9600 bits per second:

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  //Calculates power from voltage
  float power = voltage * SLOPE + Y_AXIS_CROSS;
  // print out the value you calculated:

The post Current Sensor – A Quick Calibration Method appeared first on Modern Device.

Back to blog