RC-Switch
by sui77
RC-Switch sends and receives fixed-code and rolling-code 433/315MHz signals used by cheap wireless remote sockets, garage door remotes, and DIY sensor transmitters. It handles the pulse-width protocol timing (the actual bit-banging of on/off durations) so you just call `send(code, bitLength)` or read `getReceivedValue()` for an incoming code. The catch that trips people up is receiver noise: without any transmitter nearby, a floating 433MHz receiver module picks up ambient RF noise and constantly reports garbage codes, which is normal and not a wiring fault — filter by checking a known code range or requiring repeated matching reads before acting on a signal.
Installation
Arduino IDE — Library Manager
Sketch → Include Library → Manage Libraries → search rc-switch
PlatformIO
lib_deps = sui77/rc-switchSupported boards
Examples
Send a fixed 433MHz code
Common pattern for controlling cheap remote-control power sockets.
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
mySwitch.enableTransmit(10);
}
void loop() {
mySwitch.send(5393, 24); // turn socket ON
delay(1000);
mySwitch.send(5396, 24); // turn socket OFF
delay(1000);
}Receive and print codes
Useful for sniffing an existing remote's code before replicating it in software.
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // interrupt 0 = pin 2 on Uno
}
void loop() {
if (mySwitch.available()) {
Serial.println(mySwitch.getReceivedValue());
mySwitch.resetAvailable();
}
}