arduino help project (ammeter) - Page 1
Forum section: electronics / beginners

author: islington
author_rank: Newbie
timestamp: December 08, 2019, 11:40:59 pm
content: dear forum,i'm here to ask if someone can help me with a project i'm trying to do,i'm tryng with arduino to make an ammeter with Sensore SCT-013-030 to read theampere of a line, then at 0,3 ampere swith on a light and when it reach 1,30ampereto start a buzzer.in the same time register the data of readingthank to all people will reply to me

author: MarkF
author_rank: Super Contributor
timestamp: December 08, 2019, 11:56:30 pm
content: Welcome to the forum.A quick Google search gives a simple example:https://learn.openenergymonitor.org/electricity-monitoring/ct-sensors/interface-with-arduinoShow us your circuit and your code and we will be glad to help.Edit:For what you are trying to do, you probably will want to rectify and smooth the output for the Arduino.This will provide the Arduino with a positive only voltage to convert.

author: islington
author_rank: Newbie
timestamp: December 09, 2019, 01:21:09 pm
content: thisis what we have tryed to do me and my friend ,not been able to insert the 2 alarmsnot shure of the precicion .hope to have an helpyour sincerelly sergio T.

author: MarkF
author_rank: Super Contributor
timestamp: December 09, 2019, 11:16:25 pm
content: Disclosure, I have never use these sensors.Some things I would check to start:Determine if you need a burden resistor. From what I can figure out, you do not.Measure the output of the sensor with DMM or scope. Is the sensor generating a proper voltage?Measure the input to the Arduino.Your circuit will output a sine wave to the Arduino. i.e. The Arduino will need to sample the waveform at a frequency at least 10 times the 50Hz/60Hz of your AC current and then determine the average or RMS value. Which brings me to the EnergyMonitor library. (Personally, I avoid libraries like the plague.) I leave it to you to figure out how to setup and use it.I would suggest a different circuit which would feed the Arduino a DC voltage.This voltage could then be measured with the standard ADC conversion.Make sure the max voltage does NOT exceed the Arduino analog input range!!!

author: islington
author_rank: Newbie
timestamp: December 10, 2019, 06:43:28 am
content: dear markf,thank you for suggestion and replythe ammeter work, i don't know how the precision is, but my problem is the sketch,with my friend reading around builded this one that work.. now i need to putnumber two alarms.one at the the start of reading (i can say 0,3or 0,5 when working i find correct value)the signal have to close a relaysthe 2nd when i reach around 1.3/1.5Ampere (same as above) then the signal have toclose a relays .then my circuit was ok.. (maybe if was possible to insert a time day year around the reading was betterbut don't know if possible)i have searched around on book and sites the command to insert to make this alarm butthere is something we wrong if someone can help me modifing my sketchor axplaning me how to do it i would be happythank to everyone could help at me(Ps. the capacitor is 100uF)

author: MarkF
author_rank: Super Contributor
timestamp: December 10, 2019, 07:29:59 am
content: I'm having a little trouble understanding what you have working. So...Are you asking how to use the value from the EnergyMonitor library?If you can read the current, it's just a matter of setting the alarms based on the current.The Arduino Uno does NOT have a realtime clock.So, no way to display the time and date without adding some realtime clock hardware.Some code you could merge into yours:Code:#define R1pin 13 // Relay #1 pin number#define R2pin 12 // Relay #2 pin number//============================================================void setup(){Serial.begin(9600);pinMode(R1pin, OUTPUT); // Relay #1digitalWrite(R1pin, HIGH); // Relay OFF (a LOW energizes the relay)pinMode(R2pin, OUTPUT); // Relay #2difitalWrite(R2pin, HIGH); // Relay OFF (a LOW energizes the relay)}//============================================================void loop(){bool alarmHigh, alarmLow;// Get RMS currentdouble Irms = emon1.calcIrms(1480);if (Irms > 1.5) { // *** if (Amp > 1.5A) ***if ( !alarmHigh ) {Serial.print("High alarm ON"); // Only print once}alarmHigh = TRUE;alarmLow = FALSE; /* Change to TRUE and R2pin to LOW* if you want both alarms ON when current is greater than 1.5A*/digitalWrite(R1pin, LOW); // Relay #1 ONdigitalWrite(R2pin, HIGH); // Relay #2 OFF}else if (Irms > 0.5) ( // *** if (0.5A < Amp <= 1.5A) ***if ( !alarmLow || alarmHigh ) {Serial.print("Low alarm ON"); // Only print once}alarmHigh = FALSE;alarmLow = TRUE;digitalWrite(R1pin, HIGH); // Relay #1 OFFdigitalWrite(R2pin, LOW); // Relay #2 ON}else { // *** else (Amp <= 0.5A) ***if ( alarmHigh || alarmLow ) {Serial.print("All alarms OFF"); // Only print once}alarmHigh = FALSE;alarmLow = FALSE;digitalWrite(R1pin, HIGH); // Relay #1 OFFdigitalWrite(R2pin, HIGH); // Relay #2 OFF}}

