Tyron78
Tyron78

Reputation: 4187

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...

Upvotes: 1

Views: 9377

Answers (5)

jak
jak

Reputation: 1

The answer from marekb helped me. I used GPIO2 though

pinMode(2, INPUT);
mySwitch.enableReceive(digitalPinToInterrupt(2));

I haven't yet tested any of the other examples.

Upvotes: 0

user14965388
user14965388

Reputation: 1

I finaly solve the problem with poor rc reception when wifi on the ESP32 is connected. The sollution that is working for me is to create more tasks. In 1 taks you put wifi stuff and other and into task 2 you put interupts and things you dont want to miss:

void setup(){
  //other things

  pinMode(GPIO_NUM_35, INPUT);
  mySwitch.enableReceive(digitalPinToInterrupt(GPIO_NUM_35));

  xTaskCreatePinnedToCore(loop2, "loop2", 4096, NULL, 1, NULL, 1);
  xTaskCreatePinnedToCore(loop1, "loop1", 4096, NULL, 1, NULL, 0);
}

void loop1(void *pvParameters) // Core 0
{
  while (1)
  {
    //task 1
    //wifi stuff
    Connect_to_wifi();

    delay(1);
  }
}

void loop2(void *pvParameters)// Core 1 loop
{
  while (1)
  {
    //task 2
    //RC stuff on interupt

    if (mySwitch.available())
    {
      Serial.print("Received ");
      Serial.print( mySwitch.getReceivedValue() );

      mySwitch.resetAvailable();
    }

    //other fast stuff
    delay(1);
  }
}

Upvotes: 0

Michel Durand
Michel Durand

Reputation: 1

The sender must have 5 V supply to go far, and it has not output pin which can damage the ESP32, and the receiver. Instead, must be connected to 3.3 V because it has an output which goes to ESP2 (3.3 V supply) and the output of the receiver must not be more than 3.3 V, so as not to damage the GPIO input of ESP32.

ESP32

  • The data sender(input) goes to: GPIO 5: pinMode(5, OUTPUT)
  • The data receiver (output), goes to GPIO 4: pinMode(4, INPUT)
  • Sender supply: 5 V
  • Receiver supply: 3.3 V (not to damage ESP32 GPIO 4)

Upvotes: -1

David Renner
David Renner

Reputation: 484

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)

  • You can use the ESP32-VIN for 5V if the Micro-USB is used to supply power
  • You may connect the Receiver-DATA to any ESP-32-Input-PIN BUT you might damage your ESP32 since it only allows ~3.3V
    • I tried first with some "makeshift" level shifting through resistors but I guess it lowers speed too much => A proper level-shifter (5V => 3.3V) might work out well
    • When referencing the PIN "xx" I have been just using the PIN-Number "Dxx" written on the ESP32-Dev-Board
  • You may connect an antenna of ~17.3cm to improve range
#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)

  • You can use the ESP32-3.3 to supply power
  • You may want to double check the PIN-Labels - I got confused because the DATA-Label was off and first interpreted as GND | DATA | VCC instead of GND | VCC | DATA
  • You may connect an antenna of ~17.3cm to improve range
#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.

Upvotes: 1

marekb
marekb

Reputation: 873

I know this is pretty old and maybe you've resolved the issue by now but maybe it will help others. I had the same issue and what helped me was to set the pinMode:

pinMode(GPIO_NUM_35, INPUT);
mySwitch.enableReceive(digitalPinToInterrupt(GPIO_NUM_35));

Upvotes: 3

Related Questions