Skip to content
  • 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. Development
  3. HELP!! NODE WITH RELAY VOLTAGE AND DETECTOR
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

HELP!! NODE WITH RELAY VOLTAGE AND DETECTOR

Scheduled Pinned Locked Moved Development
4 Posts 3 Posters 1.3k Views 3 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.
  • M Offline
    M Offline
    Marco Avallone
    wrote on last edited by
    #1

    Hi I'm trying to make a script of Arduino to create a node with home automation: relay, light sensor, and sensor noise.

    The problem is that the only solution for the installation of the coupling relay with a switch.

    The script should be divided into 2 sections:

    1. asynchronous control with photoresistor
    2. Turn off relay asynchronously, following a first draft to be modified:

    int stato = statorelay[message.getBool()]; //leggo stato da array
    Serial.print("stato:");
    Serial.println(stato);
    Serial.print("getbboolo:");
    Serial.println(message.getBool());
    Serial.print("messaggio sensore:");
    Serial.println(message.sensor);
    if (message.getBool()== 1, stato ==0) { // MESSAGGIO DI ACCENSIONE CON LAMPADINA SPENTA
    Serial.print("ACCENDI RELAY - Lampanida accesa ");
    digitalWrite(message.sensor-1+RELAY_3, RELAY_ON);
    statorelay[message.getBool()] = 1; // salvo in memoria stato relay
    return; // blocco script
    }
    if (message.getBool()== 0, stato ==1) { // MESSAGGIO DI SPEGNIMENTO CON LAMPADINA ACCESA
    Serial.print("SPEGNI RELAY - Lampanida spenta");
    digitalWrite(message.sensor-1+RELAY_3, RELAY_OFF);
    statorelay[message.getBool()] = 0; // salvo in memoria stato relay
    return;
    }
    if (message.getBool()== 0, stato ==0) { //MESSAGGIO DI SPEGNIMENTO CON LAMPADINA SPENTA
    Serial.print("ACCENDI RELAY - Lampanida spenta ");
    digitalWrite(message.sensor-1+RELAY_3, RELAY_ON);
    statorelay[message.getBool()] = 1; // salvo in memoria stato relay
    return;
    }
    if (message.getBool()== 1, stato ==1) { //MESSAGGIO DI ACCENSIONE CON LAMPADINA ACCESA
    Serial.print("SPEGNI RELAY - Lampanida accesa ");
    digitalWrite(message.sensor-1+RELAY_3, RELAY_OFF);
    statorelay[message.getBool()] = 0; // salvo in memoria stato relay
    return;
    }

    I NEED HELP!!! THANK YOU!

    If I was not clear please ask, sorry for my english

    1 Reply Last reply
    0
    • pansenP Offline
      pansenP Offline
      pansen
      wrote on last edited by
      #2
      • I NEED HELP!!!! is not a question. Describe your problem and then we might be able to help.
      • Please rewrite this sentence: "The problem is that the only solution for the installation of the coupling relay with a switch." I do not understand it at all. Better use google translate if your English is not so good.
      • You wrote something about asynchronously, I do not see any interrupts so your code is fully synchronous.

      Orange Pi Plus 2e connected to nrf24 PA via SPI running git-development MySensors gateway, OpenHAB2, mosquitto and MySQL persistence.

      M 1 Reply Last reply
      0
      • pansenP pansen
        • I NEED HELP!!!! is not a question. Describe your problem and then we might be able to help.
        • Please rewrite this sentence: "The problem is that the only solution for the installation of the coupling relay with a switch." I do not understand it at all. Better use google translate if your English is not so good.
        • You wrote something about asynchronously, I do not see any interrupts so your code is fully synchronous.
        M Offline
        M Offline
        Marco Avallone
        wrote on last edited by AWI
        #3

        OK, I rephrase the request.

        I have at home this CONFIGURATION

        0_1485349496573_deviatore_schema_funzionamento.png

        I created the following script:

        // Enable debug prints to serial monitor
        #define MY_DEBUG 
        
        // Enable and select radio type attached
        #define MY_RADIO_NRF24
        //#define MY_RADIO_RFM69
        
        // Enabled repeater feature for this node
        #define MY_REPEATER_FEATURE
        
        #include <SPI.h>
        #include <MySensors.h>
        
        
        #define RELAY_PIN  3  // Arduino Digital I/O pin number for relay 
        #define BUTTON_PIN  4  // Arduino Digital I/O pin number for button 
        #define CHILD_ID 1   // Id of the sensor child
        #define RELAY_ON 0
        #define RELAY_OFF 1
        
        
        
          bool state;
          int luce;
          int soglia = 25; //  imposed sensor sensitivity
          int statorelay = 0; //  variable that saves in memory initial state relay
        
        MyMessage msg(CHILD_ID,V_LIGHT);
        
        void setup()  
        {   
         
         
          pinMode(RELAY_PIN, OUTPUT); // 
          digitalWrite(RELAY_PIN, RELAY_OFF); //  Initial setting relay on off
        
        
        }
        
        void presentation()  {
        
          sendSketchInfo("RELAY DEVERTER", "1.0");
          present(CHILD_ID, S_LIGHT);
        }
        
        
        void loop() 
        {  
            
              int value;
              luce = (1023-analogRead(A0))/10.23;  // 
        I note if there is current on the bulb. I use a 220v led with a photoresistor.
              if(luce < soglia) {
             
                send(msg.set(value==HIGH ? 1 : 0)); //voltage yes
                }
              else {
                
                send(msg.set(value==LOW ? 1 : 0)); // voltage no
                }
            
             
              delay (1000);
        
        }
        
        
        
        void receive(const MyMessage &message) {
          //  SECTION ENTER POWER RELAY WITH REVERSE
        
             if (message.getBool()== 1, statorelay ==0)  {    // POWER ON MESSAGE WITH BULB OFF
                      Serial.print("ACCENDI RELAY - Lampanida accesa ");
                      digitalWrite(RELAY_PIN, RELAY_ON);
                      statorelay=1; // salvo in memoria stato relay
                      return; // blocco script
                }
             if (message.getBool()== 0, statorelay ==1)  {   //  SHUTDOWN WITH MESSAGE ON BULB
                       Serial.print("SPEGNI RELAY - Lampanida spenta");
                       digitalWrite(RELAY_PIN, RELAY_OFF);
                       statorelay=0;
                       return;
               }
             if (message.getBool()== 0, statorelay ==0)  {   // SHUTDOWN MESSAGE WITH BULB OFF - REVERSE
                         Serial.print("ACCENDI RELAY - Lampanida spenta ");
                         digitalWrite(RELAY_PIN, RELAY_ON);
                         statorelay=1;
                         return;
                }
             if (message.getBool()== 1, statorelay ==1)  {   //POWER ON MESSAGE WITH BULB ON - REVERSED
                           Serial.print("SPEGNI RELAY - Lampanida accesa ");
                           digitalWrite(RELAY_PIN, RELAY_OFF);
                           statorelay=1;
                           return;
                }
        }
        

        This script works, and allows me to see if the bulb is actually on or off, and turn it off or turn it on indipendetemente the state of the relay.

        The problem is the script:

        1. I would like to add more relays with detectors.
        2. I would like to send the status of the bulb to the gateway only when actually changes.

        Can you help me? I'VE BEEN CLEAR?

        THANK YOU!!!

        L 1 Reply Last reply
        0
        • M Marco Avallone

          OK, I rephrase the request.

          I have at home this CONFIGURATION

          0_1485349496573_deviatore_schema_funzionamento.png

          I created the following script:

          // Enable debug prints to serial monitor
          #define MY_DEBUG 
          
          // Enable and select radio type attached
          #define MY_RADIO_NRF24
          //#define MY_RADIO_RFM69
          
          // Enabled repeater feature for this node
          #define MY_REPEATER_FEATURE
          
          #include <SPI.h>
          #include <MySensors.h>
          
          
          #define RELAY_PIN  3  // Arduino Digital I/O pin number for relay 
          #define BUTTON_PIN  4  // Arduino Digital I/O pin number for button 
          #define CHILD_ID 1   // Id of the sensor child
          #define RELAY_ON 0
          #define RELAY_OFF 1
          
          
          
            bool state;
            int luce;
            int soglia = 25; //  imposed sensor sensitivity
            int statorelay = 0; //  variable that saves in memory initial state relay
          
          MyMessage msg(CHILD_ID,V_LIGHT);
          
          void setup()  
          {   
           
           
            pinMode(RELAY_PIN, OUTPUT); // 
            digitalWrite(RELAY_PIN, RELAY_OFF); //  Initial setting relay on off
          
          
          }
          
          void presentation()  {
          
            sendSketchInfo("RELAY DEVERTER", "1.0");
            present(CHILD_ID, S_LIGHT);
          }
          
          
          void loop() 
          {  
              
                int value;
                luce = (1023-analogRead(A0))/10.23;  // 
          I note if there is current on the bulb. I use a 220v led with a photoresistor.
                if(luce < soglia) {
               
                  send(msg.set(value==HIGH ? 1 : 0)); //voltage yes
                  }
                else {
                  
                  send(msg.set(value==LOW ? 1 : 0)); // voltage no
                  }
              
               
                delay (1000);
          
          }
          
          
          
          void receive(const MyMessage &message) {
            //  SECTION ENTER POWER RELAY WITH REVERSE
          
               if (message.getBool()== 1, statorelay ==0)  {    // POWER ON MESSAGE WITH BULB OFF
                        Serial.print("ACCENDI RELAY - Lampanida accesa ");
                        digitalWrite(RELAY_PIN, RELAY_ON);
                        statorelay=1; // salvo in memoria stato relay
                        return; // blocco script
                  }
               if (message.getBool()== 0, statorelay ==1)  {   //  SHUTDOWN WITH MESSAGE ON BULB
                         Serial.print("SPEGNI RELAY - Lampanida spenta");
                         digitalWrite(RELAY_PIN, RELAY_OFF);
                         statorelay=0;
                         return;
                 }
               if (message.getBool()== 0, statorelay ==0)  {   // SHUTDOWN MESSAGE WITH BULB OFF - REVERSE
                           Serial.print("ACCENDI RELAY - Lampanida spenta ");
                           digitalWrite(RELAY_PIN, RELAY_ON);
                           statorelay=1;
                           return;
                  }
               if (message.getBool()== 1, statorelay ==1)  {   //POWER ON MESSAGE WITH BULB ON - REVERSED
                             Serial.print("SPEGNI RELAY - Lampanida accesa ");
                             digitalWrite(RELAY_PIN, RELAY_OFF);
                             statorelay=1;
                             return;
                  }
          }
          

          This script works, and allows me to see if the bulb is actually on or off, and turn it off or turn it on indipendetemente the state of the relay.

          The problem is the script:

          1. I would like to add more relays with detectors.
          2. I would like to send the status of the bulb to the gateway only when actually changes.

          Can you help me? I'VE BEEN CLEAR?

          THANK YOU!!!

          L Offline
          L Offline
          LastSamurai
          Hardware Contributor
          wrote on last edited by
          #4

          @Marco-Avallone Please use the code syntax for your code snipet. Like this it's very hard to read. Also why do you use caps so much?
          For me your question isn't clear. What have you tried to actually do that did not work?

          • for 1: just add another child to your sketch for another relay... basically duplicate most of your code
          • for 2: then safe the last state and check it before sending a message

          Hope that helped.

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


          4

          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
          • OpenHardware.io
          • Categories
          • Recent
          • Tags
          • Popular