Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Monitor a DIY solarpanel with ASC712 - HELP

Monitor a DIY solarpanel with ASC712 - HELP

Scheduled Pinned Locked Moved Troubleshooting
5 Posts 3 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hausner
    wrote on last edited by Hausner
    #1

    Has anyone gotten a ASC712 to work with a actuator node?

    I'm trying to monitor my diy solar panel, so that I can see what it is producing(if).

    I've tried with the code below, but I can't get the node to send the readings to the gateway. I'm using a 30A ASC712 to do the readings. (Don't mind the motion sensor part).

    My last code:

    // Example sketch showing how to control physical relays. 
    // This example will remember relay state even after power failure.
    
    #include <MySensor.h>
    #include <SPI.h>
    const int analogIn = A0;
    int mVperAmp = 66; // use 100 for 20A Module and 66 for 30A Module
    int RawValue= 0;
    int ACSoffset = 2500; 
    double Voltage = 0;
    double Amps = 0;
    double Voltage_new = 0;
    double Amps_new = 0;
    
    #define RELAY_1 6  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 2 // Total number of attached relays
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    
    // Motion sensor defs
    unsigned long SLEEP_TIME = 10000; // Sleep time between reports (in milliseconds)
    #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motionsensor.  (Only 2 and 3 generates interrupt!)
    #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
    #define CHILD_ID 3   // Id of the sensor child
    volatile int state = LOW;
    boolean lockLow = true;
    boolean lastTripped = 0;
    
    MySensor gw;
    MyMessage msgMotion(CHILD_ID, V_TRIPPED);
    MyMessage msgvolt(4, V_VOLTAGE);
    MyMessage msgcur(5, V_CURRENT);
    MyMessage msg(CHILD_ID, V_LIGHT);
    
    void setup()  
    {   
      // Initialize library and add callback for incoming messages
      gw.begin(incomingMessage, AUTO, true);
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Relay/Motion Sensor", "1.0");
    
      // Fetch relay status
      for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        gw.present(sensor, S_LIGHT);
        // Then set relay pins in output mode
        pinMode(pin, OUTPUT);   
        // Set relay to last known state (using eeprom storage) 
        digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
      }
      
      pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as  input
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID, S_MOTION);
      // attachInterrupt(DIGITAL_INPUT_SENSOR, ON, CHANGE);
      //delay(30000);
      gw.present(4, V_VOLTAGE);
      gw.present(5, V_CURRENT);
    }
    
    
    void loop() 
    {
      // Alway process incoming messages whenever possible
      gw.process();
    
      //boolean tripped = (digitalRead(DIGITAL_INPUT_SENSOR) == HIGH);
      //  if (lastTripped != tripped ) {
    //	gw.send(msgMotion.set(tripped?"1":"0")); // Send new state
    //	lastTripped=tripped;
    //   }
      
      //Serial.print("Raw Value = " ); // shows pre-scaled value 
      //Serial.print(RawValue);
      //gw.send(msgvolt);
      //Serial.print("\t mV = "); // shows the voltage measured 
      //Serial.print(Voltage,3); // the '3' after voltage allows you to display 3 digits after decimal point
      //Serial.print("\t Amps = "); // shows the voltage measured
      for ( int i=0; i<=20; i++ ){
        RawValue += analogRead(analogIn);
        delay(50);
      }
      Voltage = (RawValue / 1023.0) * 5000; // Gets you mV
      Amps = ((Voltage - ACSoffset) / mVperAmp);
      
      //gw.send(msgcur);
      Serial.print("mV = "); // shows the voltage measured
      Serial.println(Voltage);
      //Serial.println(Amps,3); // the '3' after voltage allows you to display 3 digits after             decimal point
      //delay(2500);
    }
    void incomingMessage(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
     if (message.type==V_LIGHT) {
     // Change relay state
     digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
     // Store state in eeprom
     gw.saveState(message.sensor, message.getBool());
     // Write some debug info
     Serial.print("Incoming change for sensor:");
     Serial.print(message.sensor);
     Serial.print(", New status: ");
     Serial.println(message.getBool());
     }
    }
    

    Any help would be appreciated :)

    PS: Att HEK - why isn't there a "insert code" button, just like the "insert link" button?

    hekH RJ_MakeR 2 Replies Last reply
    0
    • H Hausner

      Has anyone gotten a ASC712 to work with a actuator node?

      I'm trying to monitor my diy solar panel, so that I can see what it is producing(if).

      I've tried with the code below, but I can't get the node to send the readings to the gateway. I'm using a 30A ASC712 to do the readings. (Don't mind the motion sensor part).

      My last code:

      // Example sketch showing how to control physical relays. 
      // This example will remember relay state even after power failure.
      
      #include <MySensor.h>
      #include <SPI.h>
      const int analogIn = A0;
      int mVperAmp = 66; // use 100 for 20A Module and 66 for 30A Module
      int RawValue= 0;
      int ACSoffset = 2500; 
      double Voltage = 0;
      double Amps = 0;
      double Voltage_new = 0;
      double Amps_new = 0;
      
      #define RELAY_1 6  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
      #define NUMBER_OF_RELAYS 2 // Total number of attached relays
      #define RELAY_ON 1  // GPIO value to write to turn on attached relay
      #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
      
      // Motion sensor defs
      unsigned long SLEEP_TIME = 10000; // Sleep time between reports (in milliseconds)
      #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motionsensor.  (Only 2 and 3 generates interrupt!)
      #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
      #define CHILD_ID 3   // Id of the sensor child
      volatile int state = LOW;
      boolean lockLow = true;
      boolean lastTripped = 0;
      
      MySensor gw;
      MyMessage msgMotion(CHILD_ID, V_TRIPPED);
      MyMessage msgvolt(4, V_VOLTAGE);
      MyMessage msgcur(5, V_CURRENT);
      MyMessage msg(CHILD_ID, V_LIGHT);
      
      void setup()  
      {   
        // Initialize library and add callback for incoming messages
        gw.begin(incomingMessage, AUTO, true);
        // Send the sketch version information to the gateway and Controller
        gw.sendSketchInfo("Relay/Motion Sensor", "1.0");
      
        // Fetch relay status
        for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
          // Register all sensors to gw (they will be created as child devices)
          gw.present(sensor, S_LIGHT);
          // Then set relay pins in output mode
          pinMode(pin, OUTPUT);   
          // Set relay to last known state (using eeprom storage) 
          digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
        }
        
        pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as  input
        // Register all sensors to gw (they will be created as child devices)
        gw.present(CHILD_ID, S_MOTION);
        // attachInterrupt(DIGITAL_INPUT_SENSOR, ON, CHANGE);
        //delay(30000);
        gw.present(4, V_VOLTAGE);
        gw.present(5, V_CURRENT);
      }
      
      
      void loop() 
      {
        // Alway process incoming messages whenever possible
        gw.process();
      
        //boolean tripped = (digitalRead(DIGITAL_INPUT_SENSOR) == HIGH);
        //  if (lastTripped != tripped ) {
      //	gw.send(msgMotion.set(tripped?"1":"0")); // Send new state
      //	lastTripped=tripped;
      //   }
        
        //Serial.print("Raw Value = " ); // shows pre-scaled value 
        //Serial.print(RawValue);
        //gw.send(msgvolt);
        //Serial.print("\t mV = "); // shows the voltage measured 
        //Serial.print(Voltage,3); // the '3' after voltage allows you to display 3 digits after decimal point
        //Serial.print("\t Amps = "); // shows the voltage measured
        for ( int i=0; i<=20; i++ ){
          RawValue += analogRead(analogIn);
          delay(50);
        }
        Voltage = (RawValue / 1023.0) * 5000; // Gets you mV
        Amps = ((Voltage - ACSoffset) / mVperAmp);
        
        //gw.send(msgcur);
        Serial.print("mV = "); // shows the voltage measured
        Serial.println(Voltage);
        //Serial.println(Amps,3); // the '3' after voltage allows you to display 3 digits after             decimal point
        //delay(2500);
      }
      void incomingMessage(const MyMessage &message) {
        // We only expect one type of message from controller. But we better check anyway.
       if (message.type==V_LIGHT) {
       // Change relay state
       digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
       // Store state in eeprom
       gw.saveState(message.sensor, message.getBool());
       // Write some debug info
       Serial.print("Incoming change for sensor:");
       Serial.print(message.sensor);
       Serial.print(", New status: ");
       Serial.println(message.getBool());
       }
      }
      

      Any help would be appreciated :)

      PS: Att HEK - why isn't there a "insert code" button, just like the "insert link" button?

      hekH Offline
      hekH Offline
      hek
      Admin
      wrote on last edited by
      #2

      @Hausner said:

      PS: Att HEK - why isn't there a "insert code" button, just like the "insert link" button?

      Sorry. Haven't found any nodebb-plugin which add this in the composer. So you have to surround code with 4 backticks ```` in the meantime.

      1 Reply Last reply
      0
      • H Hausner

        Has anyone gotten a ASC712 to work with a actuator node?

        I'm trying to monitor my diy solar panel, so that I can see what it is producing(if).

        I've tried with the code below, but I can't get the node to send the readings to the gateway. I'm using a 30A ASC712 to do the readings. (Don't mind the motion sensor part).

        My last code:

        // Example sketch showing how to control physical relays. 
        // This example will remember relay state even after power failure.
        
        #include <MySensor.h>
        #include <SPI.h>
        const int analogIn = A0;
        int mVperAmp = 66; // use 100 for 20A Module and 66 for 30A Module
        int RawValue= 0;
        int ACSoffset = 2500; 
        double Voltage = 0;
        double Amps = 0;
        double Voltage_new = 0;
        double Amps_new = 0;
        
        #define RELAY_1 6  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
        #define NUMBER_OF_RELAYS 2 // Total number of attached relays
        #define RELAY_ON 1  // GPIO value to write to turn on attached relay
        #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
        
        // Motion sensor defs
        unsigned long SLEEP_TIME = 10000; // Sleep time between reports (in milliseconds)
        #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motionsensor.  (Only 2 and 3 generates interrupt!)
        #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
        #define CHILD_ID 3   // Id of the sensor child
        volatile int state = LOW;
        boolean lockLow = true;
        boolean lastTripped = 0;
        
        MySensor gw;
        MyMessage msgMotion(CHILD_ID, V_TRIPPED);
        MyMessage msgvolt(4, V_VOLTAGE);
        MyMessage msgcur(5, V_CURRENT);
        MyMessage msg(CHILD_ID, V_LIGHT);
        
        void setup()  
        {   
          // Initialize library and add callback for incoming messages
          gw.begin(incomingMessage, AUTO, true);
          // Send the sketch version information to the gateway and Controller
          gw.sendSketchInfo("Relay/Motion Sensor", "1.0");
        
          // Fetch relay status
          for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
            // Register all sensors to gw (they will be created as child devices)
            gw.present(sensor, S_LIGHT);
            // Then set relay pins in output mode
            pinMode(pin, OUTPUT);   
            // Set relay to last known state (using eeprom storage) 
            digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
          }
          
          pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as  input
          // Register all sensors to gw (they will be created as child devices)
          gw.present(CHILD_ID, S_MOTION);
          // attachInterrupt(DIGITAL_INPUT_SENSOR, ON, CHANGE);
          //delay(30000);
          gw.present(4, V_VOLTAGE);
          gw.present(5, V_CURRENT);
        }
        
        
        void loop() 
        {
          // Alway process incoming messages whenever possible
          gw.process();
        
          //boolean tripped = (digitalRead(DIGITAL_INPUT_SENSOR) == HIGH);
          //  if (lastTripped != tripped ) {
        //	gw.send(msgMotion.set(tripped?"1":"0")); // Send new state
        //	lastTripped=tripped;
        //   }
          
          //Serial.print("Raw Value = " ); // shows pre-scaled value 
          //Serial.print(RawValue);
          //gw.send(msgvolt);
          //Serial.print("\t mV = "); // shows the voltage measured 
          //Serial.print(Voltage,3); // the '3' after voltage allows you to display 3 digits after decimal point
          //Serial.print("\t Amps = "); // shows the voltage measured
          for ( int i=0; i<=20; i++ ){
            RawValue += analogRead(analogIn);
            delay(50);
          }
          Voltage = (RawValue / 1023.0) * 5000; // Gets you mV
          Amps = ((Voltage - ACSoffset) / mVperAmp);
          
          //gw.send(msgcur);
          Serial.print("mV = "); // shows the voltage measured
          Serial.println(Voltage);
          //Serial.println(Amps,3); // the '3' after voltage allows you to display 3 digits after             decimal point
          //delay(2500);
        }
        void incomingMessage(const MyMessage &message) {
          // We only expect one type of message from controller. But we better check anyway.
         if (message.type==V_LIGHT) {
         // Change relay state
         digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
         // Store state in eeprom
         gw.saveState(message.sensor, message.getBool());
         // Write some debug info
         Serial.print("Incoming change for sensor:");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
         }
        }
        

        Any help would be appreciated :)

        PS: Att HEK - why isn't there a "insert code" button, just like the "insert link" button?

        RJ_MakeR Offline
        RJ_MakeR Offline
        RJ_Make
        Hero Member
        wrote on last edited by
        #3

        @Hausner Serial Monitor output OK?

        RJ_Make

        1 Reply Last reply
        0
        • H Offline
          H Offline
          Hausner
          wrote on last edited by
          #4

          No, serial monitor was just for testing. I would like to push it to mqtt.

          I found the V_VOLTAGE and V_CURRENT, and the serial monotir showed up correctly as 38/39.

          RJ_MakeR 1 Reply Last reply
          0
          • H Hausner

            No, serial monitor was just for testing. I would like to push it to mqtt.

            I found the V_VOLTAGE and V_CURRENT, and the serial monotir showed up correctly as 38/39.

            RJ_MakeR Offline
            RJ_MakeR Offline
            RJ_Make
            Hero Member
            wrote on last edited by
            #5

            @Hausner So the problem is with the node transmitting anything to the gateway?

            Post the radio messages from the serial monitor and hopefully someone can tell you what's going on..

            RJ_Make

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            10

            Online

            11.7k

            Users

            11.2k

            Topics

            113.0k

            Posts


            Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • MySensors
            • OpenHardware.io
            • Categories
            • Recent
            • Tags
            • Popular