Arduino and 433 MHz radio modules

Sometimes created projects require a wireless connection. One of the simplest and budget solutions for the organization of simplex (one-way) communication is the use of radio modules with a frequency of 433 MHz.
arduino-and-433-mhz-radio-module-1

Sometimes created projects require a wireless connection. One of the simplest and budget solutions for the organization of simplex (one-way) communication is the use of radio modules with a frequency of 433 MHz. In this article, we will analyze a simple example of their use in conjunction with Arduino.

To implement the project from this article, we need the following components:

  • Arduino Nano V3
  • 433Mhz receiver and transmitter kit
  • Breadboard
  • Jumper wires kit

For these modules to work, you need to solder an antenna to each of them, the recommended length is 17 cm. The operating voltage is up to 12 volts, but the 5-volt Arduino output is enough.

The range of work is directly dependent on the magnitude of the voltage.

It is worth noting that in cities, the communication range can be reduced due to the clogged frequency of 433 MHz – some signaling systems, radios, etc. work on this frequency.

Also, when using these modules with Arduino, there is one unpleasant moment – the impossibility of working with servo drives through the “Servo” library. The problem is solved using the library “ServoTimer2“.

So, the antenna is soldered, proceed to connect the modules. VCC of both modules is connected to 5v, GND to the Arduino terminal of the same name. You can power them from an external high-voltage power supply to increase the range.

To the 12th output of the transmitting board, we connect the DATA terminal of the transmitter, to the 11th output of the receiving board – either of the two DATA outputs of the receiver.

Next, we need to download the VirtualWire library:

DOWNLOAD LIBRARY

CODE FOR 433 MHz TRANSMITTER
After that we connect the transmitting board to the computer and load the following sketch into it:

#include

void setup(void)
{
vw_set_ptt_inverted(true);
vw_setup(2000); 
}

void loop(void)
{
int number = 123;
char symbol = ‘c’;

String strMsg = “z “;
strMsg += symbol;
strMsg += ” “;
strMsg += number;
strMsg += ” “;

char msg[255];

strMsg.toCharArray(msg, 255);

Serial.println(msg);

vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); 
delay(200);
}

A little bit about what this sketch is doing. We will send an strMsg variable of type String with the vw_send command. It is easier to work with this type, but before sending it you need to convert it to an array of characters with the toCharArray command.

All modules operate in the same range, so the receiver will receive data from all transmitters. To prevent receiving extra information, at the beginning of the transmitted message will record a prefix, for example, “z”.

The next part of the message is to send the “c” symbol, which can symbolize the end of the execution of any operation or a signal to the command execution by the receiver, and the number “123”, symbolizing its parameter.

CODE FOR 433 MHz RECEIVER
It is the turn of the receiver. Load the following sketch:

#include

void setup()
{
Serial.begin(9600);
vw_set_ptt_inverted(true); 
vw_setup(2000); 
vw_rx_start();
}

void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN]; 
uint8_t buflen = VW_MAX_MESSAGE_LEN; 

if (vw_get_message(buf, &buflen))
{
int i;
if (buf[0] != ‘z’)
{
return;
}
char command = buf[2]; 
i = 4;
int number = 0;
while (buf[i] != ‘ ‘)
{
number *= 10;
number += buf[i] – ‘0’;
i++;
}
Serial.print(command);
Serial.print(” “);
Serial.println(number);
}
}

First, Arduino reads the message in the buf buffer. Secondly, it will check the presence of the prefix “z”, in its absence the message will not be parsed. Third, it considers the “c” command and converts the character set to the number “123”. Fourth, Arduino will output the received information to the serial port. For more understanding in the sketch there are comments.

With the help of these sketches, you can only check the work of the radio modules. But they are not difficult to modify to transmit useful data, for example, the organization of remote control.

Share on facebook
Facebook
Share on google
Google+
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on pinterest
Pinterest