Get your 315/433Mhz RF Link Kit to work with Arduino

400px-315433MhzRFlinkKitWhile scouring the ‘net for information on some sensors I purchased, I came across a listing for a transmitter/receiver combination that was dirt cheap. Interested, I bought several pairs and have finally gotten them.  Of course, I quickly discovered that there’s little information and even less code that works with them. So, I am writing up a quick little article on how to use them with the Arduino.

The transmitter/receiver pair operate at 433Mhz and have a relative pair that operate at 315Mhz, this information should work for that pair as well.

Both parts, the transmitter and receiver, are very simple and very small.  The receiver has four pins, the transmitter has three pins. 

For the receiver, the pins are as follows:

Looking at the component side of the board, the pin closest to the edge is GROUND. The two middle pins are data and do the same thing (that is, it doesn’t matter which one you use, only one is needed) and the last pin is POWER, +5 volts.

For the transmitter:
  • Looking at the component side of the board, the middle pin is +5 volts, the right most pin is GROUND and the left most pin is DATA.

The boards are all marked, so you can use them for reference.

You will also need two Arduinos: one to transmit and one to receive.

On the transmitter:
    • Connect the DATA pin to PIN 8 on your Arduino (or, any of the digital pins, just make note of the pin you use.)
    • Connect GROUND to GND on the Arduino
    • Connect VCC to your +5 volt pin.
On the receiver:
    • Connect DATA to PIN 3
    • Connect VCC to +5 volts
    • Connect GND to GND

You will to download the RCSwitch library from here. Import the library into Arduino’s library using the IMPORT function.

The code I am using on the TRANSMITTER sends temperature and humidity data from a DHT11 sensor to the receiver Arduino:

/*
  You will need the following library:
 
http://code.google.com/p/rc-switch/ by @justy 
*/

#include <RCSwitch.h>      // Library for the transmitter
RCSwitch mySwitch = RCSwitch();

#include <TinyDHT.h>       // Library for the temp sensor
#define DHTTYPE DHT11      // DHT 11-our sensor
#define TEMPTYPE 1         // Use Fahrenheit (0 for celsius)
#define DHTPIN 2           // Sensor connected to GPIO #1 (use a
                           // 1K ohm pullup to 5V to make it work!)
DHT dht(DHTPIN, DHTTYPE); // Define Temp Sensor

void setup()
{
   Serial.begin(9600);
  // Transmitter hack- use the following if you plan to use my easy transmitter connection hack
  // VCC  : +5
  // GND  : GND
  // Data : 8 
  pinMode(8, OUTPUT);  // We’ll use pin 8 to drive the data pin of the transmitter.
  dht.begin();  // Initialize DHT Teperature Sensor
  // Transmitter is connected to Arduino Pin #8 
  mySwitch.enableTransmit(8);
}

void loop()
{
        int8_t h = dht.readHumidity();               // Read humidity
        int16_t t = dht.readTemperature(TEMPTYPE);   // read temperature
        // Send your data code every 5 seconds.
        mySwitch.send(t,24);
        mySwitch.send(h,24);

        delay(5000);
}

The relevant lines of code are highlighted. You can send any data, I was using temp and humidity data in this example.

Now, on the receiver:

#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();

void setup() {
  Serial.begin(9600);
  pinMode(3,INPUT);
  mySwitch.enableReceive(1);  // Receiver on inerrupt 1 => that is pin #3
  }

void loop() {
 
  if (mySwitch.available()) {   
    int value = mySwitch.getReceivedValue();

    if (value == 0) {
      Serial.print(“Unknown encoding”);
    } else
    {
  
      Serial.print(“Received “);
      Serial.print( mySwitch.getReceivedValue() );
      Serial.print(” / “);
      Serial.print( mySwitch.getReceivedBitlength() );
      Serial.print(“bit “);
      Serial.print(“Protocol: “);
      Serial.println( mySwitch.getReceivedProtocol() );
    }
   
    mySwitch.resetAvailable();
   
  }

}

This code is rather generic, it simply displays whatever it received.  Again, the relevant code has been highlighted for you.  The transmitter is set to send its data every five seconds, but you can change that for as often as you like. 

There’s all kinds of uses for these cheap pairs.  A local wireless net of sensors, wireless controllers, game links, etc.  I don’t know the range on them, as I’ve only used them on my desk, but they have connections for antennas, so you can solder about 15mm of wire to each to make an antenna. The boards are marked for them as well.

Some sites mention and show the VirtualWire library being used to control these things, but I could not get them to work. So far, only this RCSwitch library has worked.

Have fun with these and let us know what you are doing with them.

Advertisements

4 thoughts on “Get your 315/433Mhz RF Link Kit to work with Arduino

  1. Hi!
    I try your code, but the serial monitor n the o receiver does’t display temperature and humidity but only “Received62 / 24bit Protocol:1″…..why??

    • Post the code that you used, if you will. I have found that the WordPress theme I am using has mangled some of the code I have posted. If I can see what yours looks like, I may be able to help.

      • Hi! I can’t send temperature AND humidity in the “receiver” in two different row, unfortunately i lost my cod 😦 but my question is: how i can send many different value in many different row (by the “serial print)? how i can receive many different value in this format:

        “something text” value 1
        “something text” value 2
        “something text” value 3

        other question is:
        can I use the posted cod for send (and receive) the output of a US sensor ?

        thank you very much!!!
        Michele

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s