Hello,
Full disclosure: I have a computer science background. I have have some basic knowledge in electronics and limited knowledge in electric circuits (only what I can remember from 10 years ago )
I am trying to build a power meter using the following:
- Raspberry PI 3B+,
- YHDC SCT-013-000 (20A/1V)
- SEN0211 current sensor: https://www.digikey.co.uk/product-detail/en/dfrobot/SEN0211/1738-1194-ND/6588615
- ADC ADS1115
How does my setup look like?
- I connected the jack to the SEN0211 current sensor.
- I connected the VCC and GND of SEN0211 to 3.3V that’s coming from the raspberry.
- I connected the output of SEN0211 to pin A0 on ADS1115
- I connected the SCL & SDA pins from ADS1115 to the associated pin on the raspberry
- I connected ADS1115 to the same 3.3V
I am getting consistent raw values when sampling once every 8 ms
I am now trying to transform the raw values in amp readings. (I am in the UK so I will assume 50Hz freq)
I have tried applying the math suggested on the github repo of the SEN0211:Analog-AC-Current-Sensor/AC_Current.ino at master · DFRobot/Analog-AC-Current-Sensor · GitHub but I can’t make sense of the data. Probably the set of assumptions that their code contains doesn’t apply in my setup?
I started reading the docs from openenergy and in the example setup they are using some Current sensing electronics
.
Am I right in believing that the purpose of those components is exactly the same as what SEN0211 is doing?
The below readings show the raw values over time: At first it’s for 0amps; the next step is for 2.8 amps and the next step is for 4.015 amps
It’s worth mentioning that I am executing my code in node js and thus I can’t use EmonLib easily but I have converted the code from the Irms method into js. I suspect that the problem may lie around here.
const calc = (samples) => {
let ICAL = 111.1;
let ADC_COUNTS = 4096;
let SupplyVoltage = 3300;
let sumI = 0;
console.log(`start calc. Number of samples: ${samples.length}`);
for (let i = 0; i < samples.length; i++) {
let sampleI = samples[i];
let offsetI = ADC_COUNTS >> 1;
let filteredI = 0;
// Digital low pass filter extracts the 2.5 V or 1.65 V dc offset,
// then subtract this - signal is now centered on 0 counts.
offsetI = (offsetI + (sampleI - offsetI) / 1024);
filteredI = sampleI - offsetI;
// Root-mean-square method current
// 1) square current values
let sqI = filteredI * filteredI;
// 2) sum
sumI += sqI;
console.log(`sampleI: ${sampleI}; offsetI: ${offsetI}; filteredI: ${filteredI}; sqI: ${sqI}; sumI: ${sumI}`);
}
let I_RATIO = ICAL * ((SupplyVoltage / 1000.0) / (ADC_COUNTS));
let Irms = I_RATIO * Math.sqrt(sumI / samples.length);
console.log(`finish calc. Irms: ${Irms}; I_Ratio: ${I_RATIO};`)
return Irms * 230;
}
Here are some partial logs of what the above code is doing:
start calc. Number of samples: 125
sampleI: 47; offsetI: 2046.0458984375; filteredI: -1999.0458984375; sqI: 3996184.5040597916; sumI: 3996184.5040597916
sampleI: 46; offsetI: 2046.044921875; filteredI: -2000.044921875; sqI: 4000179.689517975; sumI: 7996364.193577766
sampleI: 47; offsetI: 2046.0458984375; filteredI: -1999.0458984375; sqI: 3996184.5040597916; sumI: 11992548.697637558
sampleI: 47; offsetI: 2046.0458984375; filteredI: -1999.0458984375; sqI: 3996184.5040597916; sumI: 15988733.20169735
sampleI: 47; offsetI: 2046.0458984375; filteredI: -1999.0458984375; sqI: 3996184.5040597916; sumI: 19984917.70575714
sampleI: 47; offsetI: 2046.0458984375; filteredI: -1999.0458984375; sqI: 3996184.5040597916; sumI: 23981102.209816933
sampleI: 50; offsetI: 2046.048828125; filteredI: -1996.048828125; sqI: 3984210.924259186; sumI: 496363245.5779867
sampleI: 46; offsetI: 2046.044921875; filteredI: -2000.044921875; sqI: 4000179.689517975; sumI: 500363425.2675047
finish calc. Irms: 179.0836027357205; I_Ratio: 0.08950927734374999