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. Hardware
  3. RF 433 MHz sensor to control RF sockets.

RF 433 MHz sensor to control RF sockets.

Scheduled Pinned Locked Moved Hardware
22 Posts 10 Posters 16.8k Views 4 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.
  • L lasso

    Hek, thank for your response. I have to send two information to node (and from node): RF433 code and period. I would like to avoid sending this information in two messages (e.g. as V_VAR1 and V_VAR2), so I joined this informations in one by using class String. Maybe do You have idea how to avoid String class in this program?

    hekH Online
    hekH Online
    hek
    Admin
    wrote on last edited by
    #8

    @lasso

    atoi, strcpy, itoa

    L 1 Reply Last reply
    0
    • hekH hek

      @lasso

      atoi, strcpy, itoa

      L Offline
      L Offline
      lasso
      wrote on last edited by lasso
      #9

      OK, I stopped using String Class, but program works in the same way.On start Arduino, program works well and I can get and send RF433 codes. After some pushes a button on RF433 remote, LED on Arduino (pin 13) turns off and then I can't send messages from gateway to node, but I can still get codes of buttons on gateway from node. I think that, maybe this problem is connected with interrupts because NRF24 and receiver RF433 modules are using interrupts. IRQ pin from NRF24 module is connected to pin 2 (int.0) in Arduino Pro Mini and data pin from receiver RF433 module is connected to pin 3 (int.1) in Arduino.
      @hek Do You have any idea why this program doesn't work properly?

          #include <Relay.h>
          #include <SPI.h>
          #include <EEPROM.h>  
          #include <RF24.h>
          
          #include <RemoteReceiver.h>
          #include <RemoteTransmitter.h>
          
          #define TRANSMITTER_PIN 8
          #define RECEIVER_INTERRUPT 1
          #define RF433_CHILD_ID 0
          Sensor gw;
          
          void setup()  
          {  
            gw.begin(28);
            gw.sendSketchInfo("RF433", "1.0");
            gw.sendSensorPresentation(RF433_CHILD_ID, S_IR);
            RemoteReceiver::init(RECEIVER_INTERRUPT, 3, getRfMessage);
          }
          
          void loop() 
          {
            if (gw.messageAvailable()) {
              message_s message = gw.getMessage(); 
              sendRfMessage(message);
            }
          }
          
          void sendRfMessage(message_s message) {
            if (message.header.messageType==M_SET_VARIABLE &&
                message.header.type==V_IR_SEND) {
          
               char sendingRfCode[7]; 
               char sendingRfPeriod[4];
               strncpy(sendingRfCode, message.data, 6);
               strncpy(sendingRfPeriod, message.data+6, 3);
               sendingRfCode[6] = 0;
               sendingRfPeriod[3] = 0;
               Serial.println(atol(sendingRfCode));
               Serial.println(atol(sendingRfPeriod));
               RemoteReceiver::disable();
               interrupts();
               delay(200);
               RemoteTransmitter::sendCode(TRANSMITTER_PIN, atol(sendingRfCode), atol(sendingRfPeriod), 3);
               RemoteReceiver::enable();
             }
          }
          
          void getRfMessage(unsigned long incomingRfCode, unsigned int incomingRfPeriod){
            
            char gettingRfMessage[10];
            sprintf(gettingRfMessage, "%lu%u", incomingRfCode, incomingRfPeriod);
            Serial.println(incomingRfCode);
            Serial.println(incomingRfPeriod);
            Serial.println(gettingRfMessage);
            gw.sendVariable(RF433_CHILD_ID, V_IR_RECEIVE, gettingRfMessage);
            delay(200);
          }
      
      1 Reply Last reply
      0
      • hekH Online
        hekH Online
        hek
        Admin
        wrote on last edited by hek
        #10

        yup, in the example you attach it to INT1 (=GPIO pin 3).

        You can safely detach IRQ pin from radio if you want. It is not used for anything right now.

        Or change RECEIVER_INTERRUPT to 0 and attach receiver to GPIO pin 2.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lasso
          wrote on last edited by
          #11

          @hek
          I detached IRQ pin from pin 2 in Arduino and attached to pin 2 data line from RF433 receiver. After that, I changed RECEIVER_INTERRUPT to 0. Program works in the same way. The problem has not been solved.

          1 Reply Last reply
          0
          • hekH Online
            hekH Online
            hek
            Admin
            wrote on last edited by hek
            #12

            If I understand the RemoteReceiver code correctly your callback will be called in an interrupt. This means you should do as little as possible there. Definetly not serial print or send any data over radio.

            I propose you just save the incoming values and a new flag like this:

            setup() {
                RemoteReceiver::init(RECEIVER_INTERRUPT, 3, newRf);
            }
            
            volatile bool receivedNew = false;
            volatile unsigned long incomingRfCode;
            volatile unsigned int incomingRfPeriod;
            
            void newRf(unsigned long _incomingRfCode, unsigned int _incomingRfPeriod){
                 incomingRfCode = _incomingRfCode;
                 incomingRfPeriod = _incomingRfPeriod;
                 receivedNew=true;
            }
            

            And in you main loop check if received new is true.

            loop() {
                 if(receivedNew) {
                     getRfMessage(incomingRfCode, incomingRfPeriod);
                     receivedNew = false;
                 }
            }
            

            Note this is not tested and should just give you an hint how to handle it without doing lots of stuff when executing inside an interrupt.

            1 Reply Last reply
            1
            • L Offline
              L Offline
              lasso
              wrote on last edited by
              #13

              @hek
              Wow it's working :+1:. Hek thank you very much, you are the master :D
              This is working code:
              #include <Relay.h>
              #include <SPI.h>
              #include <EEPROM.h>
              #include <RF24.h>

                  #include <RemoteReceiver.h>
                  #include <RemoteTransmitter.h>
                  
                  #define TRANSMITTER_PIN 8
                  #define RECEIVER_INTERRUPT 1
                  #define RF433_CHILD_ID 0
                  Sensor gw;
                  
                  volatile bool receivedNew = false;
                  volatile unsigned long incomingRfCode;
                  volatile unsigned int incomingRfPeriod;
                  
                  void setup()  
                  {  
                    gw.begin(28);
                    gw.sendSketchInfo("RF433", "1.0");
                    gw.sendSensorPresentation(RF433_CHILD_ID, S_IR);
                     delay(200);
                    RemoteReceiver::init(RECEIVER_INTERRUPT, 3, newRf);
                  }
                  
                  void loop() 
                  {
                    if (gw.messageAvailable()) {
                      message_s message = gw.getMessage(); 
                      sendRfMessage(message);
                    }
                    if(receivedNew) {
                      getRfMessage(incomingRfCode, incomingRfPeriod);
                      receivedNew = false;
                    }
                  }
                  
                  void sendRfMessage(message_s message) {
                    if (message.header.messageType==M_SET_VARIABLE &&
                        message.header.type==V_IR_SEND) {
                  
                       char sendingRfCode[7]; 
                       char sendingRfPeriod[4];
                       strncpy(sendingRfCode, message.data, 6);
                       strncpy(sendingRfPeriod, message.data+6, 3);
                       sendingRfCode[6] = 0;
                       sendingRfPeriod[3] = 0;
                       Serial.println(atol(sendingRfCode));
                       Serial.println(atol(sendingRfPeriod));
                       RemoteReceiver::disable();
                       interrupts();
                       delay(200);
                       RemoteTransmitter::sendCode(TRANSMITTER_PIN, atol(sendingRfCode), atol(sendingRfPeriod), 3);
                       RemoteReceiver::enable();
                     }
                  }
                  
                  void newRf(unsigned long _incomingRfCode, unsigned int _incomingRfPeriod){
                       incomingRfCode = _incomingRfCode;
                       incomingRfPeriod = _incomingRfPeriod;
                       receivedNew=true;
                  }
                  
                  void getRfMessage(unsigned long incomingRfCode, unsigned int incomingRfPeriod){
                    char gettingRfMessage[10];
                    sprintf(gettingRfMessage, "%lu%u", incomingRfCode, incomingRfPeriod);
                    Serial.println(incomingRfCode);
                    Serial.println(incomingRfPeriod);
                    Serial.println(gettingRfMessage);
                    gw.sendVariable(RF433_CHILD_ID, V_IR_RECEIVE, gettingRfMessage);
                  }
              
              S 1 Reply Last reply
              0
              • D Offline
                D Offline
                donnib
                wrote on last edited by
                #14

                @lasso Are you learning the codes with the receiver inorder to know what to send to them ? I would really like to react on my 433mhz sensors i have for doors and i am interested how to do that and i found your post and i am trying to figure out if i could use some of this code for that purpose, what's your take on that ?

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dayve218
                  wrote on last edited by
                  #15

                  any idea about this?

                  variable or field 'sendRfMessage' declared void

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dayve218
                    wrote on last edited by dayve218
                    #16

                    @lasso @hek
                    any idea about this?

                    variable or field 'sendRfMessage' declared void

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      Terence Faul
                      wrote on last edited by
                      #17

                      Did you ever get this working?

                      What pins did you attache the transmitter to and what pin did you attach the receiver to?

                      Is that the latest code?

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        gebir
                        wrote on last edited by
                        #18

                        Hello,
                        this is my version "Home Easy Plug-in switch (HE877)". scatch.
                        Arduino emulates remote control Elro AB440
                        AVI, thanks for the inspiration.

                        https://codebender.cc/sketch:92208

                        1 Reply Last reply
                        0
                        • L lasso

                          @hek
                          Wow it's working :+1:. Hek thank you very much, you are the master :D
                          This is working code:
                          #include <Relay.h>
                          #include <SPI.h>
                          #include <EEPROM.h>
                          #include <RF24.h>

                              #include <RemoteReceiver.h>
                              #include <RemoteTransmitter.h>
                              
                              #define TRANSMITTER_PIN 8
                              #define RECEIVER_INTERRUPT 1
                              #define RF433_CHILD_ID 0
                              Sensor gw;
                              
                              volatile bool receivedNew = false;
                              volatile unsigned long incomingRfCode;
                              volatile unsigned int incomingRfPeriod;
                              
                              void setup()  
                              {  
                                gw.begin(28);
                                gw.sendSketchInfo("RF433", "1.0");
                                gw.sendSensorPresentation(RF433_CHILD_ID, S_IR);
                                 delay(200);
                                RemoteReceiver::init(RECEIVER_INTERRUPT, 3, newRf);
                              }
                              
                              void loop() 
                              {
                                if (gw.messageAvailable()) {
                                  message_s message = gw.getMessage(); 
                                  sendRfMessage(message);
                                }
                                if(receivedNew) {
                                  getRfMessage(incomingRfCode, incomingRfPeriod);
                                  receivedNew = false;
                                }
                              }
                              
                              void sendRfMessage(message_s message) {
                                if (message.header.messageType==M_SET_VARIABLE &&
                                    message.header.type==V_IR_SEND) {
                              
                                   char sendingRfCode[7]; 
                                   char sendingRfPeriod[4];
                                   strncpy(sendingRfCode, message.data, 6);
                                   strncpy(sendingRfPeriod, message.data+6, 3);
                                   sendingRfCode[6] = 0;
                                   sendingRfPeriod[3] = 0;
                                   Serial.println(atol(sendingRfCode));
                                   Serial.println(atol(sendingRfPeriod));
                                   RemoteReceiver::disable();
                                   interrupts();
                                   delay(200);
                                   RemoteTransmitter::sendCode(TRANSMITTER_PIN, atol(sendingRfCode), atol(sendingRfPeriod), 3);
                                   RemoteReceiver::enable();
                                 }
                              }
                              
                              void newRf(unsigned long _incomingRfCode, unsigned int _incomingRfPeriod){
                                   incomingRfCode = _incomingRfCode;
                                   incomingRfPeriod = _incomingRfPeriod;
                                   receivedNew=true;
                              }
                              
                              void getRfMessage(unsigned long incomingRfCode, unsigned int incomingRfPeriod){
                                char gettingRfMessage[10];
                                sprintf(gettingRfMessage, "%lu%u", incomingRfCode, incomingRfPeriod);
                                Serial.println(incomingRfCode);
                                Serial.println(incomingRfPeriod);
                                Serial.println(gettingRfMessage);
                                gw.sendVariable(RF433_CHILD_ID, V_IR_RECEIVE, gettingRfMessage);
                              }
                          
                          S Offline
                          S Offline
                          Straydog
                          wrote on last edited by
                          #19

                          @lasso Like to try your RF 433 Mhz Sensor sketch but can't find a working instance od Relay.h.
                          Can you help?

                          1 Reply Last reply
                          0
                          • C Offline
                            C Offline
                            cdr
                            wrote on last edited by
                            #20

                            "can't find a working instance od Relay.h."

                            Having the same issue here, perhaps it's for version 1.3 of mysensors?

                            hekH 1 Reply Last reply
                            0
                            • C cdr

                              "can't find a working instance od Relay.h."

                              Having the same issue here, perhaps it's for version 1.3 of mysensors?

                              hekH Online
                              hekH Online
                              hek
                              Admin
                              wrote on last edited by
                              #21

                              @cdr

                              Yes, 1.3 had a Realy-class.

                              1 Reply Last reply
                              0
                              • alowhumA Offline
                                alowhumA Offline
                                alowhum
                                Plugin Developer
                                wrote on last edited by alowhum
                                #22

                                Does anyone have a working version of this for 2.x?

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


                                16

                                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