Author Topic: arduino help project (ammeter)  (Read 2348 times)

0 Members and 1 Guest are viewing this topic.

Offline islingtonTopic starter

  • Newbie
  • Posts: 6
  • Country: it
arduino help project (ammeter)
« on: December 08, 2019, 11:40:59 pm »
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 the
ampere of a line, then at 0,3 ampere swith on a light and when it reach 1,30ampere
to start a buzzer.
in the same time register the data of reading

thank to all people will reply to me
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2764
  • Country: us
Re: arduino help project (ammeter)
« Reply #1 on: December 08, 2019, 11:56:30 pm »
Welcome to the forum.
A quick Google search gives a simple example:
   https://learn.openenergymonitor.org/electricity-monitoring/ct-sensors/interface-with-arduino

Show 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.
« Last Edit: December 09, 2019, 12:01:55 am by MarkF »
 

Offline islingtonTopic starter

  • Newbie
  • Posts: 6
  • Country: it
Re: arduino help project (ammeter)
« Reply #2 on: December 09, 2019, 01:21:09 pm »
thisis what we have tryed to do me and my friend ,
not been able to insert the 2 alarms

not shure of the precicion .

 hope to have an help 
your sincerelly sergio T.
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2764
  • Country: us
Re: arduino help project (ammeter)
« Reply #3 on: December 09, 2019, 11:16:25 pm »
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.

    887226-0

  • 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!!!

    887214-1

« Last Edit: December 09, 2019, 11:41:34 pm by MarkF »
 

Offline islingtonTopic starter

  • Newbie
  • Posts: 6
  • Country: it
Re: arduino help project (ammeter)
« Reply #4 on: December 10, 2019, 06:43:28 am »
dear markf,

thank you for suggestion and reply

the 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 put
number 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 relays

the 2nd when i reach around 1.3/1.5Ampere (same as above) then the signal have to
close a relays .

then my circuit was ok.. (maybe if was possible to insert a time day year around the reading was better
but don't know if possible)

i  have searched around on book and sites the command to insert to make this alarm but
there is something we wrong if someone can help me modifing my sketch
or axplaning me how to do it i would be happy

thank to everyone could help at me

(Ps. the capacitor is 100uF)
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2764
  • Country: us
Re: arduino help project (ammeter)
« Reply #5 on: December 10, 2019, 07:29:59 am »
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: [Select]
#define R1pin 13   // Relay #1 pin number
#define R2pin 12   // Relay #2 pin number

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

  pinMode(R1pin, OUTPUT);     // Relay #1
  digitalWrite(R1pin, HIGH);  // Relay OFF (a LOW energizes the relay)

  pinMode(R2pin, OUTPUT);     // Relay #2
  difitalWrite(R2pin, HIGH);  // Relay OFF (a LOW energizes the relay)
}

