Ever wonder how to implement wireless control on your project without spending too much of money? It is possible with cheap radio frequency (RF) module, consists of transmitter (Tx) and receiver (Rx). The RF module has to be used in pairs which are of the same frequency. Frequency of low cost RF module available are 315MHz and 433MHz.

rf4
433MHz Transmitter
rf3
433MHz Receiver

There are some pros and cons of this RF module.

Disadvantages:

– Unidirectional

– Limited bandwidth (baudrate)

– Limited range

– Picks up noise easily

Advantages:

– Available at low cost

The pin connections of transmitter and receiver are pretty simple. A basic transmitter and receiver will have these 4 pins as below:

rf9
Pin Connections

For the transmitter, connect the data on module to the Tx (Digital Pin 1) of Arduino. For the receiver, connect the data on module to Rx (Digital Pin 0) of Arduino. The supply voltage for transmitter can be in the range of 3V to 12V, the strength of data transmission is propotional to the supply voltage. This also means that if you use a larger supply voltage, the transmission of data can cover a bigger range. Looking at the receiver, the supply voltage is limited to 5V according to the datasheet. (Always check the datasheet of modules that you are using)

Some useful informations:

– Do not share the GND of transmitter and receiver.

– Use a 23cm antenna length for 315MHz module.

– Use a 17cm antenna length for 433Mhz module.

rf8
Transmitter connected to Arduino
rf7
Close look on Transmitter
rf6
Receiver connected to Arduino
rf5
Close look on Receiver

Since the RF module involves Tx and Rx, so it involves Serial communication here. I will show how to transmit and receive data in a simple way. Note that this method works but not very effective. Most of the wireless data need a data filter to filter out the noise.

Now lets look at the code for both transmitter and receiver.

Transmitter


//transmitter
#define button 2

byte data;
boolean state;

void setup()
{

pinMode(button,INPUT);
 Serial.begin(1200);
 data='0';
}

void loop()
{
 while(1)
 {
 state=digitalRead(button);
 if(state==LOW)
 data='A';
 else
 data='B';
 Serial.write(data);
 }
}

Code explanation:

The program initially send a data ‘0’ in function void setup().

In the void loop(), the program checks on the state of button. The program will send a different data according to the state of button pressed.

To send the data, use Serial.write(data). The data will be sent in a byte.

Receiver

byte incoming;

#define led 13

void setup()
{
 Serial.begin(1200);
 pinMode(led,OUTPUT);
}

void loop()
{
 while(1)
 {
 while(Serial.available())
 {
 incoming=Serial.read();
 if(incoming=='B')
 digitalWrite(led,HIGH);
 else
 digitalWrite(led,LOW);
 }
 }
}

Code explanation:

In the void loop() function, the program checks whether there is a data received. If there is a data received, Serial.available() will always be greater than 0.

The incoming is assigned to receive the data received. So to read the data, use Serial.read().

Basically this method is simple without any data filter part. You can further improve this with a better method or by using library. Stay tune for next explanation with library here. 😀

Advertisements