arduinoarduino-ideesp32

RCSwitch library seemingly not working for 433 Hz receiver on ESP32 NodeMCU


I'm pretty new to Arduino and especially ESP32. But - before I receive the tip "use an Arduino" - I decided to go for the ESP32 because of the size and the capability to connect it to the WLAN.

However, I am trying to build some control box for my terrarium which should - in the first design - steer various lamps and the rain pump via remote controlled outlets. For this I got an ESP32 NodeMCU, a RTC time module (which seems to work quite fine) and a 433 Hz receiver/sender set.

I followed several tutorials regarding the wiring and uploaded the example files to the ESP32. No matter which pin I connect the Receiver to (I need to connect the receiver first in order to read out the signals of the 433 Hz control which came with the outlets) I won't receive any signals on the receiver.

I embedded the library RCSwitch and I tried to configure my switch as follows (here with PIN 13 as example - I tried several other pins as well):

mySwitch.enableReceive(13)

As I read in some other blog, there might be the need to convert the pin number to its interrupt address, so I tried the following:

mySwitch.enableReceive(digitalPinToInterrupt(13))

The result is always the same: dead silence on the serial monitor (except the boot messages, etc.).

Am I using the wrong library or what am I doing wrong here?

I read that there should be a library called RFSwitch, but the only version I found only features the 433 Hz sender, not the receiver.

I would be really grateful for any hint concerning this issue - I'm pretty stuck here for many hours now...


Solution

  • Have been successful with RCSwitch today on ESP32 Dev Board and a 433MHZ receiver and sender. Here is what I have been stumbling on my journey.

    Connecting the receiver (requires 5V)

    #include <RCSwitch.h>
    RCSwitch mySwitch = RCSwitch();
    
    #define RXD2 27
    
    void setup() {
      Serial.begin(115200);
      Serial.print("Ready to receive.");  
      mySwitch.enableReceive(RXD2); 
    }
    
    void loop() {    
      if (mySwitch.available()) {  
        Serial.print("Received ");
        Serial.print( mySwitch.getReceivedValue() );
        Serial.print(" / ");
        Serial.print( mySwitch.getReceivedBitlength() );
        Serial.print("bit ");
        Serial.print("Protocol: ");
        Serial.print( mySwitch.getReceivedProtocol() );
        Serial.print(" / ");
        Serial.println( mySwitch.getReceivedDelay() );
    
        mySwitch.resetAvailable();
      }
    }
    

    In your RC and Outlet can be configured by DIP-Switches you might not need to connect the receiver overall - you can directly insert the DIP-Switches levels in the RCSwitch-Library

    Connecting the sender (is fine with just 3.3V)

    #include <Arduino.h>
    #include <WiFi.h>
    #include <RCSwitch.h>
    
    #define TXD2 25
    
    RCSwitch mySwitch = RCSwitch();
    
    void setup() {
      Serial.begin(115200);
      
      // Transmitter is connected to Arduino Pin #10  
      mySwitch.enableTransmit(TXD2);
      
      // Optional set protocol (default is 1, will work for most outlets)
      // mySwitch.setProtocol(2);
    
      // Optional set pulse length.
      mySwitch.setPulseLength(311);
      
      // Optional set number of transmission repetitions.
      // mySwitch.setRepeatTransmit(15);  
    }
    
    void loop() {
      /* See Example: TypeA_WithDIPSwitches */
      mySwitch.switchOn("01010", "10000");
      Serial.println("Switch On");
      delay(10000);
      mySwitch.switchOff("01010", "10000");
      Serial.println("Switch Off");
      delay(10000);
    }
    

    I have not yet used sender or receiver while WiFi being active. Though I have been reading about issues while WiFi is active and receiving / sending via 433Mhz.