# Setting reading frequency SCT013 current sensor code using Arduino Uno

I found this code below for the Arduino platform to obtain current measurements from the SCT013 sensor, and I am wondering how can I define the 'delay' or 'frequency' of my readings? I'd be looking for 200Hz.

Code:

``````//
#include "EmonLib.h"                   // Include Emon Library
EnergyMonitor emon1;                   // Create an instance

void setup()
{
Serial.begin(9600);

emon1.current(5, 60);             // Current: input pin, calibration.
//calibration is explained bellow
}

void loop()
{
double Irms = emon1.calcIrms(1480);  // Calculate Irms only

Serial.print(Irms*230.0);        // Apparent power
Serial.print(" ");
Serial.println(Irms);            // Irms
}
//
``````
• That is a very strange question to ask. What do you want to achieve ? Have you heard about the XY-problem ? xyproblem.info If I remember it correctly, the EmonLib samples at a higher frequency and returns the average. Why do you want 200 samples per second from a 50Hz or 60Hz signal ? – Jot Oct 6 '17 at 11:46
• You already asked the question with a current sensor: arduino.stackexchange.com/questions/45293/… – Jot Oct 6 '17 at 11:51

you skip reading when the last read is less than 1000/200 = 5ms ago.

``````unsigned long lastRead;

void loop()
{
unsigned long currentMillis = millis();

double Irms = emon1.calcIrms(1480);  // Calculate Irms only

Serial.print(Irms*230.0);        // Apparent power
Serial.print(" ");
Serial.println(Irms);            // Irms
}

}
``````

If you want a 200Hz sample rate this code doesn't work for you.

With this line: `double Irms = emon1.calcIrms(1480);` you take 1480 samples as fast as Arduino can.

If you want 200Hz sample rate, read analog ping every 5ms using millis() function. And when you have enough samples you can calculate the rms current https://en.wikipedia.org/wiki/Root_mean_square

This is an example code:

``````unsigned int sample_time = 0;
int i = 0;

setup() {
}

loop() {
if (millis() - sample_time > 5){