Arduino House current limit system (SCT-013-030)

Too much current detector, absorbed from the house, made with Arduino and SCT013-020 (or SCT-013-030)

This page describes a hardware (Arduino board + SCT-013-030 sensor)  and software system capable of detecting the current flowing in a wire in order to determine whether, at home, we have too many powered-on electrical equipmentes and then run the risk of detachment of the electricity meter.

The purpose of the program is to provide a value contained in a variable, to be used to turn on a relay, or emit sound signals, when high power consumption electrical loads are switched on simultaneous, such as oven, hair dryer, washing machines, dishwashers whose absorption is around 2000W.

This value is useful in order to avoid the detachment of the electric meter for too much power consumption.

It is very economical because it only uses a non-invasive sensor from a few Euros (013-020 SCT or SCT 013-020) to detect the current flow on the main line power supply. However, given that the counter decides when to turn off the power based on the actual power consumption, while the program is based only on the current, it becomes necessary to point out that there are conditions (infrequent) in which this system is unable to fulfill its task. However, for a limited number of electrical apparatuses, such as those that normally can be found in the home, it is revealed working and reliable.

This is because its operation depends on how many devices or inductive switching type (light bulbs, electronic notebook, PC, TV ..) you have. These apparatuses put out of phase voltage and current of a certain angle and more extensive is the angle and more increases the error of this system. More than the angle is directly used the term cos (angle). On the instruction booklets of the equipment you can find itwiththe term cosphi, cos (phi) or “power factor”. Fordevices that do not slip through the current (resistance) the cosphi is 1; the maximum. In the worst equipment, including some electronic energy-saving light bulbs, such cosphi can drop to very low values.

To understand we use the figure on the right we represent an extreme case:

The two vectors (red arrows) represent the apparent power and are identical in length. But their orientation produces two different projections along the x axis (real power). The electricity meter is triggered when this projection exceeds a certain value (forexample 3000 Watt). So it is easy to see graphically that the counter is triggered onlyforthe lower vector.Proiezione della Potenza Apparente

The defect of the system is just that. It is only sensitive to the length of the vector (3300VA) and therefore does not know whether the electricity meter is going to detach the current because it has no way to calculate the projection of the vector along the x axis.

However, the illustrated case is an extreme case.

In domestic dwellings most of the large electrical loads, are resistors that do not slip through the current and therefore their vector is along the x axis (in the figure below the carrier green  is 2000W). The other switching loads or inductive, added together are represented by the blue vector (in the figure below on the left 1200VA at 45 °). Alreadywiththis situation, the difference between the apparent power and real power 2972VA 2848W and a little less than 150W.

The case in the right part is different. It is assumed that the switching loads are 1880VA at 62 °. In this situation the error is greater. Although in both cases, the projection of the vector along the x axis is approximately equal to about 2845 watts, which means that being under 3kW to the counter does not detach the power line, the program detects the values of apparent power (blue vectors) very different 2972 against 3258. An error so large that seems to frustrate this program.

Instead, the purpose of the program is not to obtain an accurate measurement of the power, but rather to determine when two appliances 2000W are lit together. To this end it is useful to the consideration that, normally, turn on together a 2000W appliance and all other loads minors (bulbs televisions etc..), does not trigger the counter. While two appliances 2000W together, instead trigger the counter. Thus is possible to choose a suitable thresholdforproceeding to operate the program as follows:

Connect an Arduino as in the diagram (below) and load the program. Detected the smallest value that the program provides to the ignition of different combinations of two of these appliances from about 2000W to time. (Please note that ignite them togetherfora few seconds, otherwise the counter can take. Loads, 2000W is intendent on bigger loads available in the home, from the smallest iron 1200W and above). This value, we call MAX (as indicated in the figures above).

Switch now these appliances one at a time and determine what will be the greater. Once found, leave it on and ignore all other applianceswithhigh power consumption. Continue to turn everything connected to the electrical system (lights, televisions, lights, notebook PCs) … and note down its value when finished. This value we call MIN.

If MAX and is greater than MIN, the system will work and the discrimination threshold of the program must be set to an intermediate value between the two values.

From the tests carried out in a home is the result that the program has given me the value 125 (MAX) in front of the absorption produced by the oven and dryer. Oven and turning on all the lights and switching equipment, I got 100 (MIN). To consider that I turned everything I have, all my TV, 28 energy saving light bulbs and even resurrected the old obsolete PCs. In theory, without the 2000W load, I have reached 950W. A situation that would not normally overtake ever. So choosing 110 as the threshold value, i am sure to kindle overcome only when two appliances together 2000W.

Instead, if the MAX is less than MIN the system described here is not suitableforyour home. It is possible that you have a lot of energy-saving lamps, notebook computers and many, many televisions and / or induction plates. If all this is spread over a huge house, the solutions to not have false alarms can be the following: 1) the power factor of the system, 2) accept false signals (If you have a huge house, will be difficult to turn on all the lights at the same time). Alternative solution could be to divide the electrical system in areas served by multiple sensors like this and then manage via software. But it would not make sense because the cost to do so no longer justifies the adoption of this small solution.


