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.
  • hekH Offline
    hekH Offline
    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 Offline
                      hekH Offline
                      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


                        19

                        Online

                        11.7k

                        Users

                        11.2k

                        Topics

                        113.1k

                        Posts


                        Copyright 2025 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