author: MarkF
author_rank: Super Contributor
timestamp: December 10, 2019, 08:18:20 am
content: Arduino and DS3231 Real Time Clock Tutorial

author: islington
author_rank: Newbie
timestamp: December 13, 2019, 01:25:19 pm
content: dear markf,thank you so much for your reply i think you have found out exactly what i was searching to do ,sorry for my english but it's too much time i'm in italy... now i'm out but when i'm back i'll try you'recode , but i think it's exactly what i was serching. for the realtime clock i think also that one it's what i'm searching,hope to understand how to implement it, another problem is when i connect laptop and open the serial monwindow i see the reading and all, but if i want to save this data into a usb key and download them into the pcwhen i want , what did i need?it's possible?thank you very much for youre help and you timeyour sincerelly sergio T.

author: islington
author_rank: Newbie
timestamp: January 13, 2020, 07:09:16 am
content: Dear Friend's ,with a help from markF I have placed 2 alarms into my ammeter (with sct013-030 sensor)i don't have placed displays or other only 2 relays that open and close when alarms occurs,and a serial terminal to log the outputs of the ammeter , but i have a little problem,the system have to do this things:at switch on with amperage under 0,5 Amp Both Relay OpenWhen reached 0,5 Amp. channel1 relays closed (bulb on) (be carefull )when reached or over 1.5Amp. Both relays Closed (ring a Bell) (DANGER)when Amperage return under 1.5 (example 1.35) Relay Channel 2 open and relay chanel1 Closedwhen amperage go under 0.5 Amp both relay open (bulb off)standbywhin a pieace of software markf done me that i've modified for me end inserted into my ammeter i've donesomething work with high current but not like i wand i've tryed to make different sequences, the only one work a bitis this, what is the error? can someone help at me?i past the codeCode:#define R1pin 13 // Relay #1 numero pin#define R2pin 12 // Relay #2 numero pin#include "EmonLib.h"#include <Wire.h> // Libreria wire già presente in Arduino ideEnergyMonitor emon1;//configurazione rete elettricaint rede = 230.0; // 230V / 110V//Pin del sensore SCT su A1int pin_sct = 1;//============================================================void setup(){Serial.begin(9600);emon1.current(pin_sct, 29);pinMode(R1pin, OUTPUT); // Relay #1digitalWrite(R1pin, LOW); // Relay OFF (High Relè Eccitato)pinMode(R2pin, OUTPUT); // Relay #2digitalWrite(R2pin, LOW); // Relay OFF (High Relè Eccitato)}//============================================================void loop(){//Calcolo della correntedouble Irms = emon1.calcIrms(1480);//Mostra il valore della CorrenteSerial.print("Corrente : ");Serial.println(Irms); // Irmsbool alarmHigh, alarmLow;// Get RMS current// double Irms = emon1.calcIrms(1480);delay(1000);if (Irms >= 1.4) { // *** if (Amp > 1.5A) ***if ( !alarmHigh ) {Serial.println("Attenzione!: Superamento Soglia"); // Stampa Su Serriale}alarmHigh = true;alarmLow = false; /* Cambia a TRUE e R2pin HIGH* Se vuoi entrambi gli alarmi ON Quando corrente superiore 1.5A*/digitalWrite(R1pin, HIGH); // Relay #1 ONdigitalWrite(R2pin, LOW); // Relay #2 OFF}else if (Irms >= 0.3) { // *** if (0.5A < Amp <= 1.5A) ***if ( !alarmLow || alarmHigh ) {Serial.println("Inizio : Tensione al minimo"); // solo stampa su seriale}alarmHigh = false;alarmLow = true;digitalWrite(R1pin, LOW); // Relay #1 OFFdigitalWrite(R2pin, HIGH); // Relay #2 ON}else { // *** else (Amp <= 0.5A) ***if ( alarmHigh || alarmLow ) {Serial.println("In attesa,No Tensione "); // solo stampa seriale}alarmHigh = false;alarmLow = false;digitalWrite(R1pin, LOW); // Relay #1 OFFdigitalWrite(R2pin, LOW); // Relay #2 OFF}}hope someone could help at me , thank very much in advantageyou sincerelly sergio T.

