Difficulty Level: Intermediate
In this tutorial, we will learn how to set up wireless communication between two Arduinos using 433MHz RF modules. These modules are widely used for wireless control systems and remote sensors. You can use them to send sensor data or control a device wirelessly.
Each RF module has a few important pins to connect:
The transmitter sends data to the receiver. You can use any data source such as a sensor or a control signal.
The receiver will capture the data sent by the transmitter and pass it to the Arduino for processing.
Here’s the code for both the transmitter and receiver to send and receive data wirelessly.
// Transmitter Code for Arduino (433MHz)
// Include the RadioHead library
#include
#include
RH_ASK driver;
void setup() {
Serial.begin(9600);
if (!driver.init()) {
Serial.println("RF Transmitter Initialization Failed!");
}
}
void loop() {
const char *msg = "Hello Arduino!";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(1000); // Send message every second
}
// Receiver Code for Arduino (433MHz)
// Include the RadioHead library
#include
#include
RH_ASK driver;
void setup() {
Serial.begin(9600);
if (!driver.init()) {
Serial.println("RF Receiver Initialization Failed!");
}
}
void loop() {
uint8_t buf[12];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) {
Serial.print("Message: ");
Serial.println((char*)buf);
}
}
To use the RF communication modules, you need to install the RadioHead library:
Sketch > Include Library > Manage Libraries
.With 433MHz RF modules, you can easily set up wireless communication between two Arduinos, allowing you to send data over a short distance without cables. You can use this for many projects like wireless sensors, home automation, or remote control systems.