In this tutorial, we are going to create a wireless communication with Arduino using RF transmitter and receiver modules.
RF Receiver on the Right and RF Transmitter on the Left
The RF Transmitter and Receiver Modules are very small in dimension and have a wide operating voltage range (3V-12V). They operate at 315Mhz and can be used to transmit signal up to 100 meters (the antenna design, working environment and supply voltage will seriously impact the effective distance). It is good for short distance, battery power device development. The wireless transmitter and receiver can easily fit into a breadboard and work well with microcontrollers to create a very simple wireless data link. There are some module parameters for the transmitter and the receiver.
Transmitter module parameters
- Product Model: MX-FS-03V
- Launch distance :20-200 meters (different voltage, different results)
- Operating voltage :3.5-12V
- Dimensions: 19 * 19mm
- Operating mode: AM
- Transfer rate: 4KB / S
- Transmitting power: 10mW
- Transmitting frequency: 433Mhz
- An external antenna: 25cm ordinary multi-core or single-core line
- Pinout from left → right: (DATA; VCC; GND)
Receiver module parameters
Material List
As we want to design a system in which two Arduinos can communicate with each other, we need:
- 2 Arduino Uno boards
- 2 Soderless Breadboards
- One 315Mhz RF Transmitter
- One 315Mhz RF Receiver
- 6 Wires
Circuit Diagram
In this example, the RFreceiver and transmitter modules are connected separately to two Arduino boards. The transmitter data pin is connected to Pin 12 of Arduino and the receiver data pin is connected to Pin 11 of Arduino.
The circuit diagram(schematic) for the RF Transmitter part with Arduino is shown below.
The circuit diagram(schematic) for the RF Receiver part with Arduino is shown below.
There is also an image showing the actual wiring of the RF transmitter and receiver modules with Arduino.
Codes
To make the RF transmitter and receiver to communicate with Arduino, you need to download the VirtualWire library in your local Arduino library folder. Here is a link to download the VirtualWire library.
Below is a sample code using the VirtualWire library in Arduino for the RF transmitter.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/* SimpleSend This sketch transmits a short text message using the VirtualWire library connect the Transmitter data pin to Arduino pin 12 */ #include <VirtualWire.h> void setup() { // Initialize the IO and ISR vw_setup(2000); // Bits per sec } void loop() { send("Hello there"); delay(1000); } void send (char *message) { vw_send((uint8_t *)message, strlen(message)); vw_wait_tx(); // Wait until the whole message is gone } |
Below is a sample code using the VirtualWire library in Arduino for the RF receiver.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/* SimpleReceive This sketch displays text strings received using VirtualWire Connect the Receiver data pin to Arduino pin 11 */ #include <VirtualWire.h> byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message void setup() { Serial.begin(9600); Serial.println("Device is ready"); // Initialize the IO and ISR vw_setup(2000); // Bits per sec vw_rx_start(); // Start the receiver } void loop() { if (vw_get_message(message, &messageLength)) // Non-blocking { Serial.print("Received: "); for (int i = 0; i < messageLength; i++) { Serial.write(message[i]); } Serial.println(); } } |
Now you can upload the codes to their corresponding Arduinos with transmitter and receiver connected;) , but BE CAREFUL that you may want to change the port when plugging with a different Arduino and make sure the two RF modules have their correct corresponding codes.
After finishing uploading the codes, now you need to plug the Arduino with the RF receiver to your computer and give power to the Arduino with the RF transmitter(either plugging it to anther computer or to an external battery). Open the serial monitor for the receiver Arduino board and see how they can communicate!
Below is the sample text shown from the serial monitor of the Arduino with the RF receiver.
Thanks for reading!