//============================================================
void loop()
{
  bool alarmHigh, alarmLow;

  // Get RMS current
  double 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 ON
    digitalWrite(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 OFF
    digitalWrite(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 OFF
    digitalWrite(R2pin, HIGH);  // Relay #2 OFF
  }
}

« Last Edit: December 10, 2019, 09:13:08 am by MarkF »
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2764
  • Country: us
Re: arduino help project (ammeter)
« Reply #6 on: December 10, 2019, 08:18:20 am »
 

Offline islingtonTopic starter

  • Newbie
  • Posts: 6
  • Country: it
Re: arduino help project (ammeter)
« Reply #7 on: December 13, 2019, 01:25:19 pm »
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're
code , 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 mon
window i see the reading and all, but if i want to save this data into a usb key and download them into the pc
when i want , what did i need?it's possible?

thank you very much for youre help and you time
your sincerelly sergio T.
 

Offline islingtonTopic starter

  • Newbie
  • Posts: 6
  • Country: it
Re: arduino help project (ammeter)
« Reply #8 on: January 13, 2020, 07:09:16 am »
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 Open
When 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 Closed
when amperage go under 0.5 Amp both relay open (bulb off)
standby

whin a pieace of software markf done me that i've modified for me end inserted into my ammeter i've done
something work with high current but not like i wand i've tryed to make different sequences, the only one work a bit
is this, what is the error? can someone help at me?

i past the code

Code: [Select]

#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 ide     

EnergyMonitor emon1;

//configurazione rete elettrica
int rede = 230.0; //  230V / 110V
 
//Pin del sensore SCT su A1
int pin_sct = 1;

//============================================================
void setup()
{
  Serial.begin(9600);
   emon1.current(pin_sct, 29);
 
  pinMode(R1pin, OUTPUT);     // Relay #1
  digitalWrite(R1pin, LOW);  // Relay OFF (High Relè Eccitato)

  pinMode(R2pin, OUTPUT);     // Relay #2
  digitalWrite(R2pin, LOW);  // Relay OFF (High Relè Eccitato)
}

//============================================================
void loop()
{
  //Calcolo della corrente 
  double Irms = emon1.calcIrms(1480);
  //Mostra il valore della Corrente
  Serial.print("Corrente : ");
  Serial.println(Irms); // Irms
   
  bool 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 ON
    digitalWrite(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 OFF
    digitalWrite(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 OFF
    digitalWrite(R2pin, LOW);  // Relay #2 OFF
  }
}

 hope someone  could help at me ,  thank very much in advantage
 you sincerelly sergio T.
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2764
  • Country: us
Re: arduino help project (ammeter)
« Reply #9 on: January 13, 2020, 10:38:36 am »
Try this.

Note:
   If Arduino pin is HIGH, then relay is OPEN
   If Arduino pin is LOW, then relay is CLOSED

908270-0

Code: [Select]
void loop()
{
  bool alarmBell = false;
  bool alarmLamp = false;
  double Irms = 0.0;

  // Get RMS current
  Irms = 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 ON
    digitalWrite(R2pin, LOW);   // Bell ON
  }
  else if (Irms >= 0.5) (
    if ( !alarmLamp || alarmBell )
        Serial.println("Lamp alarm");
    alarmLamp = true;
    alarmBell = false;
    digitalWrite(R1pin, LOW);   // Lamp ON
    digitalWrite(R2pin, HIGH);  // Bell OFF
  }
  else {
    if ( alarmLamp )
        Serial.println("No alarm");
    alarmLamp = false;
    alarmBell = false;
    digitalWrite(R1pin, HIGH);  // Lamp OFF
    digitalWrite(R2pin, HIGH);  // Bell OFF
  }

  // Delay
  delay(1000);
}
« Last Edit: January 13, 2020, 09:11:37 pm by MarkF »
 

Offline islingtonTopic starter

  • Newbie
  • Posts: 6
  • Country: it
Re: arduino help project (ammeter)
« Reply #10 on: January 14, 2020, 03:05:24 pm »
Dear markf,

    thank you for  your reply , i've tryed the code you past here but with
 this one it really don't work in any way, i've  tryed different corrections but
 no 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 problems
because 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 the
ammeter (high then without ) and read some power that is not real also when charge is swithced off . :-// :-// |O

maybe the board is not good for this project? , i need to say that the project is not yet ended so the
nano is powered  by the pc only no power supply can this create problems?


now i past the code corrected tested if see any error
and the schematic of  relays board

you sincerelly sergioT .

Code: [Select]
#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 ide     

EnergyMonitor emon1;

//Inserire la tensione della vostra rete elettrica
int rede = 230.0; // Italia 230V in alcuni paesi 110V
 
//Pin del sensore SCT su A1
int pin_sct = 1;

//============================================================
void setup()
{
  Serial.begin(9600);
   emon1.current(pin_sct, 29);
 
  pinMode(R1pin, OUTPUT);     // Relay #1
  digitalWrite(R1pin, LOW);  // Relay OFF (a LOW energizes the relay)

  pinMode(R2pin, OUTPUT);     // Relay #2
  digitalWrite(R2pin, LOW);  // Relay OFF (a LOW energizes the relay)
}

//============================================================
void loop()
{
   bool allarmeSuoneria = false;
   bool allarmeLampada = false;
 
  //Calcolo della corrente 
  double Irms = emon1.calcIrms(1480);
  //Mostra il valore della Corrente
  Serial.print("Corrente : ");
  Serial.println(Irms); // Irms
     
    if (Irms >= 1.4) {             // ***  if (Amp > 1.5A)  ***
    if ( !allarmeSuoneria ) {
          Serial.println("Attenzione!: Superamento Soglia"); 
    allarmeLampada = true;
    allarmeSuoneria = true;     
    digitalWrite(R1pin, HIGH);   // Lampada accesa
    digitalWrite(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 accesa
    digitalWrite(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 OFF
    digitalWrite(R2pin, LOW);  // Suoneria OFF
  }
// Ritardo
 delay(1000);
  } 
}






 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2764
  • Country: us
Re: arduino help project (ammeter)
« Reply #11 on: January 14, 2020, 08:14:37 pm »
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: [Select]
// Test output code
void 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);
}

908916-0
« Last Edit: January 14, 2020, 08:41:34 pm by MarkF »
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2764
  • Country: us
Re: arduino help project (ammeter)
« Reply #12 on: January 15, 2020, 12:57:20 am »
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 corrente
   double Irms = emon1.calcIrms(1480);
   // Mostra il valore della Corrente
   Serial.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 accesa
      digitalWrite(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 accesa
      digitalWrite(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 OFF
      digitalWrite(R2pin, LOW);   // Suoneria OFF
   }

   // Ritardo
   delay(1000);
   // }    => DELETE THIS LINE <=
}

« Last Edit: January 15, 2020, 01:23:14 am by MarkF »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf