[Raspberry Pi - Arduino ]Lamp Switch [Raspberry Pi – Arduino ]Lamp Switch[/caption]
A month ago we planned to manage our Arduino irrigator (aka Irrigatorino) through the NRF24l01+ wireless  module. Our little project has been subjected to a little change, since we decided to make our life easier (buahahah…) and remote control a light over a browser (yes, mobile too). Surprisingly, a lot of people liked the little demo I’ve made with some raw code and asked for a tutorial, so here we are:

Ladies and (more probably) Gentleman, I’m glad to present  you the lamp driven by a browser switch!

Nothing new actually, but still exciting!

Arduino Nano 328 connected with NRF24l01+ module and Lamp

Arduino Nano 328 connected with NRF24l01+ module and Lamp (in the background)


To test the wiring we suggest you to use the ping/pong test you can find  in the RF24 libraries (both, of the raspberry and the arduino).

Raspberry Pi

The connection between the Raspberry Pi and the NRF24l01+ module was a little bit tricky, so you have to double ( or triple) check the wiring before giving up. Here is the wiring scheme, the Raspberry Pi is a revision 2, and the module is the + (plus) version.

Raspberry Pi (rev2) - NRF24l01+ Diagram

Raspberry Pi (rev2) – NRF24l01+ Diagram


The setup is easy and similar to a mix of our tutorials about Irrigatorino and NRF24l01+ Tests.
Just keep in mind that you are playing with dangerous voltage, so if you get struck, it’s only your fault. I would suggest, anyway, to check if everything (especially the relay board) is working with a multimeter, before connecting to a real lamp.

Arduino Nano - NRF24l01+ - Lamp Diagram

Arduino Nano – NRF24l01+ – Lamp Diagram


Our plan to communicate between all this stuff is to use a Node.js application to run a binary ‘./switch -f On‘ and ‘./switch -f Off‘  sending a message to the Arduino with the text 1 and 0 .
When the arduino receive it, it then sends back an acknowledgment packet to the raspberry with the same message (yeah, like a parrot). In the meantime, if the message the arduino receive is 1  it will close a relay (turning on a light, like a good parrot), otherwise it will open it (I doubt a parrot could be so clever).


The sketch for the Arduino Nano is nothing more than a Getting Started demo of the RF24 library. We just modified it to switch the relay on in case it receive a message with 1 as text, or open it otherwise. Of course you’ll need the RF24 library to make it work.


Enabling Raspberry Pi GPIO and Installing Node.js

First we enable the Raspy GPIO:

Method 2 (not tested, but should work):

Let’s install node.js.
If you don’t need the latest version you can install it from the repos:

Otherwise you can follow this instructions (under Ubuntu, Mint… section) to compile the latest version.

The Lamp Switch Application

What we need now is to write an application that will send a message to the arduino using the NRF24l01+ and the Raspi. So the first thing to do is download the RF24 library ported for Raspberry Pi.  I would suggest to use git.

Now let’s install the library:

NOTE: please note that the author has recently changed the library folder’s name, if you encounter some problems while compiling or using it, let me know. I’ve just changed the names but didn’t have the time to test it.  If you would like to be so kind to propose a fix, we would all love you a little more.


And now we create the switch application,which will be the main binary we will use to send message to the arduino.

We compiled the Raspberry RF24 communication module on our Raspberry and you can find it on github:

Or you can compile it by yourself using the cpp file or creating a new file called remote.cpp in the ~/RF24/RPi/RF24/examples folder and past this code inside:

And now compile the application:

If everything went well you should be able to turn on (and off) the relay at this point using the ./remote -m 1  or 0 application, hearing the famous ‘click’ from the relay board.

We’ve left the debug printout in the code so you can easy arrange a solution in case of some bugs.

The Node.js Lamp Application

At  this point the only thing left is to build a little node.js server and bind a click  on a client browser to an exec function on the raspberry server.

Since it’s more than just a file, we’ve placed  a link to the repository on github. All the code is commented, so I hope everything is clear.

We are using git submodule to add the base node application RemoteRaspberry.  So here is a list of commands to clone the repo:

Anyway, since we were a little bit confused on our first node application we’ve decided to write down a little note to help you understand:

- lightSwitch.js   => is a link to the application  (remote.js) you need to run with “sudo node lightSwitch.js” (the sudo is NEEDED). This is the web server and will launch the client interface too.

  • views (folder) => contains the main layout and the basic template.

- routes.js => contains the route to the template.

  • RemoteRaspberry (folder) => the basic node app, which contains:

  • package.json => required modules (with version) you need to run the application

  • node_modules (folder) => it’s an auto generated folder which contains the modules

  • public  (folder) => contains remoteClient.js, the javascript code loaded on the client and bootstrap folder for styling

  • remote.js => the actual node app


To run the application you need to:


Authors note (31/3/2014)

We love the way you support each other in the comments! It’s really a satisfaction for us.
We can’t be always here to answer your questions or doubts, and all your contributions are a really great value you add to this website.
Thank you all!

Update  (10/5/2014)

We’ve refined a bit the code, making it more clean and definitely more readable. All you have to do now to add new buttons, is to create a new button in the node app views giving it a data-command tag. The value of that tag will be automagically passed to the old switch -f  binary (now called remote -m). Of course you still need to tell arduino how to interpret the message.  No more c++ recompiling.  Plus, we’ve made the web interface give you a visual feedback when the raspberry receive the ack package from arduino.


Update  (27/8/2014)

Looks like the Rf24 library author has changed the folder’s name. I’ve tried to fix the article with the new names. Didn’t have time to check it yet. Let me know if everything is ok. Edo.


Have Fun!





