433 MHz remote on an Arduino Uno
Two Unos and the FS1000A and XY-MK-5V pair, no wire between them: one sends a 24-bit code every two seconds with rc-switch, the other prints it through the receiver’s noise. The whole build, an Arduino Uno and 2 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Intermediate About 15 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $56. On Mokxi they're free.
What you'll learn
- Multi-board
- IoT
- Using the RF transmitter
- Using the RF receiver
- Difficulty: Intermediate
- Time: About 15 minutes
- Board: Arduino Uno R3
- Parts: 4
How it works
Two Unos and the FS1000A and XY-MK-5V pair, no wire between them: one sends a 24-bit code every two seconds with rc-switch, the other prints it through the receiver’s noise.
Arduino Uno R3 runs the sketch below. The circuit around it: RF transmitter, FS1000A, RF receiver, XY-MK-5V. delay waits 2000 milliseconds. Serial.begin opens the serial port at 9600 baud.
Parts list
4 parts, plus the jumper wires. They retail for about $56; on Mokxi they're free.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| RF transmitter, FS1000A pin GND | Arduino Uno R3 (1) pin GND |
| RF transmitter, FS1000A pin DATA | Arduino Uno R3 (1) pin 10 |
| RF transmitter, FS1000A pin VCC | Arduino Uno R3 (1) pin 5V |
| RF receiver, XY-MK-5V pin GND | Arduino Uno R3 (2) pin GND |
| RF receiver, XY-MK-5V pin DATA | Arduino Uno R3 (2) pin 2 |
| RF receiver, XY-MK-5V pin VCC | Arduino Uno R3 (2) pin 5V |
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// 433 MHz remote, the sending end.
//
// An FS1000A transmitter on pin 10 sends a 24-bit code every two seconds with
// rc-switch, the way a remote control or a wireless doorbell button does. The
// module has no chip: DATA high is the carrier on, DATA low is off, and
// send() makes every pulse of the code itself, then repeats the whole code
// ten times so the receiver can be sure of it.
//
// There is no wire to the other board. Every 433 MHz receiver on the canvas
// hears this transmitter.
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
unsigned long code = 5393;
void setup()
{
Serial.begin(9600);
Serial.println("433 MHz sender");
// The transmitter's DATA pin.
mySwitch.enableTransmit(10);
// Protocol 1 (350 us pulses) suits most remote sockets.
mySwitch.setProtocol(1);
}
void loop()
{
Serial.print("Sending ");
Serial.println(code);
mySwitch.send(code, 24);
code++;
delay(2000);
}
// 433 MHz remote, the receiving end.
//
// An XY-MK-5V receiver's DATA on pin 2, which is interrupt 0 on an Uno.
// rc-switch times every edge in an interrupt and takes a code once it has
// arrived twice the same way. That matters: with nothing sending, the
// receiver's DATA pin is random noise (open the logic analyzer on it and
// see), and only a real code repeats.
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup()
{
Serial.begin(9600);
Serial.println("433 MHz receiver");
mySwitch.enableReceive(0); // interrupt 0 is pin 2
}
void loop()
{
if (mySwitch.available()) {
Serial.print("Received ");
Serial.print(mySwitch.getReceivedValue());
Serial.print(" / ");
Serial.print(mySwitch.getReceivedBitlength());
Serial.print("bit Protocol: ");
Serial.println(mySwitch.getReceivedProtocol());
mySwitch.resetAvailable();
}
}
Code walkthrough
The key functions of the sketch, and what each one does.
setup sketch.ino
Runs once when the board starts. It gets the pins and libraries ready.
void setup()
{
Serial.begin(9600);
Serial.println("433 MHz sender");
// The transmitter's DATA pin.
mySwitch.enableTransmit(10);
// Protocol 1 (350 us pulses) suits most remote sockets.
mySwitch.setProtocol(1);
}loop sketch.ino
Runs over and over for as long as the board has power. This is where the project does its work.
void loop()
{
Serial.print("Sending ");
Serial.println(code);
mySwitch.send(code, 24);
code++;
delay(2000);
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- Upload fails or nothing runs after wiring pins 0 and 1 to a module. Arduino Uno R3
Pins 0 and 1 are the USB serial port. Move the module to other pins, or unplug it while uploading. Also check the right board is selected. - Pins misbehave or the board resets when you power motors or servos from it. Arduino Uno R3
Each I/O pin gives about 20 mA, 40 mA max. Power motors and servos from their own supply and join its ground to the Uno's GND.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.