433Mhtz RF communication between Arduino and Raspberry Pi: Raspberry Pi as receiver

In this post we will see how to communicate data from an Arduino to a Raspberry pi over 433Mhtz RF protocol
Edit
In this other post: http://www.homautomation.org/2014/03/02/433mhtz-rf-communication-between-arduino-and-raspberry-pi-arduino-as-receiver/ I explain how to communicate from the Raspberry Pi to the Arduino using same method: 433Mhtz

Price: Less than $85

 

Sans titre-3

Needed Hardware.

ArduinoUno_r2_front450px

Arduino Uno

Price: less than $30 (Amazon)

300px-RaspberryPi

Raspberry Pi

Websitehttp://www.raspberrypi.org/

Price: less than 50$ (Amazon)

Mine is a B Model

rf433k

433Mhz RF link kit

Price: less than 5$ (<Amazon)

Choosing a lib for Arduino and Raspbery.

Tons of lib are existing to use RF transmiter/receiver – here is 2 which are interesting

I choose RCSwitch because of the Raspberry Version. And this lib is directly compliant with a lot of RF standard devices (I will make a post about that later)

Arduino.

The lib is responsive for everything and it is really easy to use. Download it here and add it to your Library folder.

Connect the emitter to the Arduino (on Pin 10)

Arduino

 

Here is the code to send message – Here we can send bytes with a common protocol hardcode in the lib.

#include 
 
RCSwitch mySwitch = RCSwitch();
 
void setup() {
  Serial.begin(9600);
  // Transmitter is connected to Arduino Pin #10  
  mySwitch.enableTransmit(10);
 
  // Optional set pulse length.
  // mySwitch.setPulseLength(320);
 
  // Optional set protocol (default is 1, will work for most outlets)
  // mySwitch.setProtocol(2);
 
  // Optional set number of transmission repetitions.
  // mySwitch.setRepeatTransmit(15);
 
}
 
void loop() {
  /* Same switch as above, but using decimal code */
  mySwitch.send(5393, 24);
  delay(1000);  
  mySwitch.send(5396, 24);
  delay(1000);  
 
  /* Same switch as above, but using binary code */
  /*mySwitch.send("000000000001010100010001");
  delay(1000);  
  mySwitch.send("000000000001010100010100");
  delay(1000);*/
 
  delay(2000);
  //mySwitch.send(4212181, 24);
 
}

 

Raspberry Pi.

On Raspberry Pi, the process is a little bit more complex. First install a Raspbian system.

Then we will need to install wiringPi. This lib allow to manage easily Raspberry GPIO.

pi@raspberrypi ~ $ git clone git://git.drogon.net/wiringPi
...
pi@raspberrypi ~ $ cd wiringPi/wiringPi
pi@raspberrypi ~/wiringPi/wiringPi $ sudo su
...
root@raspberrypi:/home/pi/wiringPi/wiringPi# ./build

Test the build

root@raspberrypi:/home/pi/wiringPi/wiringPi# gpio readall
+----------+-Rev1-+------+--------+------+-------+
| wiringPi | GPIO | Phys | Name   | Mode | Value |
+----------+------+------+--------+------+-------+
|      0   |  17  |  11  | GPIO 0 | IN   | Low   |
|      1   |  18  |  12  | GPIO 1 | IN   | Low   |
|      2   |  21  |  13  | GPIO 2 | IN   | Low   |
|      3   |  22  |  15  | GPIO 3 | IN   | Low   |
|      4   |  23  |  16  | GPIO 4 | IN   | Low   |
|      5   |  24  |  18  | GPIO 5 | IN   | Low   |
|      6   |  25  |  22  | GPIO 6 | IN   | Low   |
|      7   |   4  |   7  | GPIO 7 | IN   | Low   |
|      8   |   0  |   3  | SDA    | IN   | High  |
|      9   |   1  |   5  | SCL    | IN   | High  |
|     10   |   8  |  24  | CE0    | IN   | High  |
|     11   |   7  |  26  | CE1    | IN   | High  |
|     12   |  10  |  19  | MOSI   | IN   | High  |
|     13   |   9  |  21  | MISO   | IN   | High  |
|     14   |  11  |  23  | SCLK   | IN   | High  |
|     15   |  14  |   8  | TxD    | ALT0 | High  |
|     16   |  15  |  10  | RxD    | ALT0 | High  |
+----------+------+------+--------+------+-------+

Ok, wiringPi is well installed

Then I found out an interesting project called 433Utils. This project is just perfect for our use case. We will build it.

root@raspberrypi:/home/pi/wiringPi/wiringPi# cd ../..
root@raspberrypi:/home/pi/# git clone https://github.com/ninjablocks/433Utils.git
...
root@raspberrypi:/home/pi/# cd 433Utils/RPi_utils
root@raspberrypi:/home/pi/433Utils/RPi_utils# ./make
....

