SCT-013-030 current monitor sensor



  • @fredok

    I had SCT-013-000 , not SCT-013-030 maybe this is the problem of measuring .



  • updated my sketch with new values for SCT-013-00 result is now

    #define MY_DEBUG
    #define MY_RADIO_NRF24
    // EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3  ***/
    #include <SPI.h>
    #include <MySensors.h>
    #include "EmonLib.h"             // Include Emon Library
    EnergyMonitor emon1;             // Create an instance
    
    #define CHILD_ID_CLAMP1 0
    #define PIN_ANALOG_I1 A1 //pince amperemetrique1
    
    unsigned long lastSend_power = millis();
    unsigned long lastSend_c = millis();
    unsigned long SEND_FREQUENCY = 120000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
    unsigned long SEND_FREQUENCY_C = SEND_FREQUENCY / 30;
    int index = 0;
    double Irms1 = 0;
    boolean pcReceived1 = false;
    float nrj1 = 0, old_nrj1;
    
    MyMessage IrmsMsg1(CHILD_ID_CLAMP1, V_WATT);
    MyMessage kWhMsg1(CHILD_ID_CLAMP1, V_KWH);
    MyMessage pcMsg1(CHILD_ID_CLAMP1, V_VAR1);
    
    void before() {
    
    }
    
    
    void presentation()
    {
      sendSketchInfo("Multisensors_Entree", "2.0");  // Send the sketch version information to the gateway and Controller
      present(CHILD_ID_CLAMP1, S_POWER);   // Register this device as power sensor
      request(CHILD_ID_CLAMP1, V_VAR1);
    }
    
    
    void receive(const MyMessage &message)
    {
      if (message.type == V_VAR1)
      {
        nrj1 = old_nrj1 = message.getFloat();
        Serial.print("Received last nrj count from gw:");
        Serial.println(nrj1);
        pcReceived1 = true;
      }
    }
    
    void setup()
    {
      emon1.current(PIN_ANALOG_I1, 111.1);       // Current: input pin, calibration.
      Serial.println("SETUP completed");
    }
    
    void envoi_donnees(double intrms, int id_clamp)
    {
      Serial.print("Envoi des donnees .... clamp="); Serial.println(id_clamp);
      double energie = (intrms * 240.0 * SEND_FREQUENCY / 1000) / 3.6E6;
      switch (id_clamp) //can be modified ...
      {
        case 1:
          {
            send(IrmsMsg1.set(intrms * 240.0, 1));
            nrj1 += energie;
            send(kWhMsg1.set(nrj1, 5));
            send(pcMsg1.set(nrj1, 5));
            old_nrj1 = nrj1;
          }
          break;
      }
    }
    
    void loop() {
      unsigned long now = millis();
      bool sendTime_c = now - lastSend_c > SEND_FREQUENCY_C;
      // Calcul de Irms1 et Irms2
      if (sendTime_c) //calcul Irms moy clamp1/clamp2
      {
        if (index == 0)
        {
          Irms1 = emon1.calcIrms(1480);
        }
        else  
        {
          Irms1 = (index * Irms1 + emon1.calcIrms(1480)) / (index + 1);
        }
        lastSend_c = now;
        index++;
      }
    
    bool sendTime_power = now - lastSend_power > SEND_FREQUENCY;
    
     if (sendTime_power)
    {
      // Envoi ou request Puissance1
      if (pcReceived1) envoi_donnees(Irms1, 1);
      else     {
        request(CHILD_ID_CLAMP1, V_VAR1);
        Serial.println("Request VAR1");
      }
      //on reinitialise les compteurs
      lastSend_power = now;
      index = 0;
      }
    }
    

    0_1490992284051_upload-583cafbf-bd94-4bad-8fd3-8c510f5cfbfc



  • great !!!!!



  • Hi , i update your sketch for Multiple sensor

    #define MY_RADIO_NRF24
    #define MY_DEBUG
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <EmonLib.h> 
    
    #define SERIAL_BAUD 115200
    
    #define PIN_ANALOG_I1 A0   // The input you attached SCT1.
    #define PIN_ANALOG_I2 A1   // The input you attached SCT2.
    #define PIN_ANALOG_I3 A2   // The input you attached SCT3.
    
    #define CHILD_ID_WATT 0    // child-id of sensor
    #define CHILD_ID_KWH  1    // child-id of sensor
    #define CHILD_ID_VAR1 2    // child-id of sensor
    
    #define MAX_CT 3           // Number of CT sensor
    
    EnergyMonitor ct1, ct2, ct3;
    
    MyMessage msgWatt(CHILD_ID_WATT,V_WATT);
    MyMessage msgKwh(CHILD_ID_KWH,V_KWH);
    MyMessage msgVar(CHILD_ID_VAR1,V_VAR1);
    
    unsigned long lastSend_power = millis();
    unsigned long lastSend_c = millis();
    unsigned long SEND_FREQUENCY   = 60000;               // 1 mn Minimum time between send (in milliseconds).
    unsigned long FREQUENCY_SAMPLE = SEND_FREQUENCY / 12 ; // ( 5 s)
    
    #define MAX_CT 3
    
    double  Irms[MAX_CT];
    float   nrj[MAX_CT];
    boolean pcReceived[MAX_CT];
    
    int    index = 0;
    
    void setup()
    {
    #ifdef MY_DEBUG
      Serial.begin(SERIAL_BAUD);
      Serial.println("Begin SETUP");
    #endif
      //ct1.current(PIN_ANALOG_I1, 111.1);     // Current: input pin, calibration.                                        
      ct1.current(PIN_ANALOG_I1, 60);          // current constant = (100 ÷ 0.050) ÷ 33 Homs = 60
      ct2.current(PIN_ANALOG_I2, 60);            
      ct3.current(PIN_ANALOG_I3, 60);            
    
      Irms[0] = ct1.calcIrms(1480);            // initial boot to charge up capacitor (no reading is taken) - testing
      Irms[1] = ct2.calcIrms(1480);
      Irms[2] = ct3.calcIrms(1480);
    
      for (int i=0; i<MAX_CT; i++) {
           Irms[i] = nrj[i] = 0;
           pcReceived[i]=false;
      }
    #ifdef MY_DEBUG
      Serial.println("SETUP completed");
    #endif
    
    }
    
    void presentation() {
      
      sendSketchInfo("Energy Meter", "2.1");
    
      present(0, S_POWER);
      request(0, V_VAR1);
      
      present(1, S_POWER);
      request(1, V_VAR1);
    
      present(2, S_POWER);
      request(2, V_VAR1);  
    }
    
    
    void receive(const MyMessage &message) {
      int SensorID ;
    
      SensorID = message.sensor ;
      
      if (message.type == V_VAR1) {
        
          nrj[SensorID] =  message.getFloat();
          pcReceived[SensorID] = true;
    
    #ifdef MY_DEBUG
          Serial.print("Received last nrj[");
          Serial.print(SensorID);
          Serial.print("] count from GW:");
          Serial.println(nrj[SensorID]);
    #endif
      }
    }
    
    void send_data(double intrms, int SensorID) {
    
    #ifdef MY_DEBUG
      Serial.print("Send data for SensorID="); 
      Serial.println(SensorID);
    #endif
    
      double energie = (intrms * 240.0 * SEND_FREQUENCY / 1000) / 3.6E6;
      
      nrj[SensorID] += energie;
      send(msgWatt.setSensor(SensorID).set(intrms * 240.0, 1));
      send(msgKwh.setSensor(SensorID).set(nrj[SensorID], 5));
      send(msgVar.setSensor(SensorID).set(nrj[SensorID], 5));
    }
    
    void loop() {
      
      unsigned long now = millis();
      double _Irms[MAX_CT];
      bool sendTime_c = now - lastSend_c > FREQUENCY_SAMPLE;
      
      if (sendTime_c)
      {
        _Irms[0] = ct1.calcIrms(1480) ; if (_Irms[0] < 0.3) _Irms[0] = 0;
        _Irms[1] = ct2.calcIrms(1480) ; if (_Irms[1] < 0.3) _Irms[1] = 0;
        _Irms[2] = ct3.calcIrms(1480) ; if (_Irms[2] < 0.3) _Irms[2] = 0;
    
        Irms[0] = (index * Irms[0] + _Irms[0]) / (index + 1);
        Irms[1] = (index * Irms[1] + _Irms[1]) / (index + 1);
        Irms[2] = (index * Irms[2] + _Irms[2]) / (index + 1);
    
        lastSend_c = now;
        index++;
    
    #ifdef MY_DEBUG
        for (int i=0; i<MAX_CT; i++) {
            Serial.print("CT");
            Serial.print(i);  Serial.print(" : ");
            Serial.print(Irms[i]*240.0);  // Apparent power
            Serial.print(" ");
            Serial.println(Irms[i]);      // Irms
        }
    #endif
      }
    
      bool sendTime_power = now - lastSend_power > SEND_FREQUENCY;
    
      if (sendTime_power)
      {
        for (int i=0; i<MAX_CT; i++) {
        // Envoi ou request Puissance1
           if (pcReceived[i])
            { 
             send_data(Irms[i], i);
            } else {
             request(i, V_VAR1);
             Serial.println("Request VAR1");
            }
        }
        //on reinitialise les compteurs
        lastSend_power = now;
        index = 0;
      }
    }
    


  • fine thx....


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.