Here are some feature of the program.

The program reads the voltage detected by theSCT-013-030 sensor’s via analog pin of Arduino. From some observations I noticed that the real representation of this wave detected by the sensor is litteredwithspikes (values that appear as spurious wave peak amplitude and random position). To contain them, the program does not directly consider the wave, but its mediation to 5 values. (In the following picture, a real wavewithspike and in red his mediation to 5 values).

Onda rilevata dal sensore SCT-013-020 con spike e in rosso la sua mediazione a 5 valoririco

Calculation of the reference value at zerovolts
Upon power up, theArduinoreads some sinusoidal cycles to identify the value that the analog input of the Arduino detects on the zerovoltsine wave. From these readings determines the peak maximum and minimum wave which averaged together provide the average value taken as 0volts. I preferred to calculate each time the zerovoltsbecause the analog pin is maintained at 2.5 V from a resistive divider resistors that hardly has the same or keeps these over the years (a phenomenon known as drift components). It follows that the reference value may be different from 2.5 V and change over time. However recalculating always the right valueforzerovoltsevery time the Arduino board will avoid having to periodically calibrate the circuit. The zerovoltis important because the result depends on him. It can be seen in the following figure where the areas of half-waves of changewithreference to zerovolts. (In the figure the value of the celestial is different from the red to the simple fact that the red area takes the reference to zerovoltslower.)

Variazione Area onda sinusoidale al variare del riferimento a 0 Volt


Output of the program

The program provides a numerical indication that growswiththe current to the only purpose of having a threshold value to disconnect a relay or, as in my case reportwithvoice messages that it is good to deactivate some eletrical apparatus. The numerical indication does not represent neither a power and neither a current. It ‘s just a number that increaseswiththe current. The choice not to measure the power derives mainly from the fact that the program is designed to be inserted as a routine in a more complex program. It must therefore have the characteristic of not requiring too much calculation power and to use the lowest possible memory. Other factors that have influenced the choice, the total cost (the SCT-013-030 sensor costs 6 Euro).

Method of Calculation

The program provides its numerical indication by calculating the arithmetic mean of repeated readings on the period of the sine wave (assuming the negative half-waves as positive). In practice, except use the geometric rather than quadratic, is the same algorithm (a repeated cycle) that is used to calculate the current effective.

In the realization of the sketch, I chose to use the arithmetic mean because ipotizzavo that,fortheArduinoboard, this would have been much faster to compute (I later found that there are significant differences between the computation time of the two averages). Furthermore, the difference between the two averages only consists in a compression of the results that does not affect the purpose of the project, therefore, works independently of the media used.

The program using a while loop makes sure to make a reasonable number of readings. Discard the first values as long as the wave does not pass through the relative value of zerovoltsand then begins to treat the amounts until, after reading goes over different periods of the wave not to 0V. In other words, the program reads full periods and these make its calculations to determine the area. 

Onda rilevata dal sensore SCT-013-020 sotto diverse combinazioni di carichi elettrici.The area of the wave and not the peak, because in some test I noticed that increasing the electrical load, the peak-to-peak wave does not increase much, while the wave becomes larger (ie, increases the wave area). In the figure the green wave (the higher wave) in comparisonwiththe gray wave). In other cases, the wave splits into two peaks; dark-green wave).

The figure shows the waves detected by the sensor SCT-013-30 on various electrical loads. At the beginning of the x axis a short horizontal line continues expresses the geometric mean of the wave of the corresponding color. The line, after a rising edge, continueswitha further horizontal section that represents the root mean square. This representation visually expresses the difference between the two averages. You can notice that the root mean square values are expanded along the y axis. However the purpose intended by the program, use one or the other media is equivalent. Withboth averages exists a threshold value, different in according to the used media, that the behavior of the system remains the same.



Wiring diagram to connect the Arduino circuit with sensor SCT-013-030 or SCT-013-020


Home connect a SCT-013-030 Sensor to an Arduino board

Circuit to connect Arduino to SCT-013-030

SCT-013-030 to Arduino Board

To connect arduino to SCT-013-030

SCT-013-20 Sensor installed.jpg

SCT-013-20 Sensor


The programforreading from the current non-invasive sensor SCT 013 020 (013 030 or SCT)

//** ********************************************************************* **//
//**                                                                       **//
//** AlertHighPower                                                        **//
//**                                                                       **//
//** Rilevatore di troppa corrente  per sensore SCT-013-020 o SCT-013-030  **//
//**                                                                       **//
//** ********************************************************************* **//
//** Lo scopo del programma è quello fornire  un valore, contenuto in  una **//
//** variabile, da usare  per accendere  un relè o emettere segnali sonori **//
//** quando in una casa si accendono contemporaneamente due grossi carichi **//
//** elettrici (forno,  phon,  lavatrici, lavastoviglie  ecc.; in generale **//
//** quelli superiori a 1500W).                                            **//
//**                                                                       **//
//** E’ un programma utile al fine di evitare  il  distacco  del contatore **//
//** elettrico per troppa potenza assorbita.                               **//
//**                                                                       **//
//** Tuttavia il programma funziona  a condizione  che l’ assorbimento del **//
//** maggiore carico elettrico, acceso insieme  a tutti  gli altri carichi **//
//** inferiori (tv, lampadine, computer ecc.) non sia tale da far scattare **//
//** il contatore.  Una  condizione  rispettata  in  quasi  tutte  le case **//
//** medio-piccole.                                                        **//
//**                                                                       **//
//** Per la prima impostazione:                                            **//
//** Lanciate il programma. Rilevate il valore (max) dato dall’assorbimen- **//
//** to di due grossi carichi. Rilevate il valore (min) dato dal più gros- **//
//** so carico che avete acceso insieme con tutti i carichi minori.  Assu- **//
//** mete  la  media  tra  questi  due  valori  come valore  di soglia ed  **//
//** impostatelo nell’ ultimo  IF del programma (…if  somma >110… )  al  **//
//** posto del numero 110.                                                 **//
//**                                                                       **//
//**                                                                       **//
//** Maggiori informazioni in             **//
//**                                                                       **//
//** Scritto da Corrado Bevilacqua nei ritagli di tempo.                   **//
//** Iniziato il 23/09/2013. Software e debug completato il 31/12/2013.    **//
//** Versione che non memorizza in un vettore i  singoli valori dell’ onda **//
//** per risparmiare memoria.                                              **//
//** Lavora sulla media  delle ultime 5 letture  per contenere la presenza **//
//** di impulsi spuri “spike” sull’onda sinosuidale rilevata.              **//
//**                                                                       **//
//** Software liberamente copiabile a patto morale di citare l’autore nei  **//
//** commenti del vostro programma.                                        **//
//** ********************************************************************* **//
//**  Written by Corrado Bevilacqua (C) –  **//
//** ********************************************************************* **//

//** ********************************************************************* **//
//** Variabili per il sensore di corrente                                  **//
//** ********************************************************************* **//
int valmedio[5];
int analogPin = 1; //pin da collegare al rilevatore di corrente SCT 013 020
int zerovolt=0;
long Quantacorrenteoldtempo=0; //per evitare che controlli la corrente di continuo

void setup()
Serial.println(“Sketch: AlertHighPower”);

//** **************************************************************** **//
//** Per il sensore di corrente – Rileva lo zerovolt                  **//
//** **************************************************************** **//
ZeroVolt();                                                      //** **//
//** **************************************************************** **//
}  // end setup

void loop()
//controlla la corrente
}    //end loop

void ZeroVolt()
//** **************************************************************** **//
//** Determino il valore da 2,5V a cui è collegato il sensore         **//
//** SCT 013-020. Lo calcolo ogni volta all’accensione dell’Arduino   **//
//** per evitare la deriva dei componenti.                            **//                   **
//** **************************************************************** **//

int max2 =0;
int min2 =9999;


int punta=0;
int mediato=0;

long oldtime1;

while (millis()-oldtime1<=85)
if (punta<4)


if (max2<mediato)
if (min2>mediato)


zerovolt = (max2+min2)/2;

Serial.print(“zerovolt = ” );

}    //end zerovolt

int QuantaCorrente()
if (abs(millis()-Quantacorrenteoldtempo) >= 10000)   //entra nel ciclo solo ogni dieci secondi

long somma=0;
long conta=0;
int punta=0;
int mediato=0;
int i=0;
int PerZeroOk=0;
int tante = 10;             //indica quante mezze onde leggere. Con 10 semionde (5 periodi) ci mette 100ms

//leggi valori per costruire la prima media


boolean onda=0;
if (mediato-zerovolt>0 )    //Se maggiore di uno allora per onda metto 1 altrimenti zero, Dice se l’onda è sopra o sotto lo zero

long TempoStart;             //variabile per calcolare quanto tempo ci mette

while (PerZeroOk<=tante && abs(millis()-TempoStart) < (tante+4)*20)
//Mediamo i valori letti per contenere gli spikes
if (punta<4)

// L’IF seguente Rileva il passaggio per zero e conseguentemente riesce a contare le semionde.
// Tuttavia per bassi assorbimenti di corrente non riesce a contarle bene e quindi fornisce un
// valore più basso di quello dovuto. E’ un problema che  si presenta solo per  basse correnti
// e quindi non inficia  il funzionamento del programma  perchè  lavora sulla fascia dei forti
// assorbimenti di corrente.

if ((onda==1 && mediato <0) || (onda==0 && mediato >0))
onda=onda^B1;   //Cambia lo stato da 0 a 1 e viceversa

//In PerZeroOK=0 siamo in un punto a caso della prima semionda per cui ignoriamone i valori. Dobbiamo prendere sempre semionde intere.
if (PerZeroOk>=1)


Serial.print(” TempoElaborazione=”);
Serial.print(” conta=”);
Serial.print(” Semionde=”);

if (somma >110 )    //se il valore supera la soglia, qui impostata a 110, allora segnala il troppo assorbimento di corrente.
Serial.print(“Troppa corrente”);

}    //end QuantaCorrente


The entire program (sketch) can be downloaded from the following link:

Translatedwith the help of google translate.
a better translation are appreciated.
If you try it, let me know your impressions