Ok we are ready. Let connect the raspberry (Data will be connected to GPIO 2 – pin 13 on the header – take a look here)

RPi

 

Warning: no not forget the Antenna! – a simple 20cm wire will do the job

Testing all

Now it is time to start to test all the system.

Start RFSniffer on the Raspberry Pi

root@raspberrypi:/home/pi/433Utils/RPi_utils# ./RFSniffer

Ok now, Raspberry Pi is ready to receive command. Start the Arduino…
final

Next

Plans for next steps are

  • Sniffing existing devices to reverse command signal
  • Using this communication way to send data from Arduino sensor (such as electrical consumption sensor) to Raspberry in order to monitor sensors from the web.

80 Comments

    • ok, sorry, I could download them, but not, when I want to execute them, I have this error:

      vortice104@DarkFiles:~/Downloads/RF/433Utils-master/RPi_utils$ gcc RFSniffer.cpp
      RFSniffer.cpp: In function ‘int main(int, char**)’:
      RFSniffer.cpp:42:63: warning: format ‘%i’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat]
      /tmp/ccV6HtKH.o: In function `main’:
      RFSniffer.cpp:(.text+0x12): undefined reference to `wiringPiSetup’
      RFSniffer.cpp:(.text+0x32): undefined reference to `RCSwitch::RCSwitch()’
      RFSniffer.cpp:(.text+0x74): undefined reference to `RCSwitch::enableReceive(int)’
      RFSniffer.cpp:(.text+0x83): undefined reference to `RCSwitch::available()’
      RFSniffer.cpp:(.text+0x93): undefined reference to `RCSwitch::getReceivedValue()’
      RFSniffer.cpp:(.text+0xb8): undefined reference to `RCSwitch::getReceivedValue()’
      RFSniffer.cpp:(.text+0xd4): undefined reference to `RCSwitch::resetAvailable()’
      /tmp/ccV6HtKH.o: In function `__static_initialization_and_destruction_0(int, int)’:
      RFSniffer.cpp:(.text+0xf9): undefined reference to `RCSwitch::RCSwitch()’
      collect2: error: ld returned 1 exit status

      Why I have these undefined references??

      Thank you,

      Miguel A.

      Reply
  1. Hi Vincent.

    Thanks for this tutorial. I did everything like you but the raspberry is unable to get anything!
    I tried Arduino to arduino it is ok, but Arduino to raspberry nok.

    I was wondering about how you power the RF modules? With a specific power or from raspberry? Also about the rights of files on raspberry you need to add excecute rights?

    Thanks for your help

    Reply
      • Hi,

        Do I have to solder a wire to the transmitter and another to the receiver? I tried to use a pair of connection cables without soldering them but I don’t get any communication. I guess the reception is too bad but which I could confirm it. I lack metal wires I can solder. 🙂

        BR,
        Fanten

        Reply
      • Hello
        Thank you Vincent Demay
        Nice tutorial and nice explained.
        On the picture with the RF Receiver which Pins you exactly use it looks like you are using V+ on 5V pin?
        I think V+ should on 3.3V not?
        Because Data output will be also 3.3V.
        And Input Max Voltage should be 3.3V or am I wrong?
        GND ond GND
        Data on Input pin 13 (gpio 2)

        I am just asking because on 3.3V Receiver with a antenna i reach just about 5-10m.
        Thanks

        Reply
        • Hello James,

          Yes I plugged the receiver to the +5V on the Rasperry Pi. This kind of 433Mhtz Receiver can be powered with 5V and more: Device on Amazon

          The operating voltage is 3.5V – 12V. Higher the power voltage is, longer is the range. Anyway this kind of module are not designed to be used with long range (40m max @ 12V)

          Hope this help, Best,

          Reply
          • I htink he was not refering to the module but to the raspberry pi data io pins. They can only support 3.3V! If you put your receiver on 5V, the data io pin of the raspberry will also receive 5V which is way ot high. A simple resistor (4.7k) should be fine, as already outlined in many forum posts (regarding rpi and 5V data pin topic).

          • I am concerned about connection the receiver module to 5V as for the same reason as “romgen” stated in his post on July 31, 2014 at 4:07 pm. I googled a lot and just read the advice to use a level shifter or build a voltage divider via resistors. I don’t wanna spend money on the level shifter and I am worried that a simple voltage divider might cause problems in fast communications. @romgen: Could you post corresponding links to tutorials how to attach this 433MHz receiver powered with 5V eactly via a 4.7k resistor to Raspi? Would help me a lot, thank you so much.

  2. This tutorial is a mess…
    “pi@raspberrypi ~/wiringPi/wiringPi $ sudo su

    root@raspberrypi:/home/pi/433Utils/RPi_utils# ./build”
    did not clone the 433Utils…how is it gonna build..
    recheck your commands

    Reply
  3. so any idea for sending bytes (e.g. strings) ? I have searched and searched and found nothing 🙁 I have 4 arduinos – temperature senders (RF) and RPi as webserver and arduino as RF receiver. My receiver arduino gets info from other arduinos and sends to RPi by wire. I’d really like to eliminate the receiver arduino and use RPi as a RF receiver / (other)cmnd sender. Any ideas ? 🙂

    Reply
  4. Hi Vincent,

    Thanks for this tutorial, in one hour I was able to communicate beetween Arduino and Raspberry Pi.

    But I have an issue and I don’t know where the bug comes from arduino or Raspberry. In fact, when I launch the RFSniffer, I have always the 3 same values writting in the console.

    I have modified the arduino code in the aim to send a static integer by RF. This integer is incremented each a value is sent.
    And this is the result :
    Received 1
    Received 1
    Received 1
    Received 1
    Received 2
    Received 2
    Received 2
    Received 3
    Received 3
    Received 3
    ….

    Have you the same problem ? Do you known where the bug comes from ?

    Reply
    • Hi SnowPatrol,
      As a RF emitter, the Arduino sent several time the same command. This is done because RF protocol has no acknowledge, to be sure that data is really received.
      Best

      Reply
        • Hi SnowPatrol.
          There isn’t any acknowledge on a basic RF communication. Anyway, you can mount a receiver and an emitter on each device in order to confirm the message is received.

          Reply
  5. Hi Vincent.
    Nice tutorial.
    I was wondering if raspberry pi could be used as a transmitter and arduino as a receiver. As a 14 year old arduino programmer,i have no experience in raspberry pi.
    Thanks in advance.

    Reply
  6. Is it possible to send and receive information by raspberry? And is it possible to create some webapp to execute these commands? (sorry for my english)

    Reply
      • Would be possible to do this comunication with a raspberry pi and many arduinos? The raspberry pi would be the brain and it would send informations to arduinos. And the arduinos can send informations to raspberry too.

        Reply
        • Hi
          I’ve tried to have the send and receive on the same board connected to my raspberry pi. So far, i did not managed to have the sniffer able to receive, it never meet the “if (mySwitch.available())” condition. As the two transmitters are very close, i’ve no antenna.
          Is there some special set up of the pi to be done to have it working?
          Many thanks in advance for help
          Lucio
          PS. I’ve already posted yesterday, but i do not see my post.

          Reply
          • Hi Lucio,

            Sorry, I took some time to moderate your previous comment.
            It is possible you get some conflicts between both devices on the same RPi. You should try with 2 Rpis or with a Arduino.

            Best,

  7. Just wondering, is the dta not 5V? If connected to the PRI GPIO does it not burn the poor little rasperry? Ive read a lot about that on the net, but are still not sure if it actually works or not!

    Reply
  8. Hi, I try to do the reverse. I want to use the raspberry as emitter and the arduino as receiver but i don’t know witch library to use, and witch raspbian function tu use to send simple caracter like “1” or “a” .

    Reply
  9. Thanks for your tutorial Vincent,
    It worked fine for me but I have still one question: Why do we get more than one “Receive data:”, even though we just send the value once? Is there a chance to limit the messages sent to just one (as it would be easier to do any further tasks with that data on Raspi without any “filtering”, even though a message might be lost because of interrupted transmission).
    Thanks
    Michael

    Reply
  10. Hi,
    With the antenna I can only reach a range of 3m.
    In order to increase this range I tried to power the receiver with an external 5v charger (that means that only the data pin is connected to the raspi). A LED connected to the data pin show me that data are received, but no data are displayed by the raspi. What should I do to use external power?

    Reply
    • Connecting the gpio GND of raspi to the – of power solve the issue.
      By the way I have now 3cm range, I’ll have to check my antenna.

      Reply
  11. I couldn’t run the following comand:
    root@raspberrypi:/home/pi/433Utils/RPi_utils# ./make

    The following notofication appears:
    bash: ./make: No such file or directory

    I’ve listed and nothing like “make” appeared. Have I downloaded a corrupted directory? (sorry by my english)

    Reply
  12. Hi, I followed your tutorial, it worked worked perfect.
    How would i go getting a python script on the raspberry pi to read the output to store in a my-sql database or something similar.
    the sniffer worked a treat but it doesn’t allow it to be used in anything else. thanks in advance for any help you can provide 🙂

    Reply
  13. Hello;
    I’ve tried to put the emitter and the receiver on the same raspberrypi (just to test), and i do not receive any data. I’ve put leds that give me the impression something happens, at least for the send part. Is there something special to have this config working.
    Thanks in advance
    Lucio

    Reply
    • Thanks for the answer, and sorry for the double post,
      Regarding msg, it was yesterday in “waiting for moderation”, then was no longer there.
      unfortunately, i’ve not a second pi, or arduino.
      I need to find an external emitter, and double check, the receiver only.
      But which kind of conflict can i face, and how to troubleshoot it? any idea.
      Lucio

      Reply
    • Hello,

      I followed this tutorial, but unfortunately it doesn’t work for me, I can’t receive anything from the raspberry pi.

      What is working:

      – The same arduino sketch on my first arduino works perfectly with the ReceiveDemo_simple sketch on a second arduino (with the rc-switch library)
      – 2 arduinos with the virtualwire library (both with or without extra antenna)

      So I guess the problem is with the raspberry pi 🙂

      I also tried your other tutorial (from rpi to arduino), it doesn’t seem to transmit from the raspberry. I also used an external 5V supply for powering the receiver module, it’s the same.

      I’m using a raspberry B+, with the new gpio, but I kept the required GPIO number (2). I’m also using the latest wiringpi library (2.21), maybe it raised some incompatibility with older code? What do you think?

      Reply
  14. We are working on a school project when we came across your blog. We were wondering whether it would be possible to send video information from an arduino to a raspberry pi and display it live on an attached lcd screen. Thanks!

    Reply
  15. Hi Vincent,

    Thanks for such a great tutorial. Learnt a lot of things from the blog. However I am getting a strange issue, everything runs very fine and smooth if I use “Arduino Leonardo” As Emitter and “Raspberry Model B” as receiver. But if I use “Raspberry Model B” as Emitter than I face a huge data loss, if I run the “codesend” command 50 times via script, then <=5 signals are received as arduino. Even with 1000 codesend, data received is <=100 signals.

    May be I am doing some silly mistake, but not able to resolve it so far. Kindly help.

    Reply
    • Hi,

      I’ve already get this kind of issue, it seems to because of some noise somewhere on the Arduino or on the Raspberry. Try to put the sender or the receiver less close to the rest of the hardware.
      I’ve also fixed this kind of issue soldering a different wire as antenna.

      Hope this help.

      Reply
      • Hi Vincent,

        I attached approx 1 meter wire between Pi and Tx, attached 1 meter wire between Arduino and Rx, Tx and Rx were 10-15 cms apart and had a 15-20 cm wires on both as antenna.

        I worked perfectly once, then I had to restart my Pi and since then its not working again. Can’t figure out what happened to it. As usual, the reverse setup is running without any problem at all.

        Reply
  16. Hello,
    I am a noob in raspberry – raspbian environment. I have followed each step and at the end, when launching RFSniffer it says wiringPisetup: must be root
    Please help.

    Reply
  17. Hey Vincent,

    I really liked your tutorial.
    I am current working on the same project but I need it to transmit over 1km. Any advise on where I can start? Would this be even possible with more expensive transmitters and receivers?
    Not sure about the Pi and Arduino Limitations.

    Thanks,
    Shiva

    Reply
  18. Hello Vincent,
    In your next steps, you talk about “Sniffing existing devices to reverse command signal”, have you made progress on this?
    Best
    Lucio

    Reply
  19. HI Vincent

    Thank you for the tutorial. Sniffing works well. When the guys struggle with receiving signals they must check their antennae and move the transmitter closer if they still don’t pick up signals.

    My question here, I would like to use a Raspberry Pi to constantly monitor for signals from possibly various transmitters and hopefully do something with specific signals received. I would have to “catch” the signal somehow with the Pi, compare it and issue a command using something like an if statement – probably using BASH or Python. Can you maybe guide me in the right direction?

    Thank you once again

    Reply
  20. Hello,
    i like your work.
    Could you help me pleace, how can I remove the word “Received” in the RFSniffer and how can I save the received information. I hope you can help me and thanks for your answer.

    Reply
  21. Hi all,
    I am fairly new to Arduino but have had a basic experience with python on RPi (Model 2). I am trying to connect ultrasonic sensors (for distance measuring) on Arduino and then send (RF transmission) the value to Raspberry Pi. I am not able to figure out how to write a code for receiving the transmitted code. I have to receive the code, decode it and then update it in my SQLITE database (on the same RPi).

    I have already tried RFSniffer but I am unable to receive value other than “INT”. RPi shows nothing if I send any “CHAR” or “STRING”.

    Please do suggest me how should I proceed.

    Thanks in advance

    Pradeep Verma

    Reply

Leave a Comment.