author: MarkF
author_rank: Super Contributor
timestamp: January 13, 2020, 10:38:36 am
content: Try this.Note:If Arduino pin is HIGH, then relay is OPENIf Arduino pin is LOW, then relay is CLOSEDCode:void loop(){bool alarmBell = false;bool alarmLamp = false;double Irms = 0.0;// Get RMS currentIrms = emon1.calcIrms(1480);Serial.print("Corrente: ");Serial.println(Irms);if (Irms >= 1.5) {if ( !alarmBell )Serial.println("Bell alarm");alarmLamp = true;alarmBell = true;digitalWrite(R1pin, LOW); // Lamp ONdigitalWrite(R2pin, LOW); // Bell ON}else if (Irms >= 0.5) (if ( !alarmLamp || alarmBell )Serial.println("Lamp alarm");alarmLamp = true;alarmBell = false;digitalWrite(R1pin, LOW); // Lamp ONdigitalWrite(R2pin, HIGH); // Bell OFF}else {if ( alarmLamp )Serial.println("No alarm");alarmLamp = false;alarmBell = false;digitalWrite(R1pin, HIGH); // Lamp OFFdigitalWrite(R2pin, HIGH); // Bell OFF}// Delaydelay(1000);}

author: islington
author_rank: Newbie
timestamp: January 14, 2020, 03:05:24 pm
content: Dear markf,thank you for your reply , i've tryed the code you past here but withthis one it really don't work in any way, i've tryed different corrections butno workout....... and i dont know why(the first one work in part like i want)other thing, i am using an arduino nano maybe is this?the pin setup is invertd, because if i have pin low no power from pin,and if set to high i have around 5 volts, but no problemsbecause if i invert all the instruction work correctly.the only problem is that if i connect this relays board, i get a wrong readings from theammeter (high then without ) and read some power that is not real also when charge is swithced off .maybe the board is not good for this project? , i need to say that the project is not yet ended so thenano is powered by the pc only no power supply can this create problems?now i past the code corrected tested if see any errorand the schematic of relays boardyou sincerelly sergioT .Code:#define R1pin 13 // Relay #1 pin number#define R2pin 12 // Relay #2 pin number#include "EmonLib.h"#include <Wire.h> // Libreria wire già presente in Arduino ideEnergyMonitor emon1;//Inserire la tensione della vostra rete elettricaint rede = 230.0; // Italia 230V in alcuni paesi 110V//Pin del sensore SCT su A1int pin_sct = 1;//============================================================void setup(){Serial.begin(9600);emon1.current(pin_sct, 29);pinMode(R1pin, OUTPUT); // Relay #1digitalWrite(R1pin, LOW); // Relay OFF (a LOW energizes the relay)pinMode(R2pin, OUTPUT); // Relay #2digitalWrite(R2pin, LOW); // Relay OFF (a LOW energizes the relay)}//============================================================void loop(){bool allarmeSuoneria = false;bool allarmeLampada = false;//Calcolo della correntedouble Irms = emon1.calcIrms(1480);//Mostra il valore della CorrenteSerial.print("Corrente : ");Serial.println(Irms); // Irmsif (Irms >= 1.4) { // *** if (Amp > 1.5A) ***if ( !allarmeSuoneria ) {Serial.println("Attenzione!: Superamento Soglia");allarmeLampada = true;allarmeSuoneria = true;digitalWrite(R1pin, HIGH); // Lampada accesadigitalWrite(R2pin, HIGH); // Suoneria accesa}else if (Irms >= 0.3) { // *** if (0.5A < Amp <= 1.5A) ***if ( !allarmeLampada || allarmeSuoneria )Serial.println("Inizio : Tensione al minimo");allarmeLampada = true;allarmeSuoneria = false;digitalWrite(R1pin, HIGH); // Lampada accesadigitalWrite(R2pin, LOW); // Suoneria Spenta}else { // *** else (Amp <= 0.5A) ***if ( allarmeLampada )Serial.println("In attesa,No Tensione ");allarmeLampada = false;allarmeSuoneria = false;digitalWrite(R1pin, LOW); // LAMPADA OFFdigitalWrite(R2pin, LOW); // Suoneria OFF}// Ritardodelay(1000);}}

author: MarkF
author_rank: Super Contributor
timestamp: January 14, 2020, 08:14:37 pm
content: I do not see any problems with the code.Your last version is nearly identical to mine with the exception of the inverted output pins.I'm curious why your current breakpoints are 1.4A and 0.3A if you truly want 1.5A and 0.5A.Maybe the library is not returning the correct value?I'm thinking the transistors in your circuit are not able to drive the relays?Try taking out just the transistors and see if the LEDs show correctly.I have had a similar problem and replaced the transistors with the ULN2003 Darlington Transistor Array.You might test the outputs by just having the loop() cycle through the outputs every two seconds.Code:// Test output codevoid loop(){digitalWrite(R1pin, LOW);digitalWrite(R2pin, LOW);delay(2000);digitalWrite(R1pin, HIGH);digitalWrite(R2pin, LOW);delay(2000);digitalWrite(R1pin, LOW);digitalWrite(R2pin, HIGH);delay(2000);digitalWrite(R1pin, HIGH);digitalWrite(R2pin, HIGH);delay(2000);}

author: MarkF
author_rank: Super Contributor
timestamp: January 15, 2020, 12:57:20 am
content: I found your code problem.It is 'if' nesting errors.I did not have brackets around the single line 'if' statements in my last code.void loop(){bool allarmeSuoneria = false;bool allarmeLampada = false;// Calcolo della correntedouble Irms = emon1.calcIrms(1480);// Mostra il valore della CorrenteSerial.print("Corrente : ");Serial.println(Irms);//========== CORRENTE { Amp >= 1.5A } ==========if (Irms >= 1.4) {if ( !allarmeSuoneria ){Serial.println("Attenzione!: Superamento Soglia");}allarmeLampada = true;allarmeSuoneria = true;digitalWrite(R1pin, HIGH); // Lampada accesadigitalWrite(R2pin, HIGH); // Suoneria accesa}//========== CORRENTE { 0.5A <= Amp < 1.5A } ==========else if (Irms >= 0.3) {if ( !allarmeLampada || allarmeSuoneria ){Serial.println("Inizio : Tensione al minimo");}allarmeLampada = true;allarmeSuoneria = false;digitalWrite(R1pin, HIGH); // Lampada accesadigitalWrite(R2pin, LOW); // Suoneria Spenta}//========== CORRENTE { Amp < 0.5A } ==========else {if ( allarmeLampada ){Serial.println("In attesa,No Tensione ");}allarmeLampada = false;allarmeSuoneria = false;digitalWrite(R1pin, LOW); // Lampada OFFdigitalWrite(R2pin, LOW); // Suoneria OFF}// Ritardodelay(1000);// } => DELETE THIS LINE <=}