Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
rpi/exercises/01_arduino/power/ac_current.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
49 lines (38 sloc)
1.46 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const unsigned int numReadings = 200; //samples to calculate Vrms. | |
int readingsVClamp[numReadings]; // samples of the sensor SCT-013-000 | |
int readingsGND[numReadings]; // samples of the <span id="result_box" class="" lang="en"><span class="hps">virtual</span> <span class="hps alt-edited">ground</span></span> | |
float SumSqGND = 0; | |
float SumSqVClamp = 0; | |
float total = 0; | |
int PinVClamp = A0; // Sensor SCT-013-000 | |
int PinVirtGND = A1; // <span id="result_box" class="" lang="en"><span class="hps">Virtual</span> <span class="hps alt-edited">ground</span></span> | |
void setup() { | |
Serial.begin(9600); | |
// initialize all the readings to 0: | |
for (int thisReading = 0; thisReading < numReadings; thisReading++) { | |
readingsVClamp[thisReading] = 0; | |
readingsGND[thisReading] = 0; | |
} | |
} | |
void loop() { | |
unsigned int i=0; | |
SumSqGND = 0; | |
SumSqVClamp = 0; | |
total = 0; | |
for (unsigned int i=0; i<numReadings; i++) | |
{ | |
readingsVClamp[i] = analogRead(PinVClamp) - analogRead(PinVirtGND); | |
delay(1); // | |
} | |
//Calculate Vrms | |
for (unsigned int i=0; i<numReadings; i++) | |
{ | |
SumSqVClamp = SumSqVClamp + sq((float)readingsVClamp[i]); | |
} | |
total = sqrt(SumSqVClamp/numReadings); | |
total= (total*(float)2/3); // Rburden=3300 ohms, LBS= 0,004882 V (5/1024) | |
// Transformer of 2000 laps (SCT-013-000). | |
// 5*220*2000/(3300*1024)= 2/3 (aprox) | |
Serial.println(total); | |
delay(1500); | |
} |