Electronics > Beginners

arduino help project (ammeter)

<< < (3/3)

islington:
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: ---#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);
  } 
}


--- End code ---





MarkF:
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 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);
}

--- End code ---

MarkF:
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 <=
}

Navigation

[0] Message Index

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod