Tuesday 14 March 2017

Measuring Power Using a Current Clamp

This post shows hot to use a current clamp to measure current and power using an op-amp based rectifier, and A to D and the Raspberry Pi. This is an extract from the e-book on Interfacing the Raspberry Pi to Analogue Signals.

When working with analogue signals sometimes there is a requirement to measure AC voltages. Up to now we have only dealt with DC voltages that vary dependent on the input but do not vary in time. AC signals vary all the time and normally have a frequency (or a number of frequencies) associated with them.

For example, mains voltage varies at 50 Hz which means that it varies 50 times a second. Musical tones vary at hundreds of Hz a siren at thousands of Hz.

The process of turning an AC signal to a DC signal is known as rectification. For large signals this can be done with diodes as shown below.


The circuit below shows a simple rectifier circuit. The diode allows current to flow one way but not the other. The capacitor charges up to the peak value of the signal coming in.



While the circuit here works well for large signals of a few Volts, it can present problems when measuring small signals of less than 1 V. The diode will not conduct until the input voltage is more than about 0.5V so this will cause inaccuracies.

The way to overcome this is to use an Op-amp as shown in the circuit below. This will overcome the problem with using a diode on its own.


When dealing with small AC signals, it might be necessary to introduce some amplification before rectification. The circuit below shows how this can be done. The amplification is set by the ratio of R1 to R2 and here it is x 10.


The circuit here can be used to measure the output from a current clamp to work out power consumption of an appliance. It can also be used to measure the power consumed in a home if clamped to the main cable going to the distribution board.

A range of split-core current clamp that can be used for this is shown below. They come in different current ranges and output 0.33V hen the maximum rated current is flowing through the cable that it is clamped around.



When measuring the current flowing into an appliance it is important to clamp around the Live or Neutral wire. It may be necessary to make a special extension lead as shown here. Please take care to insulate the wires.



The current clamp can also be used to measure all the power being consumed in a building. To do this one has to first locate the main power cable and fuse coming into the building. The photo below shows a current clamp in place. Please take care when doing – if in doubt get help from a competent person.




As the maximum output from the clamp is 0.33V and the range of the ADC is 3.3V we need an amplification of around 10. The output from the clamp is an AC voltage at 50 Hz and we need to rectify this signal to a DC before we measure it using the circuit described earlier.

When we measure the voltage and work out the current, first we just have to remember to divide by 10 in the software to allow for the x10 gain of the circuit. Then we have to divide by 1.414 to convert the rectifies peak value to an Root Mean Square (RMS) value which represents the true ‘average’ value of the current.

The Python code for working out the current and power is presented below. Here we assume that the voltage is 240V and multiply the current by this figure to get the power.

#!/usr/bin/env python
# Python code for Measuring Current and Power using Clamp
# www.sf-innovations.co.uk

import time
import smbus
import math

#********************************************
#I2C addresses
add= 0x4F
bus=smbus.SMBus(1)

#DtoA channel select
ch0= 0x00
ch1= 0x01
ch2= 0x02
ch3= 0x03

def readanalog(add):
 #   bus.write_byte_data(add,ch0,0x00)
    analog=bus.read_byte(add)
    return analog
   
def writedtoa(add,value):
    bus.write_byte_data (add, 0x44, value)
#******************************************

while True:

    writedtoa(add,0)
    an0= readanalog(add)
    an0 = readanalog(add)
    print "channel 0 raw AtoD = ", an0
    V = 3.3 * an0 / 256
    V = round (V, 3)
    print "channel 0 Voltage = ", (V)
    Curr = 80 * V/(0.33)
    Curr = Curr / 10            #adjust for opamp gain of 10
    Curr = Curr / 1.414         #work out RMS from peak value
    Curr = round (Curr , 1)
    print "Curr (I) = ", Curr
    Power = Curr * 240 /1000
    Power = round (Power, 1)
    print "Power (kW) = ", Power
    print "*****"
    time.sleep(2)


When executed, this program measures the power taken by the appliance (or the building) every 2 seconds. A useful development of this program is to monitor this integrate this over time and work out the energy consumed. The unit for this is kWhr. This will allow one to estimate the cost of the electricity consumed as the rate for this is quoted in pence per kWhr.

Note: Multiplying the measured current by the assumed voltage only gives an approximation of the power consumed. IN practice, the voltage and current can be out of phase and one will need to measure this to get a really accurate value.

No comments:

Post a Comment