Post a comment
  1. Esaú #
    November 13, 2014

    Does anyone know how can I turn on a led on my Raspi?
    I tried to include the “wiring pi” library to my code with “FR24″ library, but it didn’t work. I would like to get some help :(

    • November 16, 2014

      Just to be sure, did you include the FR24 library or it is just a typo? Because the real name is RF24

      • Esaú #
        November 23, 2014

        hoo! jaja it was my mistake, but yes the name of the library is RF24, it seems like all going well, I’ve already sended data from an arduino to my rasp, but I want to do the same thing like your post, but, on the contrary, the transmitter (arduino), and reciver (raspberry pi)

  2. Andrea #
    October 30, 2014

    I tried to make a receiver using the same library but I can’t make it working..

    I don’t understand why it seems that the application doesn’t take the settings writed in the start of the block:
    in the block start I see:
    pipes = [[0xf0, 0xf0, 0xf0, 0xf0, 0xe1], [0xf0, 0xf0, 0xf0, 0xf0, 0xd2]]
    and other things.
    When I start the script I see a warning message:
    nrf24.py 373: RuntimeWarning: This channel is already in use, continuing anyway. USE GPIO.setwarnings(False) to disable warnings. GPIO.setup(self.ce_pin, GPIO.OUT)
    Then I see the initial settings differs: I see RX ADDRP0-1= 0x0000000000 0x0000000000
    data rate 1mbps
    Then I see a bunch of random strange chars..
    I have to say that, using the RF24 c++ version I have the same effect (bunch of chars).
    Have you got some ideas about my problem?

    Thank you so much,

    • Esaú #
      November 23, 2014

      If you want describe what do you want to do?, i’ve heard the python library is not good, it has some bugs, and did you follow the instructions at the begining in this post?

  3. Fabian Kluge #
    October 28, 2014

    Great project,
    I only got one problem left and would be really thankful if someone could help me: When i start the server with “sudo node lightSwitch.js” i can access the website via another computer. But when i click one of the two buttons the terminal on the raspberry gives me an error: “librf24.so.1 no such file or directory”. In the RF24 Library i have a librf24.so.1.0 and a librf24-bcm.so.1.0. I have no idea what i have to do to get this going. Maybe theres something i need to do different since i have the B+ Raspberry version.
    Thank you!

  4. Guille #
    October 26, 2014

    Finally i could run the program. I do some changes to the code.

    First change the “__msleep(10)” to “sleep(0.01)” and the “__millis()” to “millis()”

    Then change the command line to compile
    g++ -Wall -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -L../librf24/ -lrf24 remote.cpp -o remote
    g++ -Wall -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jz -L../ -lrf24-bcm remote.cpp -o remote

    And an other change
    RF24 radio(“/dev/spidev0.0″,8000000 , 25);
    RF24 radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);

    I hope that help someone

    • Guille #
      October 26, 2014

      g++ -Wall -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -L../ -lrf24-bcm remote.cpp -o remote

      • patricio #
        October 28, 2014

        did you get it to work that way? i did made that changes, it means i have to change the CE pin on the nrf24 to pin 15(GPIO25) i am not having any readings in the pi.

    • Guille #
      October 29, 2014

      Yo no uso éste código exactamente, tengo hechos bastantes cambios para adaptarlo a mi proyecto, pero creo que con los cambios que he dicho debería funcionar.
      Tengo usados los mismos pines que dice la página.


      I dont use this code, i did some changes to my proyect, but i think that must work. I use the same pin of the image and work.

    • Marco #
      November 10, 2014

      Any thoughts on this is much appreciated.
      Adjusted the remote.cpp code (First change the “__msleep(10)” to “sleep(0.01)” and the “__millis()” to “millis()”) but got a few errors during the check.
      Arduino: 1.0.6 (Mac OS X), Board: “Arduino Nano w/ ATmega328″
      remote.cpp: In function ‘bool switchLight(int)':
      remote.cpp:57: error: ‘sleep’ was not declared in this scope
      remote.cpp: In function ‘int main(int, char**)':
      remote.cpp:87: error: ‘getopt’ was not declared in this scope
      remote.cpp:95: error: ‘optarg’ was not declared in this scope
      The mod code is now:
      //Let’s take the time while we listen
      unsigned long started_waiting_at = millis();
      bool timeout = false;
      while ( ! radio.available() && ! timeout ) {
      if (millis() – started_waiting_at > 1000 )
      timeout = true;
      Not sure what is meant by …’sleep’ was not declared & how to fix it.
      Also saw the ‘get opt’ ‘optarg’ errors. Again not sure what this means & now to fix them.
      That code is as:
      while(( choice = getopt( argc, argv, “m:”)) != -1){
      if (choice == ‘m’){

      printf(“\nOpening the gates…\n”);
      while(switched == false && counter < 5){

      switched = switchLight(atoi(optarg));
      counter ++;


  5. Photobook #
    October 7, 2014

    You should take part in a contest for one of the
    highest quality blogs on the internet. I most certainly will recommend this website! Go on like this guys!

  6. Kason #
    October 6, 2014

    The Git repository folder no longer offers the librf24. It only has librf24-bcm which does not seem to work

    • Kason #
      October 7, 2014

      With the new files coming out of git for rpi use gpio22(pin15) for ce that fixed the problem for me.I can now receive on the rpi(still having issues sending)

    • Kason #
      October 13, 2014

      for anyone having trouble..the -bcm library files uses a different pin out. Also if you aren’t receiving data on the arduino, try increasing the data rate to 2mb on the wifi transmission. For some reason this works better than the 1mb setting.

  7. September 29, 2014

    I got this remote file working on my computer so you can give it a try go to the following link

    • September 30, 2014

      Sorry I mistakenly put the wrong remote file just updated to the new one

      • pepeu #
        October 3, 2014

        Thanks! Now I got the remote working, but then I’m stuck again. My B+ shows me this:

        pi@raspberrypi ~/RF24/RPi/RF24/examples $ sudo ./remote -m 1

        Preparing interface
        ================ SPI Configuration ================
        CSN Pin = CE0 (PI Hardware Driven)
        CE Pin = Custom GPIO25
        Clock Speed = Probably Bad !!!
        ================ NRF Configuration ================
        STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
        RX_ADDR_P0-1 = 0xf0f0f0f0e1 0xf0f0f0f0d2
        RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
        TX_ADDR = 0xf0f0f0f0e1
        RX_PW_P0-6 = 0x20 0x20 0x00 0x00 0x00 0x00
        EN_AA = 0x3f
        EN_RXADDR = 0x03
        RF_CH = 0x4c
        RF_SETUP = 0x07
        CONFIG = 0x0f
        DYNPD/FEATURE = 0x00 0x00
        Data Rate = 1MBPS
        Model = nRF24L01+
        CRC Length = 16 bits
        PA Power = PA_MAX

        Opening the gates…
        Now sending 1…failed.
        Failed, response timed out.
        Now sending 1…failed.
        Failed, response timed out.
        Now sending 1…failed.
        Failed, response timed out.
        Now sending 1…failed.
        Failed, response timed out.
        Now sending 1…failed.
        Failed, response timed out.

        I have their GettingStarted on my Arduino with a led at pin 8, but nothing.

        Any ideas?

        • pepeu #
          October 3, 2014

          My Arduino gives me:

          Light Switch Arduino

          STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
          RX_ADDR_P0-1 = 0xf0f0f0f0e1 0xf0f0f0f0d2
          RX_ADDR_P2-5= 0xc3 0xc4 0xc5 0xc6
          TX_ADDR = 0xf0f0f0f0e1
          RX_PW_P0-6 = 0x20 0x20 0x00 0x00 0x00 0x00
          EN_AA = 0x00
          EN_RXADDR = 0x03
          RF_CH = 0x4c
          RF_SETUP = 0x07
          CONFIG = 0x0f
          DYNPD/FEATURE = 0x00 0x00
          Data Rate = 1MBPS
          Model = nRF24L01+
          CRC Length = 16 bits
          PA Power = PA_HIGH

        • October 7, 2014

          did you open the spi on raspberry pi if no then follow this by default spi is not enabled on raspberry pi.

          sudo raspi-config
          go to advanced and have spi run every time raspberry pi boots hope that helps

          let us know if that helps

          • October 7, 2014

            also after enabling spi reboot and then


            sudo apt-get update
            sudo apt-get upgrade

            reboot again

          • pepeu #
            October 7, 2014

            Wooo! The lamp works! :OD Thank you sooo much for your tremendous help!

            Though the remote.js isn’t really doing anything. Nothing happens when I run: sudo node lightSwitch.js, nor when I run: sudo npm cache clean or npm install. Pardon for my Linux noobness here.

          • October 11, 2014

            I am noob as well lol when it comes to linux however I try my best to understand the code so I get a better idea of what the code is doing so I can fix any problem. Anyway I am also trying to figure how to use the express3-handlebars also the express3-handlebars is changed to express-handlebars so the code node.js needs some cleaning. I cant seem to run the npm install for some reason looks like my nodejs is not installed correctly or its using the different version than what it is suppose to be. I will try re-formatting rpi and doing this over so I don’t have any unnecessary stuff in there. If someone can help on this matter I would really appreciate. I get some warning message when I run the npm install and then some error message

            again any help will be greatly appreciated thank. I would really love to have it controlled through the app. Also I did manage to run a different project of the express-handlebars and it worked I was able to go to the webpage. So I am sure that the stuff works.

            here is the error I get when i run sudo node lightSwitch.js

            pi@raspberrypi ~/RF24/RPi/RF24/examples/LightSwitchInNode $ sudo node lightSwitch.js

            throw err;
            Error: Cannot find module ‘express’
            at Function.Module._resolveFilename (module.js:338:15)
            at Function.Module._load (module.js:280:25)
            at Module.require (module.js:364:17)
            at require (module.js:380:17)
            at Object. (/home/pi/RF24/RPi/RF24/examples/LightSwitchInNode/RemoteRaspberry/remote.js:6:15)
            at Module._compile (module.js:456:26)
            at Object.Module._extensions..js (module.js:474:10)
            at Module.load (module.js:356:32)
            at Function.Module._load (module.js:312:12)
            at Function.Module.runMain (module.js:497:10)

            pi@raspberrypi ~/RF24/RPi/RF24/examples/LightSwitchInNode/RemoteRaspberry $ sudo npm cache clean
            pi@raspberrypi ~/RF24/RPi/RF24/examples/LightSwitchInNode/RemoteRaspberry $ npm install
            npm WARN package.json Raspberry_Remote@2.0.0 No repository field.
            npm WARN deprecated express3-handlebars@0.5.0: THIS PACKAGE HAS BEEN RENAMED TO: express-handlebars
            > ws@0.4.32 install /home/pi/RF24/RPi/RF24/examples/LightSwitchInNode/RemoteRaspberry/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws
            > (node-gyp rebuild 2> builderror.log) || (exit 0)

            make: Entering directory ‘/home/pi/RF24/RPi/RF24/examples/LightSwitchInNode/RemoteRaspberry/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws/build’
            CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
            SOLINK_MODULE(target) Release/obj.target/bufferutil.node
            SOLINK_MODULE(target) Release/obj.target/bufferutil.node: Finished
            COPY Release/bufferutil.node
            CXX(target) Release/obj.target/validation/src/validation.o
            SOLINK_MODULE(target) Release/obj.target/validation.node
            SOLINK_MODULE(target) Release/obj.target/validation.node: Finished
            COPY Release/validation.node
            make: Leaving directory ‘/home/pi/RF24/RPi/RF24/examples/LightSwitchInNode/RemoteRaspberry/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws/build’
            express3-handlebars@0.5.0 node_modules/express3-handlebars
            ├── async@0.2.10
            ├── semver@2.3.2
            ├── glob@3.2.11 (inherits@2.0.1, minimatch@0.3.0)
            └── handlebars@1.3.0 (optimist@0.3.7, uglify-js@2.3.6)

            express@3.4.8 node_modules/express
            ├── methods@0.1.0
            ├── merge-descriptors@0.0.1
            ├── cookie-signature@1.0.1
            ├── range-parser@0.0.4
            ├── debug@0.8.1
            ├── fresh@0.2.0
            ├── buffer-crc32@0.2.1
            ├── cookie@0.1.0
            ├── mkdirp@0.3.5
            ├── commander@1.3.2 (keypress@0.1.0)
            ├── send@0.1.4 (mime@1.2.11)
            └── connect@2.12.0 (uid2@0.0.3, pause@0.0.1, qs@0.6.6, bytes@0.2.1, raw-body@1.1.2, batch@0.5.0, negotiator@0.3.0, multiparty@2.2.0)

            socket.io@0.9.16 node_modules/socket.io
            ├── base64id@0.1.0
            ├── policyfile@0.0.4
            ├── redis@0.7.3
            └── socket.io-client@0.9.16 (xmlhttprequest@1.4.2, uglify-js@1.2.5, active-x-obfuscator@0.0.1, ws@0.4.32)
            pi@raspberrypi ~/RF24/RPi/RF24/examples/LightSwitchInNode/RemoteRaspberry $

          • October 11, 2014

            Ah got this working but still cant turn on and off the lights fixed the problem by installing the latest nodejs

          • October 11, 2014

            I am an idiot forgot to copy the remote file to the root directory of the lightSwitch.js
            got it working now.
            I will try to redo all from fresh install and provide steps for people who is having trouble.
            For now I guess try installing the latest update and dont forget to put the remote file inside the directory with the lightSwitch.js and route.js files

            one more thing if you run the server and exit out of it then you can not run the server again. you need to restart rpi. If there is a better way please do tell. Thanks

  8. pepeu #
    September 28, 2014

    Is there an ETA on an update in the code/guide? Or could you please post the library you used instead of linking to the new one that won’t work. I reeeally want this to work. :O)


  9. Ted #
    September 14, 2014

    Running Debian Wheezy, (newest version)
    executing sudo apt-get install nodejs — DOES NOT install a file called node.js

    I did a wildcard search and a direct name search, and I can not find it.

    Any clues?

    • Jack #
      October 4, 2014

      On raspbian ‘sudo apt-get install nodejs’ installs ‘node’ as ‘nodejs’

  10. pepeu #
    September 3, 2014

    This project looks awesome, but I’m afraid that I’m a complete noob when it comes to anything Linux. You mention that some folders have changed names, but I assume that the code is still the old one?

    g++ -Wall -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -L../librf24/ -lrf24 remote.cpp -o remote

    That line means absolutely nothing to me. :O)

    When I try it is says:

    g++: error: remote.cpp: No such file or directory
    g++: fatal error: no input files
    compilation terminated.

    (Do I have to be in a certain folder when doing it? Am I missing something “obvious”?)

    I made a remote.cpp in ~/RF24/RPi/RP24/examples
    Is that wrong? In a reply in the comments you say “Did you put the rf24 library and the remote in the right place, as described in the article?”

    What RF24 library should be there? (we’re still talking about the examples folder, right?) I must be blind, but I don’t see it in the guide. :O/

    Sorry for this long wall of text, but I love programming and tinkering about, but Linux and the command prompt is a part a would rather skip. :O)

    Thanks in advance

    • pepeu #
      September 3, 2014

      Is it possible that you could update the guide/text/images a bit so it’s crystal clear even for us noobies?


    • pepeu #
      September 4, 2014

      The remote.cpp IS there now, but when I run it it says:

      remote.cpp:9:21: warning: extra tokens at end of #include directive [enabled by default]
      remote.cpp:12:41: error: invalid conversion from ‘const char*’ to ‘uint8_t {aka unsigned char}’ [-fpermissive]
      ../RF24.h:254:3: error: initializing argument 1 of ‘RF24::RF24(uint8_t, uint8_t, uint32_t)’ [-fpermissive]
      remote.cpp:12:41: warning: large integer implicitly truncated to unsigned type [-Woverflow]
      remote.cpp: In function ‘bool switchLight(int)’:
      remote.cpp:51:49: error: ‘__millis’ was not declared in this scope
      remote.cpp:54:20: error: ‘__msleep’ was not declared in this scope

      What am I missing? What do I do now? (You mention in the comments that you have updated the code, but it still shows, from what I can tell, the old code.)

      At least I’m one step closer! :O)

      • September 4, 2014

        Hi! I see a lot of interest, great! I don’t have time now to update the article in a more “nooby” way. In the next week I hope I’ll be able to provide a new compiled version of the remote.cpp bin and check the code. It did work for Ralf(another generous user of the blog), so I think it hasn’t to be that hard to find a way to make it works, so if you want to find the solution to your problem while you wait I think you can reach it.

        • pepeu #
          September 4, 2014

          Thank you for your swift reply! Do you think you could tell me the correct command line, since:

          g++ -Wall -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -L../librf24/ -lrf24 remote.cpp -o remote

          seems to be for the old code/package, as there is no librf24 folder anywhere?

          Thanks in advance!

      • Karn Patel #
        September 14, 2014

        Hi I am having the exact same problem let me know if you can figure something out

        Thanks in advance

  11. cbcercas #
    August 31, 2014

    Thanks for this how-to.

    Just a little typo in “First we enable the Raspy GPIO:” :

    “sudo adduser pi i2c” need to be executed after the i2c-tools installation otherwise i2c group doesn’t exist.

  12. Ralf #
    August 28, 2014

    Hi Edo,

    This is currently not stable enough.
    Although the switch programm is working for me, it stops responding after a few on off switches.

    I assume this is some kind of timing issue when the rpi and the arduino talk…
    I have to blame the arduinos, since the opening the serial from the ide does some kind of reset on the arduino , i can definetely get this up and running again, turning the relay on and off … for a while… then it just stops communicating back to the rpi.
    In that scenario resetting the arduino (by opening a serial to the com port) , will then allow me to run the
    sudo ./remote switch -m 1
    from the pi again until it times out all the time again to get the response from the arduino.

    Would it make sense to put some delays in the code to delay sending the response, or delay the acknowledge on the pi or similar.
    Any ideas?

    • August 28, 2014

      Have you tried changing the arduino? And powering the arduino from a different source like a phone charger?
      It looks like is going to idle, but this is not a known feature of arduino. I did not have a similar issue, not even with different arduinos.
      Make this tries and let men know.

      • Ralf #
        August 29, 2014

        It was my Arduino.
        works fine with with a ATmega32U4 based controller, and it is very stable …

        I was looking at the other stuff maniacbug is doing and his mulitple nodes stuff.
        sounds like a plan to get deeper!

        • August 29, 2014

          Glad you solved, next thing could have been to test if the computer which power the arduino was sending to idle the usb port.
          Anyway, have fun with your light and thank a lot for your donation, it has been really appreciated.

          • Ralf #
            August 29, 2014

            it was something on the arduino itself.
            tried with different chargers, and different chargers to the usb , and or power over the usb serial.
            worked fine with this little guy, and no change in code.

            Thanks again for this tutorial.

            I cannot get your Nodejs application to work and i have problems to install the npm properly

            i am trying something like this now.

            ON OFF

            $.load( “home/pi/./switchon”, function( data ) {

            $.load( “home/pi/./switchon”, function( data ) {

            no luck so far… wonder whether it is something i can do at all with jquerry ,,, to run a binary on the webserver running on the pi

  13. Ralf #
    August 26, 2014


    Thanks a lot for the nice documentation.
    I was wondering whether you could help.
    Sorry for being such a noob , but i hope somebody can give me some help.

    i tried to compile the remote application running on the Pi as described , but i am getting a few errors.
    I am beginning to think that the repository might have changes a bit , and therefore i will need to do something else, i just don’t know where to go.

    I have taken the remote.cpp file and added the line to the make file

    pi@raspberrypi ~/RF24/RPi/RF24/examples $ make
    g++ -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -Wall -I../ -lrf24-bcm remote.cpp -o remote
    remote.cpp:9:20: warning: extra tokens at end of #include directive [enabled by default]
    remote.cpp:12:41: error: invalid conversion from ‘const char*’ to ‘uint8_t {aka unsigned char}’ [-fpermissive]
    .././RF24.h:254:3: error: initializing argument 1 of ‘RF24::RF24(uint8_t, uint8_t, uint32_t)’ [-fpermissive]
    remote.cpp:12:41: warning: large integer implicitly truncated to unsigned type [-Woverflow]
    remote.cpp: In function ‘bool switchLight(int)’:
    remote.cpp:51:46: error: ‘__millis’ was not declared in this scope
    remote.cpp:54:14: error: ‘__msleep’ was not declared in this scope
    make: *** [remote] Error 1
    pi@raspberrypi ~/RF24/RPi/RF24/examples $

    running the binary from this folder will give me

    pi@raspberrypi ~/RF24/RPi/RF24/examples $ ./remote -m 1
    ./remote: error while loading shared libraries: librf24.so.1: cannot open shared object file: No such file or directory

    so although this is beatiful and i am getting close :) i am lost and i a

    • August 26, 2014

      Hi! If you are encountering difficulties, and you don’t need to customise the code, I think you would like to download the compiled bin from the github repo.

      • Ralf #
        August 26, 2014

        Thanks for looking into it.

        i tried that, but it gives me
        ./remote: error while loading shared libraries: librf24.so.1: cannot open shared object file: No such file or directory

        • August 26, 2014

          Did you put the rf24 library and the remote in the right place, as described in the article?

          • Ralf #
            August 26, 2014

            Sorry again, i am not very familiar with the Debian os.

            i thought so.
            the RF24 library from the repository must have gotten a slight modification, and i noticed that only the bcm library got installed though ? Maybe that is excacty my problem.

            pi@raspberrypi ~/RF24/RPi/RF24 $ sudo ldconfig -v librf24.so.1.0
            ldconfig: relative path librf24.so.1.0' used to build cache
            pi@raspberrypi ~/RF24/RPi/RF24 $ sudo ldconfig -v | grep librf
            ldconfig: Path
            /lib/arm-linux-gnueabihf’ given more than once
            ldconfig: Path `/usr/lib/arm-linux-gnueabihf’ given more than once
            ldconfig: /lib/arm-linux-gnueabihf/ld-2.13.so is the dynamic linker, ignoring

            librf24-bcm.so.1 -> librf24-bcm.so.1.0
            ldconfig: /lib/ld-linux.so.3 is the dynamic linker, ignoring

    • Jim #
      August 27, 2014


      I’m facing same issue. As in case above the folder reference by article does not exist ‘RF24/librf24-rpi/librf24′, instead we have the RPi folder.

      Also when we run the command we get ‘librf24-bcm.so.1 -> librf24-bcm.so.1.0, note the ‘bcm’ in there.

      Any help would be greatly appreciated.

      • August 27, 2014

        Looks like the author changed folder’s name. I’ve updated the names, please check if it works.

      • Ralf #
        August 27, 2014

        Hi Jim,

        Phew , not the only one who is a bit confused about it :)

        The switch application includes a lot of other libraries as well which are not included in the repository mentioned in the article, so they must have gotten some other libraries and have just not updated the website for one reason or the other.

        I do not have this running so far.

        in the meantime maybe have a look at


        as per the article above,
        the repository here
        looks more like what the Lenotta guys might have used to get this up and running.

        • August 27, 2014

          Hi Ralf! Just in time. Actually we were using the same repo we posted. I’ve updated the article with the changes the librarie’s author made. Please check if it work, it should just be a matter of folder’s name.
          Thank you for proposing a fix.

          • Ralf #
            August 27, 2014

            wow, that is quick replying.
            Thanks Edo.
            You guys are good.
            Will try.

          • Jim #
            August 29, 2014

            Thanks for speedy reply, very much appreciated. I’ll try this tonight hopefully, looking forward to it working :)

          • Jim #
            August 29, 2014

            Hi there,

            I totally removed the folder and started from scratch using the updated instructions but I get exact same error. I tried modifying the make file to remove the ‘-bcm’ which appeared to create the same lib name as th example byut on running ,/remote got same error as original post.

            Tried using the .cpp and compiling but still no luck :(

            I’ll keep plugging away for a bit longer.

          • Jim #
            August 29, 2014

            eek, done something bad I think.

            Ever since changing makefile I get this:
            ./remote: symbol lookup error: ./remote: undefined symbol: _ZN4RF24C1ESsjh

            Even if start from scratch and clean !

          • August 29, 2014

            Try with a make clean. When I’ll have 10 minutes I’ll try agar again.

  14. August 25, 2014

    Do you mind if I quote a few of your articles as long as I provide credit and sources back
    to your site? My blog is in the exact same niche as yours and my visitors would genuinely benefit from some of the information you present here.

    Please let me know if this ok with you. Many thanks!

  15. Dave #
    July 21, 2014

    Hello and thank you for the great post. I am a newbie to the raspberry pi and arduino, so forgive my lack of understanding. I was able to follow everything until the “To run the application you need to:”. I was able to type “./remote -m 0 or 1″ and turn on and off the light, but I haven’t been able to run the Node.js application. Below are the errors I got.

    #install the dependencies
    cd ~/RF24/librf24-rpi/librf24/examples/LightSwitchInNode/RemoteRaspberry
    ###(((okay, made it this far)))

    #but first clean the npm cache
    sudo npm cache clean
    ###(((at this point I get an error that states, sudo: npm: command not found)))

    npm install
    ###(((i get an error that states, bash: npm: command not found)))

    #run the application
    cd ../
    sudo node lightSwitch.js
    ###(((error, sudo: node: command not found)))

    Any help with these errors would be greatly appreciated.


    • July 21, 2014

      Hi! It looks like you don’t have node and npm (which is node package manager) installed. Try to install it ( http://joshondesign.com/2013/10/23/noderpi ) and retry.
      So it is like “Hey Npm, clean your cache you dirty!” but no application named Npm is present in your raspy, so raspy says “Npm? Who’s this Npm? I can’t find him.”. Just a little example on how to interpret error messages.
      Let us know how it goes.

      • Ralf #
        August 29, 2014

        i am getting the following
        pi@raspberrypi ~/RF24/RPi/RF24/examples/LightSwitchInNode/RemoteRaspberry $sudo npm cache clean
        pi@raspberrypi ~/RF24/RPi/RF24/examples/LightSwitchInNode/RemoteRaspberry $npm install
        pi@raspberrypi ~/RF24/librf24-rpi/librf24/examples/LightSwitchInNode/RemoteRaspberry $ npm install
        npm http GET https://registry.npmjs.org/socket.io/0.9.16
        npm http GET https://registry.npmjs.org/express/3.4.8
        npm http GET https://registry.npmjs.org/express3-handlebars/0.5.0

        npm ERR! Error: failed to fetch from registry: socket.io/0.9.16
        npm ERR! at /usr/share/npm/lib/utils/npm-registry-client/get.js:139:12
        npm ERR! at cb (/usr/share/npm/lib/utils/npm-registry-client/request.js:31:9)
        npm ERR! at Request._callback (/usr/share/npm/lib/utils/npm-registry-client/request.js:136:18)
        npm ERR! at Request.callback (/usr/lib/nodejs/request/main.js:119:22)
        npm ERR! at Request. (/usr/lib/nodejs/request/main.js:212:58)
        npm ERR! at Request.emit (events.js:88:20)
        npm ERR! at ClientRequest. (/usr/lib/nodejs/request/main.js:412:12)
        npm ERR! at ClientRequest.g (events.js:156:14)
        npm ERR! at ClientRequest.emit (events.js:67:17)
        npm ERR! at HTTPParser.parserOnIncomingClient [as onIncoming] (http.js:1256:7)
        npm ERR! You may report this log at:
        npm ERR!
        npm ERR! or use
        npm ERR! reportbug –attach /home/pi/RF24/librf24-rpi/librf24/examples/LightSwitchInNode/RemoteRaspberry/npm-debug.log npm
        npm ERR!
        npm ERR! System Linux 3.12.22+
        npm ERR! command “/usr/bin/nodejs” “/usr/bin/npm” “install”
        npm ERR! cwd /home/pi/RF24/librf24-rpi/librf24/examples/LightSwitchInNode/RemoteRaspberry
        npm ERR! node -v v0.6.19
        npm ERR! npm -v 1.1.4
        npm ERR! message failed to fetch from registry: socket.io/0.9.16
        npm ERR!
        npm ERR! Additional logging details can be found in:
        npm ERR! /home/pi/RF24/librf24-rpi/librf24/examples/LightSwitchInNode/RemoteRaspberry/npm-debug.log
        npm not ok
        pi@raspberrypi ~/RF24/librf24-rpi/librf24/examples/LightSwitchInNode/RemoteRaspberry $

        similar name changes on the registry npmjs website?

        • Ralf #
          August 29, 2014

          different versions i suppose

          • August 31, 2014

            Indeed, I think you have an old npm, did you tried updating it?

  16. Jean-Maurice #
    July 16, 2014


    Thanks a lot for your instructions and script! Everything worked well. I was able to use your script with python using the subprocess.call function and it worked well to send a message from the raspberry pi to the arduino.

    subprocess.call([“./remote”, “-m”, “0”])

    But I’m not able to use the answer (from the Arduino to my raspberry pi) in my python program. Does anyone know how to read and use the arduino’s message in a python program on the raspberry pi?

    • July 16, 2014

      I’m parsing the output of the c++ program as text with the node application. What exactly your python code does?

      • Jean-Maurice #
        July 18, 2014

        Hi Edoardo!
        Thanks for your interest and help. I got two projets :

        1) Automatic irrigation system: The arduino is connected to the pump and moisture sensor inside. I want to send wireless a command from the Raspberry Pi inside to the Arduino outside to activate the pump. I can do that with your remote.cpp file and it work well:

        subprocess.call([“./remote”, “-m”, “0”])

        Then I want the arduino to answer with the values of the moisture sensor. But I can’t use these values in my python code, I can received them with your remote.cpp, but I can’t use them in my python program….

        2) Automatic curtain: The Arduino control the motor to open or close the curtain. The Raspberry Pi is connected to internet. I’m able to send the command from the Raspberry Pi to the Arduino, but I want to use the answer from the Arduino to know if the curtain are open or closed.

        So my two projects are working only as a 1 way wireless communication…

        Thanks again for your help, I whish I can share my projet if some people are interested and if it’s working :-)


        • Neeraj #
          July 19, 2014

          HI Jean-Maurice, I working for complete home automation. Where all the electric goods will be controlled by mobile . same configuration i m using . Rpi+arduino+many sensor+mobile app+ dimmer + web APIs + DVR.

          Also I m thinking about for commercial production if project will be successful ..

  17. keg188 #
    July 13, 2014

    Has anyone got this working on the beaglebone black.

    everything seems fine but i get this:

    Preparing interface
    STATUS = 0xff RX_DR=1 TX_DS=1 MAX_RT=1 RX_P_NO=7 TX_FULL=1
    RX_ADDR_P0-1 = 0xffffffffff 0xffffffffff
    RX_ADDR_P2-5 = 0xff 0xff 0xff 0xff
    TX_ADDR = 0xffffffffff
    RX_PW_P0-6 = 0xff 0xff 0xff 0xff 0xff 0xff
    EN_AA = 0xff
    EN_RXADDR = 0xff
    RF_CH = 0xff
    RF_SETUP = 0xff
    CONFIG = 0xff
    DYNPD/FEATURE = 0xff 0xff
    Data Rate = 1MBPS
    Model = nRF24L01
    CRC Length = 16 bits
    PA Power = PA_HIGH

    Opening the gates…
    Now sending 1…ok…Got response 4294967295, round-trip delay: 140

    I get the same response when the nRF24L01+ is disconnected

    • keg188 #
      July 13, 2014

      When using the Beaglebone black be sure to use the correct SPI port.
      I now have the remote app compiled and running on BBB.

      Thanks for this guide.

  18. Omer #
    July 10, 2014

    What a wonderful tutorial!
    Very clear explanations – thank you! :)

    • Neeraj #
      July 10, 2014

      You have not faced any problem in implementation ???

      Can you please help me . I am getting below error.

      Preparing interface
      SPI device = /dev/spidev0.0
      SPI speed = 8000000
      CE GPIO = 25
      STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
      RX_ADDR_P0-1 = 0xf0f0f0f0e1 0xf0f0f0f0d2
      RX_ADDR_P2-5 = 0xe2 0xe3 0xe4 0xe5
      TX_ADDR = 0xf0f0f0f0e1
      RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20
      EN_AA = 0x3f
      EN_RXADDR = 0x3f
      RF_CH = 0x4c
      RF_SETUP = 0x07
      CONFIG = 0x0f
      DYNPD/FEATURE = 0x00 0x04
      Data Rate = 1MBPS
      Model = nRF24L01+
      CRC Length = 16 bits
      PA Power = PA_MAX

      Opening the gates…
      Now sending 1…failed.
      Failed, response timed out.
      Now sending 1…failed.
      Failed, response timed out.
      Now sending 1…failed.
      Failed, response timed out.
      Now sending 1…failed.
      Failed, response timed out.
      Now sending 1…failed.
      Failed, response timed out.

      • Jean-Maurice #
        July 16, 2014

        Hi Neeraj,
        I got the same problem. In my case, it was a power problem. I solved it by connecting a .1uF to 10 uF (MicroFarad) capacitor between the module and the arduino (and also between the module and the raspberry) from +3.3V to Gnd (Watch + and – !)

        You can have more details in the “power problems” section of this website


        • Neeraj #
          July 19, 2014

          Thanks ……………..

  19. wpk78 #
    July 8, 2014


    Zadzialalo za pierwszym razem (It worked for the first time)

    • Neeraj #
      July 10, 2014

      You have not faced any problem in implementation ???

      Can you please help me . I am getting below error.

      Preparing interface
      SPI device = /dev/spidev0.0
      SPI speed = 8000000
      CE GPIO = 25
      STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
      RX_ADDR_P0-1 = 0xf0f0f0f0e1 0xf0f0f0f0d2
      RX_ADDR_P2-5 = 0xe2 0xe3 0xe4 0xe5
      TX_ADDR = 0xf0f0f0f0e1
      RX_PW_P0-6 = 0×20 0×20 0×20 0×20 0×20 0×20
      EN_AA = 0x3f
      EN_RXADDR = 0x3f
      RF_CH = 0x4c
      RF_SETUP = 0×07
      CONFIG = 0x0f
      DYNPD/FEATURE = 0×00 0×04
      Data Rate = 1MBPS
      Model = nRF24L01+
      CRC Length = 16 bits
      PA Power = PA_MAX

      Opening the gates…
      Now sending 1…failed.
      Failed, response timed out.
      Now sending 1…failed.
      Failed, response timed out.
      Now sending 1…failed.
      Failed, response timed out.
      Now sending 1…failed.
      Failed, response timed out.
      Now sending 1…failed.

  20. Neeraj #
    July 6, 2014

    We are getting below error . I have rechecked all the connection and libraries . Might be some problem in GPIO pin setting and status . Please help is anybody has resoled the problem .

    Preparing interface
    SPI device = /dev/spidev0.0
    SPI speed = 8000000
    CE GPIO = 25
    STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
    RX_ADDR_P0-1 = 0xf0f0f0f0e1 0xf0f0f0f0d2
    RX_ADDR_P2-5 = 0xe2 0xe3 0xe4 0xe5
    TX_ADDR = 0xf0f0f0f0e1
    RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20
    EN_AA = 0x3f
    EN_RXADDR = 0x3f
    RF_CH = 0x4c
    RF_SETUP = 0x07
    CONFIG = 0x0f
    DYNPD/FEATURE = 0x00 0x04
    Data Rate = 1MBPS
    Model = nRF24L01+
    CRC Length = 16 bits
    PA Power = PA_MAX

    Opening the gates…
    Now sending 1…failed.
    Failed, response timed out.
    Now sending 1…failed.
    Failed, response timed out.
    Now sending 1…failed.
    Failed, response timed out.
    Now sending 1…failed.
    Failed, response timed out.
    Now sending 1…failed.
    Failed, response timed out.

    • Suresh #
      July 28, 2014

      Hey Neeraj,

      I am facing the same problem. I tried the eample code with RF24 lib rpi-hub and pingtest(Arduino) they work fine.
      In case you found a solution, please help me with what worked for you.


      • July 28, 2014

        Have you tried with the 10 uF (MicroFarad) capacitor solution?

        • Neeraj Agrawal #
          September 6, 2014

          Ya now working fine , and project completed successfully . I have used PiHome for UI . Which is looking great . Enhanced the UI with adding lot of tables and new web template..

  21. Binh #
    June 12, 2014

    Hi Edoardo,
    How to encrypt string sender side and decrypt receiver side?

    • August 13, 2014

      Are you trying to send encrypted messages? If so, the easiest thing to do is to either copy a cipher from some source and provide both ends with the key. In other words, the only way to encrypt/decrypt is to do so on the two computers (pis, arduinos, etc). There are lots of algorithms on the web you can try.

  22. FJaskolski #
    June 12, 2014

    Hello there! I am in the middle of nowhere, trying to make Atmega8A and RPi talk to each other with a help from NRF2401A.

    The thing, that troubles me the most is slightly different architecture of my radio modules (provided by local company). I found similar ones within SparkFun resources: https://www.sparkfun.com/products/152 . I also figured out how to use “DATA” pin (according to Nordic sheets, you just plug it to both MISO and MOSI pins through a 10k resistor).

    Knowing all this, I still cannot establish a working connection. The rpi-hub example gives me “Recv: size=127 payload= pipe=7″ no matter what. I thousand-checked all the hardware, and I am pretty certain about software on Atmega side.

    Could you please give me any hints on porting your library to NRF2401A modules? Is there something I can do to determine the centre of the problem?


  23. Kiaran #
    June 5, 2014

    Good day,
    First of all, great tutorial, I have it working using “./remote -m 1″, however, as soon as I type “sudo npm cache clean” or “npm install” I get the message “npm: command not found”. Any suggestions?
    Thanks in advanced.

    • Kiaran #
      June 16, 2014

      Got it working, installed npm a different way. Works perfectly. Thanks for sharing this

  24. Stephan #
    June 1, 2014

    Sorry, don’t know how to paste html code…testing

    in light.handlebars i add a checkbox and a slider:

    label style=”width:120px;”>PowerPowerFade</div

  25. Stephan #
    June 1, 2014


    i like your project very mutch and i want to use it for me.

    After i get it to run, i want to implement a toggle button and a slider control based on jquery into the page and it still does not work.
    In another project it worked fine.

    Heres my code:

    in light.handlebars i add a checkbox and a slider:



    in remoteClient.js i add a new function called initControls and call it from windows.onload function:

    function initControls(){
    // change checkbox to button

    // define the slider
    value: 0

    When i start now the app, the button is shown as a checkbox and the slider i can’t see (but is included in page).

    I’m new in javascript, jquery and node.js, can you help me with this problem. in another app (also node.js based) i do this by the same way,
    but there i have a html file with all the code in it and not separated.

    Sorry about my english…

    Greets from Germany

  26. Jody Roth #
    June 1, 2014

    I had my nRF24 modules working on the library examples and wanted to try out your web-controlled lamp version to learn a bit about the IoT side of things. Everything worked well except installing Nodejs required me to use the Adafruit site instructions at :https://learn.adafruit.com/raspberry-pi-hosting-node-red/setting-up-node-dot-js

    Thanks for putting this information onliine. Your tutorial is very well done!

    An additional feature request: Instructions to make the web page available via the internet rather than the local network. At least, that is what I’m off to find now.

    • June 8, 2014

      Hi! Glad you liked it! To reach the app from the internet: register no-ip account, install noip2 client on raspberry, log on the noip2 client with you credentials, open the choosen port on the router .
      Ex: if is your app raspy port, then you should open port 3000 on the router telling him to send connections on on port 3000. You will then be able to connect on example.no-ip.org:3000.

    • xmh #
      June 10, 2014

      Wprogram.h is a header file from version of Arduino’s IDE earlier than 1.0.
      It’s now included in Arduino.h, so it’s common error when compiling sources from github. ;-)

  27. May 30, 2014

    when i build file c++ , it had a error: Wprogram.h no such directory. I have check All file of RF24, but I didn’t find Wprogram.h. Can you give me hand. Thank you.

  28. Binh #
    May 28, 2014

    Hi Edoardo Odorico,
    I’m trying to communicate and pi pic, but I have yet to communicate. Pic of the pipe address is 0x3f
    Pic is receive.
    Rpi is send.
    Can I use address pipe 1 bytes for Rpi?
    Ex: const uint64_t pipes=0x3F;
    When I run the file rpi-hub model is nRF24L01, not nRF24L01+. I use IC as in your picture.
    This is 3 times test my rpi-hub, receive alway =ỹỹỹỹỹỹỹỹỹ…:
    Sorry for my english level.

    • June 8, 2014

      I’m sorry, would you explain it more clearly? I don’t understand your questions. Looks like you are trying to send a picture, maybe? I don’t think the plus sign is really a problem.

  29. May 20, 2014

    Nice work guys this is exactly what i am looking for at the moment. I have it working with a Pro Mini embedded within a light switch. However when i try to run it as a service i keep getting errors which i believe are related to file paths.

    Being a bit of a noob in the Linux area i’m fumbling my way through but cant seem to work out how to resolve the issue. I’ve tried using /etc/init.d creating a service and also trying to run it using “forever”. I’ve messed about with the path variables but it only ever works if ran using the command as described in the post from the LightSwitchInNode folder.

    Does anyone have any thoughts as to where i’m going wrong?


    • May 21, 2014

      Since I would like to have a kind of log of what I’m doing, I made it run on a screen instance.
      1- create a file called bootScript.sh, write inside:
      !/bin/bashcd /home/user/folderOfNodeApplication/sudo node remote.js

      and give it exec permissions (chmod +x)
      2- Write inside /etc/rc.local this:
      su -c 'screen -d -m -S lightApp /home/user/folderOfTheScript/bootScript.sh'

      3- reboot. You should now be able to acces the screen with the app running by going on sudo (sudo su) and then writing:
      screen -r lightApp

      • May 21, 2014

        Awesome, Works perfectly… Once I realized I had to install “screen”.


  30. May 9, 2014

    1. printf.h:no such file or directory
    2.many many errors

    • May 9, 2014

      First, as you may know caps lock is equivalent to yell, and this is not a nice behaviour while asking help.
      For what concern you errors, the first usually happen when your arduino IDE is unable to find the printf library, check at beginning for the include.
      About the other errors, we recently used the same code to prepare another arduino, and everything worked flawlessy. Maybe you should send us the error.

      Have a nice day.

      • May 9, 2014

        I’m sorry about my behaviour. Thanks for your help. how to overcome about error “printf”. I have not understood how to check at beginning for the include. About 1 month ago, I have added printf library for arduino. If you have a printf library to surmount this error, Can you give me it? Thanks a lot.

        • May 9, 2014

          file switch.cpp. How to make it? Write on Rasp? thank you

          • Mohit #
            May 9, 2014

            If you have added the printf library to the Arduino IDE, just make sure the printf code is open in the IDE.

            Switch.cpp is to be compiled on the Pi .. follow the instructions in the blog post …

          • May 9, 2014

            Comply error in sketch in Arduino, error about printf. IDE belongs to Raspberry. if you have a printf library. Can you send me a link to download. I have also a question. What program do we use to make Switch.cpp

          • May 9, 2014

            Here you can find all the informations needed for the printf library http://playground.arduino.cc/Main/Printf
            To write Switch.cpp code you can use whatever text editor you prefer (vim, emacs, sublime, nano… even, not recommended, Word)
            Just save the file with .cpp extension and compile it.

          • May 9, 2014

            thank you
            Edoardo Odorico #

          • May 9, 2014

            printf_begin is not decalred. I don’t know why?

  31. Matteo #
    May 1, 2014

    Hi, anyone know how can send string, and not only int?

    Thanks a lot!

    • May 8, 2014

      We are sending integers because it’s faster. I think that if you need to send a text you can just wrap it up in double apexes.
      Remember to double check types, since you are in C (like done = radio.read( &message, sizeof(unsigned long) );)
      Plus, don’t forget you have to compare strings instead of integers -> http://www.wikihow.com/Compare-Two-Strings-in-C-Programming

  32. Björn #
    April 18, 2014

    Hi, I’m pretty new on the linux environment and not sure what I’m doing. I’ve tried to use the guide but I’m getting the following error when trying to compile the switch program:

    pi@greenhouse ~/RF24/librf24-rpi/librf24/examples $ sudo g++ -Wall -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -L../librf24/ -lrf24 switch.cpp -o switch
    /tmp/ccm241WK.o: In function setup()':
    switch.cpp:(.text+0x14): undefined reference to
    switch.cpp:(.text+0x24): undefined reference to RF24::setRetries(unsigned char, unsigned char)'
    switch.cpp:(.text+0x30): undefined reference to
    RF24::setChannel(unsigned char)’
    switch.cpp:(.text+0x3c): undefined reference to RF24::setPALevel(rf24_pa_dbm_e)'
    switch.cpp:(.text+0x48): undefined reference to
    switch.cpp:(.text+0x58): undefined reference to RF24::openWritingPipe(unsigned long long)'
    switch.cpp:(.text+0x6c): undefined reference to
    RF24::openReadingPipe(unsigned char, unsigned long long)’
    switch.cpp:(.text+0x74): undefined reference to RF24::startListening()'
    switch.cpp:(.text+0x80): undefined reference to
    /tmp/ccm241WK.o: In function switchLight(int)':
    switch.cpp:(.text+0xa8): undefined reference to
    switch.cpp:(.text+0xc8): undefined reference to RF24::write(void const*, unsigned char)'
    switch.cpp:(.text+0xe0): undefined reference to
    switch.cpp:(.text+0xe4): undefined reference to __millis'
    switch.cpp:(.text+0xf4): undefined reference to
    switch.cpp:(.text+0x134): undefined reference to RF24::read(void*, unsigned char)'
    switch.cpp:(.text+0x138): undefined reference to
    switch.cpp:(.text+0x154): undefined reference to __msleep'
    switch.cpp:(.text+0x158): undefined reference to
    /tmp/ccm241WK.o: In function _GLOBAL__sub_I_radio':
    switch.cpp:(.text.startup+0x1c4): undefined reference to
    RF24::RF24(std::basic_string<char, std::char_traits, std::allocator >, unsigned int, unsigned char)’
    collect2: ld returned 1 exit status

    Any ideas what I’ve missed? Using 2014-01-07-wheezy.raspian

    • May 8, 2014

      looks like you are missing the RF24 library, since all the missing functions refer to it.

      • Anders #
        May 28, 2014

        I have the same problem. I had it working compiling just fine. Then one day it just started spitting out the same errors. I have RF24.h in place, I’ve even reinstalled the RF24 library a couple of times with no success.

        I can not figure out what’s wrong. (I’m a raspberry and linux beginner).

  33. Mohit #
    April 18, 2014

    Hey Guys,

    I’m building a system where my Pi (central unit) needs to connect to multiple Arduinos wirelessly.

    So I have one Pi and 3 Arduinos set up.

    Each Arduino has a variable called ID to help identify it.

    If my Pi want to talk to Arduino with ID = 1, it will send a message with the format : 1XXXX
    If it wants to talk to Arduino with ID =1, the message sent out will be : 2XXXX

    Even though all units are kept in the same room for now, I’m noticing major packet drops.

    One of my observations is this : when the Pi transmits, all the Arduinos receive, but if the ID does not match, they do nothing, only the Arduino with the correct ID will give an Acknowledgement back, but it turns out the Pi does not receive the Acknowledgement.

    What I can’t figure out is, whether my modules are faulty, or are they not designed to work this way ..??

    Thanks !

  34. sid #
    April 18, 2014

    Hi Edoardo,

    I have implemented this for a home automation system.
    This works but the problem is it works intermittently.

    At times it works really smooth.
    The next moment it stops working.
    After some investigation I found that the NRF24l01 on arduino receives the request works on it and sense the response back to NRF24l01 on raspberry. But the raspberry is not able to receive it resulting in packet drops.

    It enters the following part of cpp code

    while ( ! radio.available() && ! timeout ) {
    if (__millis() – started_waiting_at > 1000 )
    timeout = true;

    As radio.available never becomes true this thing times out.
    I increased the delay to 100 from 10 to give NRF24l01 on rpi time to find data sent from arduino, but that didn’t help.

    What surprises me is even the switch is not toggled by arduino.
    Range can’t be an issue as arduino and rpi are in same room.

    Can you please tell me what is the problem here.
    Is it the NRF24l01? Is it faulty?
    Or do i need to add anything in the code?

    • May 10, 2014

      Sorry for the delay, it has been a very busy period.
      Don’t know actually what could be the problem . I didn’t have any kind of problem like your.
      Before editing the code, since everything is working fine for me, I would suggest:
      1- double check wires (it happened to us faulty cables drive crazy)
      2- check the modules (they are really cheap and it’s always good to have one more for backup)
      3- check the arduino (it happened to us to lose a whole day with a broken arduino… )
      4- do not place the arduino nor the transmitter near wifi routers (same frequency 2.4GHZ)

      Let us know.

  35. Oscar #
    April 15, 2014

    Hi. Thanks a lot for sharing your jobs. I’ve done your project, in order to test miself!!. But now I have to implement my own solution. I want to control some blinds, each one with an arduino one, with a raspberry pi. But my problem is that I’m gonna use some wall blind switch. So I would need to transmit with the arduino to the raspberry when the switch its been activated, in order to memorize the new blind position on the raspberry. My first solution to do that it’s to have two different programs on the raspberry: One always running, just to listen when some arduino sends info to the raspberry with his new position. And another one program to control the blinds movement from remote.
    Do you think that’s a good solution?? Maybe I could have some collission problems when both programs will be running?
    Thanks a lot for you help

    • April 15, 2014

      Hi Oscar,
      hopefully I’ve understood the problem, please correct me if I’m wrong.
      Since you are sending a message to the arduino, I suppose that the message is different when opening and closing the blinds.
      Said that, the arduino actually replies with the same message you’ve sent (ack package) when he receive the message correctly.
      Now, your raspberry know that your blind is being opened and can hold and manage this information. The same happen when you are closing the blinds. What you might to achieve is to have a “callback” when the blinds are effectively closed. Without creating two programs, you could use the same, given the fact the opening/closing the blinds will be eventually a locking command during all the time of the operations. Which means that when you are opening the blinds you can’t turn the lights on, for instance. This solution simply tell the raspberry to ping the arduinoBlinds every 5 seconds after you’ve pressed the action and send a message, like “What are you doing?” and he answers: 00) Closed .10)I was open and I’m closing .01) I was closed and I’m opening. 11) I’m open. When the raspberry receive the last command it will stop to ping.

      Let’ make an example.
      Raspberry knows that arduBlinds is 00 (Because of a ping or a previous known state saved, for instance, on a db). So Raspberry tells him “11”. Then Raspberry start to pings arduBlinds with “What are you doing?”. At first the arduBlinds will say “01” for the time it is opening the blinds and then, when finished, it will say “11”. At this point Raspberry stop to ping.

      I don’t have libraries with me, but I suppose you have to switch mode from listening to sending.

      Let me know.

      • Oscar #
        April 15, 2014

        Thanks for your time, unfortunately I don’t explain myselfarruinó. nk I can write all the process between arduino and the raspberry. My problem is when I use the wall switch, not via the raspberry. Every blind has it’s own switch, connected to the arduino to avoid conflict between switch and online orders. So, if I act the switch, the arduino can send a message to the raspberry with the new blind position. But then I need to Have the raspberry always listening for a message from the arduino ? . and another program to operate the blinds ‘online’??. Thanks a lot again

  36. Mohit #
    April 10, 2014

    I’m connecting the transceiver to an Arduino Mega and it stops working … I connect it to the Uno and it works … any ideas ?

    • Mohit #
      April 10, 2014

      Ooops … turns out SPI connections on MEGA are different …

  37. Evan #
    March 31, 2014


    I’ve gotten to the point where I need to compile where I need to compile the application, but I get errors:

    pi@raspberrypi ~/RF24/librf24-rpi/librf24/examples $ sudo g++ -Wall -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -L../librf24/ -lrf24 switch.cpp -o switch
    switch.cpp:2:1: error: stray ‘\302’ in program
    switch.cpp:2:1: error: stray ‘\240’ in program
    switch.cpp:15:45: warning: extra tokens at end of #include directive [enabled by default]
    switch.cpp:15:46: fatal error: ~/RF24/librf24-rpi/librf24/RF24.h: No such file or directory
    compilation terminated.

    Any ideas? the “RF24.h” file is in the directory it says it is not.


    • Mohit Athwani #
      March 31, 2014

      Hey Evan,

      Stray \302, \240 could be some issue with copy pasting code (not sure though)

      About the extra toke, get rid of the semi-colon “;” at the end of line 15 of your code …

      I put my code in the examples folder in the RF24 directory and it worked fine …

  38. March 30, 2014

    Hi! I know this is somewhat off topic but I was wondering if you knew where I could find
    a captcha plugin for my comment form? I’m using the
    same blog platform as yours and I’m having trouble finding
    one? Thanks a lot!

  39. March 16, 2014

    Awesome tutorial ! But sadly I cannot get it to work :(

    I’ve checked, double checked and triple checked the connections.

    Out put on my Arduino Uno is :

    Light Switch ArduinoSTATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0RX_ADDR_P0-1 = 0xf0f0f0f0e1 0xf0f0f0f0d2RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6TX_ADDR = 0xf0f0f0f0e1RX_PW_P0-6 = 0x20 0x20 0x00 0x00 0x00 0x00EN_AA = 0x3fEN_RXADDR = 0x03RF_CH = 0x4cRF_SETUP = 0x07CONFIG = 0x0fDYNPD/FEATURE = 0x00 0x00Data Rate = 1MBPSModel = nRF24L01+CRC Length = 16 bitsPA Power = PA_HIGH

    And out put on my Pi is :
    Preparing interfaceSPI device = /dev/spidev0.0SPI speed = 8000000CE GPIO = 25STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0RX_ADDR_P0-1 = 0xf0f0f0f0e1 0xf0f0f0f0d2RX_ADDR_P2-5 = 0xe2 0xe3 0xe4 0xe5TX_ADDR = 0xf0f0f0f0e1RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20EN_AA = 0x00EN_RXADDR = 0x3fRF_CH = 0x4cRF_SETUP = 0x07CONFIG = 0x0fDYNPD/FEATURE = 0x00 0x04Data Rate = 1MBPSModel = nRF24L01+CRC Length = 16 bitsPA Power = PA_MAXTurn it ooooon!Now sending 1...ok...Failed, response timed out.Now sending 1...ok...Failed, response timed out.Now sending 1...ok...Failed, response timed out.Now sending 1...ok...Failed, response timed out.Now sending 1...ok...Failed, response timed out.

    Can’t figure out what’s going on …

    • March 17, 2014

      Woke up today morning and tried it again, and guess what the 2 devices communicated.

      So I kept on playing with the on/off commands and noticed that communication is never 100% … can anybody comment on the success rate ?

      • March 22, 2014

        Hi Mohit!
        We are happy that you finally managed to make them communicate! We did have the same problems, which turned out it was just a matter of clean implementation and wiring.
        About the succes rate, we’ve found that turning on the light in the same room as the Raspy was almost instantaneous. Maybe you have some device which is generating some intereferences with your modules. Remember that the frequency is 2.4 Ghz, which is the same as wifi and microwave oven (and some other devices). Try to change channel frequency and, if you are brave enough, have a look at some antenna mods you find around for 2.4ghz (remember I’ve seen this module with an antenna mod too).
        Let us now how it goes!

    • Jemson #
      May 10, 2014

      I have the same issue here. Maybe 1 in 50 attempts will actually succeed.
      Have tested at millimeters apart as well as a few meters.
      Also disconnected all 2.4GHz devices (WAP, Cordless phone etc) as well as checked, checked and rechecked the pinouts and it still won’t work consistently. Have also tried a second Nano, and also replaced the NRF24I01+ at both ends.
      Only thing I haven’t replaced is the Pi itself, but have tested the SPI by looping it back and that works fine.

      At a bit of a loss as to why it won’t work. Only thing I can think of is to start again, reimport libraries and reimage the SD on the Pi in case there is any sort of conflict.

      If anyone else has any other suggestions I will be happy to hear them.

      • Jemson #
        May 10, 2014

        So I went ahead and recreated the config and had the same issue, but stumbled across the cause of the issue by dumb luck on the pingpong test.
        Seems if I am connected to the serial interface of the Arduino tests fail, however, if I am not connected it all works fine.
        I will try and dig into why, but at least it is working for now. If I can’t fix it, it will make debugging other issues a little harder but I can live with that.

        • May 10, 2014

          I would suggest a possible cause.
          Recenlty we were working on a project with 433MHZ module. We needed to listen carefully the waves received from another Arduino with the TX module. I noticed that when connected to the computer the received message was a lot disturbed by the dirty DC passed with the USB cable (even if the computer was on battery), but when the tx arduino was attached to a 12v battery, then the received signal was really clean.

          That said, since I didn’t find this problem with my computer nor the raspberry or the chinese usb adapter the arduino is powered by, you could try attach the arduino to a normal usb adapter and the raspberry too.

          Let us know how it goes.

  40. Ishu #
    March 14, 2014

    So, I have competed a complete working automation solution using same hardware … any advice as to how i should publish it. should i licence it or something .. I’m new to the field.

    • March 16, 2014

      Hey Ishu ,

      since you got it working, maybe you can help me out with my problem above ?



  41. Mar #
    March 12, 2014

    thanks for this great project. I succeed with it. But I have one strange behaviour. I succeed to send the on (1) and off (2) to arduino from Raspberry Pi. But when the Raspberry Pi get back the response it never receive the same information. I would expect that when Raspberry Pi send “1” to arduino then arduino send back again “1”. But I never get this back on Raspberry Pi. I always get some different strange number (0, 1678878, 245584 etc…) but never 1. I also tryed to send same static number from the Arduino to Pi but I never receive the correct number on Pi. Do you have any idea where could be the problem?


    • May 10, 2014

      Usually wiring bugs give this error. Double check the RF24 library installation (link in the article)

  42. Hduque #
    March 2, 2014


    I am no able to get it work yet. May be could be for this (like luke previous comment):

    pi@raspberrypi ~ $ sudo ldconfig -v | grep librf
    ldconfig: Path /lib/arm-linux-gnueabihf' given more than once
    ldconfig: Path
    /usr/lib/arm-linux-gnueabihf’ given more than once
    librf24.so.1 -> librf24.so.1.0

    Can you help me please? am i missing something?

    thanks in advance

    • March 2, 2014

      ldconfig is telling you he has already found other /lib/arm-linux-gnueabihf and /usr/lib/arm-linux-gnueabihf libraries link.
      Have you tried to move on the next step?

      • Hduque #
        March 2, 2014


        Thanks for your quick response.

        Yes, i have moved to the next steps. I have test “sudo ./switch -f on” and i get “Failed, response timed out”.

        I have double check the connections, but it is ok. Maybe my problem is in the Arduino side (i have use Arduino uno). Right now, the Arduino sketch is showing a message when is compiled, it says “printf_begin was not declared in this scope”.

        I have run the scanner to, and it shows something like this:


        I am really sure that i am doing something wrong, but i can`t figure what.

        If you can give me some tips i’ll really appreciate and i wil try to get it work.

        Thanks again.

        • March 3, 2014

          Have a double check at the wires first. We’ve exchanged pins so many times! We have a UNO around, so if you want we can have look. I don’t see the point why it should not work anyway. Keep in mind that we are planning a huge step up on this project in the next months. Plus, we have to work too :D So we’ll not have so much time to support all the requests of help we receive. Said that, since we would have really appreciated an help from someone who finally made it, we’ll reply as soon as we can, trying to keep everything updated.
          Have a nice day!

          • Hduque #
            March 3, 2014


            I will check again the wires and the pins, and i let you know how it goes.

            Thanks again for your replies.

          • Hduque #
            March 4, 2014

            Hi Guys

            Finally it’s working. Apparently the problem presented by the RF24 library was corrupt. I downloaded again and upload the sketch to the Arduino again, and it worked.

            About the printf_begin problem, what i did, was open the printf.h file in the arduino IDE, and the sketch at the same time. Upload the sketch and the message disappear.

            Thanks a lot for yur help.

  43. Ishu #
    March 2, 2014

    great project guys,
    i have tried it myself and am wondering if it possible to run “./switch -f on” through php execute function.
    Thank you in advance.
    keep up the good work.

    • March 2, 2014

      I think you can use it with exec(). Not sure though if you can run it with sudo.
      Have a nice day!

    • Mar #
      March 12, 2014

      Hi Ishu, I succeed to run the switch through PHP script using the exec() function and also .sh file in between the switch and PHP script. Part on which I spend the most of the time was correct rights of all the files and also the fact that I succeed only in case that www-data account has been set to work without password. PHP script then run the .sh file with one parameter which can be then passed to switch -f . When switch example is slightly modified then it can sand many kinds of commands to arduino. If more info neede let me know and I can add some more tips.

      Then I would also like to thanks for this great project.

      • VaSe7u #
        October 18, 2014

        Hi Mar,
        can you give more info on how you made it work, because I am a little new to Linux and I don’t know what .sh does and how to do the rest of the configuration. Thanks.

  44. JuanMi #
    February 28, 2014

    Hi there!

    Thank you guys for this fine article! It helped me a lot! I am involved in a project concerning Arduino and RPi communication and I suceeded connecting both.

    The starting point was your example code which I modified to my needs. It worked at (just) the second try! :).

    Again, thank you for sharing,


    • February 28, 2014

      You’re welcome!

      • GG #
        May 5, 2014

        Me too. Awesome – opens up lots of possibilities. Thanks!

  45. Tom #
    February 27, 2014

    Hi. Great project, thx! I have done everything and now i can switch one relay from Pi :) I’m trying to add some line to turn on second relay on board but need some help. Could You guys give me some tips? How should Arduino Sketch and switch.cpp looks like? Thank You :)

    • February 28, 2014

      Holaaaa Tom!
      You need to pass a different message to arduino for each relay you want to switch.
      Let’s say “1” is “turn on the R1 (relay 1)” and “3” is “turn on the R2 (relay 2)”.
      Remember you need a message to turn them off too. So, you’ll define “0” as a message to turn off R1, and “2” to turn off R2.
      With this pattern you’ll have all couples, with a pair and an odd number. The pair switch off, the odd switch on.
      Like this:
      R1 | R2 | R3
      0 – 1 | 2 – 3 | 3 – 4
      off-on | off-on | off-on

      We are working on something similar, but more “modular” on our side. More in the next week!

  46. luke #
    February 18, 2014

    hi *,

    maybe someone can help me. i dont get it. i suppose, that may this is the reason:

    pi@raspbmc ~$ sudo ldconfig -v | grep librf
    ldconfig: Path /lib/arm-linux-gnueabihf' given more than once
    ldconfig: Path
    /usr/lib/arm-linux-gnueabihf’ given more than once
    librf24.so.1 -> librf24.so.1.0

    i also checked “sudo modinfo i2c-dev”, witch results in “module i2c-dev not found”.

    any ideas?
    thnx & regards

  47. Camillo #
    February 10, 2014

    Hi, great tutorial and project!
    I am wondering if it is possible (and how!!!) to power the arduino part on a battery or coin cell and make it live for about an year or so.
    Thank you!

  48. kevingmgb #
    February 1, 2014


    I think this is a great project. I am working on a project that would send text from tweets from the pi to an arduino with an lcd screen using the nrf24l01. Every example I find out there for the pi is sending numeric information. I saw the serialchat example in the arduino and I am having a tough time replicating something similar to send a string across the radio. Anyway you could point me in the right direction?


    • February 11, 2014

      I think you should try send strings directly. Unfortunately don’t have the time to try it.

  49. kg77 #
    January 26, 2014

    I’m begginer in this technology…
    Is the revision 2 of Raspberry Pi really importent? RPiV1 and V2 functions of used GPIO pins are the same.
    I’ve RPiV1. Everything (preparation, and compilation are OK) but unfortunaltelly I’ve problem after run:
    ./switch -f on
    Preparing interface
    Segmentation fault

    Do you think that it is because of Raspberry revision?


    • January 26, 2014

      Hi! I’m on my phone, but at first shot I think you are missing a sudo before the command. Using gpio requires sudoers privileges. Have a nice day.

      • kg77 #
        January 26, 2014

        Exactly. Now it’s OK. Thx :)

  50. January 9, 2014

    Its a wonderful project and has a huge potential, I am from India, I am working on the same kind of project. Your project is a great help to us, My question is can we use nRF24LE so that data sent can be encrypted and to avoid arduino nano. Thank you once again for the resources.

    • Lorenzo Farnararo #
      January 9, 2014

      I digged around and I found some material to work on. First of all I wuold use AES simmetric key to do the job. Here some reference to a library written for NRF24LE1.
      I don’t understand why the WiFi module alone… if you want to explain us you project or link something we would be grateful!

      • January 9, 2014

        I don’t understand why the WiFi module alone… if you want to explain us you project or link something we would be grateful!

        Indeed, I don’t understand neither :D . That module (the NRF24LE1) doesn’t seems to have a micro-processor you could use as an arduino’s one. Plus,I think that if you would use it for encryption it would be better to keep it separated from other calculus, which right now belongs to arduino.

        If we’ve misunderstood please correct us, since we are looking for an “encrypted” solution too.
        Have a nice day.

  51. November 10, 2013

    Hi, really cool project you have there!..


    I’ve been working with the same project for the past 2 months and got the rpi and the arduino uno talking to each other via the RF24 unit(s). I also managed to get some PHP + MySql codes working to turn the relay OFF @ ON respectively.

    But the only thing that halted my project is the RF24 security, which if i’m not mistaken, transfers the data forth and back in plain form. I thought that it would be ‘dangerous’ if someone could just send a forged packet and my arduino would blindly accept it. So I’ve been googling around for a library that could be used both in RPI & Arduino Uno to encrypt the packets with no luck.

    So does the RF24 unit has any security implementation inside that i can use?.

    Thanks again for sharing this.

    • Lorenzo Farnararo #
      November 10, 2013

      Hi Mr.F. I don’t think the little RF24 has the dedicated hardware which can provide encryption. You’ll have to do develop it software-side both on the Raspberry Pi (not a problem) and the arduino (can be a problem).
      Like you, I mind very much about security, but for this little test I didn’t bother too much actually. Do you have so much “nerd” neighbours???

      If you would like to build something interesting, I strongly suggest you a symmetrical key (like AES). I’ve looked around the internet and I’ve found some arduino’s libraries [on the Raspberry Pi you have Debian ;) ]:
      Give it a try, but keep in mind that encryption is such an heavy task for an arduino.

  52. October 26, 2013

    Hi. Is it possible to control several nodes with only one “hub” (Raspi)?

    • October 26, 2013

      Sure, you’ll need to set different wifi addresses. You can pass these addresses to the RF24 library.

      On the arduino you identify them on the sketch with this code:
      // Radio pipe addresses for the 2 nodes to communicate.const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

      on the raspberry application (.cpp) with:
      const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

      • Jose #
        October 28, 2013

        Great, thank you! And, is it possible to create a bi-directional link? I want to send commands from Raspi to Arduino and receive sensor data back.

        • October 28, 2013

          Actually it is a bidirectional communication. Indeed, we’ve made arduino reply with the same message he received, to check if communication worked, but you can make him respond whatever you need.
          On line 92 of Arduino sketch you can change
          radio.write( &message, sizeof(unsigned long) );
          to deliver anything you want.
          Have nice coding!

          • November 4, 2013


            Ho acquistato questi moduli due mesi fa, poi li ho abbandonati per carenza di tempo e poca documentazione per ciò che mi serviva.

            Il mio progetto di impianto domotico è completo e volevo estenderlo in altre camere evitando di infilare cavi inutili in tutta casa, se ti interessa puoi cercare DomoHome su YouTube tanto per farti un’idea..
            Detto questo.. non ho ancora dato un’occhiata al source in js, ma probabilmente non farà altro che chiamare l’applicazione compilata in C a runtime, mi sbaglio?

            Il mio problema più grande è che il mio progetto è scritto interamente in python su Raspberry, e ci ho impiegato moltissimo tempo per scriverlo da zero, quindi doverlo riscrivere in C non saprei da dove partire.

            Ho tutto l’occorrente a disposizione, mi servirebbe giusto un consiglio sulla giusta pista da adottare..

          • November 4, 2013

            Hi Angelo,
            we’ve seen your awesome project on youtube. The road we’ve taken is definitely more “wireless” :D
            Js instructions are interpreted by a binary file pre compiled written in C++. This binary interface itself with RF24 libraries written in C (If I remember well) which probably (almost surely) have a python sub layer.
            To be able to use those libraries you should unmount them or look for the pre porting version. From there, I think the rest is pretty easy.
            Next time could be better to write in english, so all the world can take advantage from your doubts and projects.
            Thank you again for you participation!

            Ciao Angelo,
            abbiamo visto il tuo fantastico progetto su youtube. La strada che stiamo percorrendo noi e’ decisamente piu’ “wireless” :D
            Le istruzioni js vengono interpretate da un binario pre compilato scritto in C++. Questo binario si interfaccia con delle librerie per RF24 in C (se non sbaglio) che probabilmente (quasi sicuramente) hanno un sub layer in python.
            Per sfruttare queste librerie dovresti smontarle o cercare il pre porting. Da li’ penso che la strada sia abbastanza in discesa.
            La prossima volta sarebbe meglio tu scrivessi in inglese, in modo che tutto il mondo possa trarre vantaggio dai tuoi dubbi e dai tuoi progetti.
            Grazie ancora per la partecipazione!

          • November 4, 2013

            I found a wrapper written in python a month ago but it didn’t work due to different configurations. I’ve learnt that you need to set different params in order to let them communicate.

            Is there a way to talk to you directly and share some information to let this project work for a lot of people like me who codes in python?

          • November 9, 2013

            Sure, althought I have to tell you that I do not have so much free time (like you see). My email is edo “at” lenotta.com

          • November 16, 2013

            In these days I found the time to write down a wrapper to send data from Raspberry through nRF24L01. It’s simply to use, it accepts three parameters.. the sender address, the receiver address and the message coded in long long unsigned int.

            Thanks to this wrapper the only thing you have to do is to configure the receiver, in my case an Arduino Uno, in order to understand your messages.

  53. October 6, 2013

    Cool project! I’ve been working on something like this for my desktop computer. By any chance, do you know what the current draw of the Raspberry Pi is when it’s idle waiting for a command?

Leave a Reply

Basic HTML is allowed. Your email address will not be published.

Subscribe to this comment feed via RSS