Posts by Lorenzo Farnararo

[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


If you are encountering problems while receiving or transmitting, like packet loss, consider adding a capacitor of 10 μF between the pin 1 and 2 of the NRF24l01+, with ground capacitor side on pin 1. You should do this on both the modules, on raspberry and arduino.

Capacitor on NRF24l01+

Capacitor on NRF24l01+


Our plan to communicate between all this stuff is to use a Node.js application to run a binary ‘sudo ./remote  -m 81‘ and ‘sudo  ./remote -m 80‘  sending a message to the Arduino with the text 81 and 80 . The message is composed by pin identifier (8) and action to perform (0|1|2). After the action has been  read, all the other numbers identify the pin which the action refers to.

When the arduino receive it, it then sends back an acknowledgment packet to the raspberry with the same message (yeah, like a parrot), except for action 2, which will not perform any action, but will reply with actual state of the pin. In the meantime, if the message the arduino receive is 1  it will close a relay (turning on a light, like a good parrot), 0 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

For Raspberry Pi 2 users: some of our readers pointed out that this library is a bit outdated for the Raspberry 2 and it’s encountering some problems. Until we have time to update the article, please refer to this post on the Raspberry Official Forum to solve the “Preparing interface” stuck problem (kudos to Andrei).

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:

At this point, with the RF24 library installed, you can use the compiled remote application or compile it yourself with make command:

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


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.

Update  (2/12/2014)

I’ve cleaned and updated the code to the latest RF24 libraries from TMRh20. I’ve managed to submit a bug (issue #46)of the RF24 lib to the TMRh20 github account, and apply the workaround he proposed.  Unfortunately it looks like the modules needs time between communications, it’s a known bug that right now we don’t have time to fix. If you would like to fork the RF24RaspberryCommunicator project, magically fix it and make a pull request, we would love it. Right now, since we do it for free, we don’t have time to fix it. Hope you like it.  Edo.

Update  (17/01/2016)

For the Raspberry Pi 2 users who got stucked at “Preparing interface” message, please refer tothis post on the Raspberry Official Forum .


Have Fun!



Arduino Gardening

Arduino Gardening

It’s a burning summer in Florence and I needed a solution to watering my little plants I have around the house.

Of course I had a look at some shops for a ready solution, but where is the joy of experimenting with an arduino?

First thing to do in this case is to know what you want, and where your project could drive you. It’s nice to fly high with ideas, but to make them affordable you have to take off first.

So here we are with our project/tutorial: a time programmed irrigator which will water my plants for 1 minute, once a day, on alternate days.

The whole thing costs around 25$ (we’ve bought almost everything from china).

What we’ve used


Wiring Diagram

Wiring Diagram


I wanted to make arduino water my plants on alternate days, so we had to add a little function ‘dayOfYear’ which will tell us (guess what?) the day of the year it is. Example: February 1st is the 32nd day of the year, and our function will return ’32’.

Maybe there was a better solution, or it was already implemented, but this way was faster for our purpose.

If the day number it’s even and the time correspond to what I’ve set, it will close the relay (and the valve will open).

We’ve used the RTClib (with the little edit I mentioned about ‘dayOfYear’) to control and read the RTC.

The Sketch

The Function We Added

We have modified the class DateTime in RTClib.h as follow:


and added  the following function to RTClib.cpp:


Possible Developments

As you’ve seen this is a really stupid implementation, but it was on our purpose to make it stupid and not including any sort of display.
In fact, the main project is a little bit bigger than just a programmable Garduino (as someone calls it).

What we have in mind is to make the Garduino just an interpreter for our garden architect “Mr Rasp Gardner”, a raspberry pi which will communicate with the arduino using the NRF24l01+ module we tested here. As you can imagine, this drive us to an intelligent gardener, a nice web interface, statistics and much (much) more.


One of the first thing to implement, apart wireless communication, could be a simple hygrometer which will tell us if the plants have actually been watered. Maybe next week.


Cfeon Q23b-104

We made it!

After thousand of tests, passing by a serial tftp boot, trying jtag reprogramming we finally get back the wr841nd (ver.8.1) to life!


We followed an OpenWRT guide that you can find over here

Well… we disassembled the flash of another working router with a very small soldering iron tip (all the merit goes to Edo).

Then we connected to the serial of the router via an arduino adapter. Doing this we cuold connect to uboot (remember the “tpl” keys for getting to the uboot console!!).

From the console we dumped all the files of the flash into the ram with the command:

The command is: copy the content of the flash (0x9f000000) to the ram (0x81000000) for the lenght (0x3effff)

Then we reassembled the old broken flash and copied all back in that one with the command:

And doing this we restored uboot in the broken flash. After this we reinstalled OpenWRT via the tftp server mode with the following commands:

Finally we had a working router!

The first link of Ninux Firenze is now online! I am now connected to Leonardo via a radio link in the 5GHz bandwith. Let’s summarize the installation, I’ve needed:

  • Ubiquity NanoBrige M5 25dBi
  • IP56 waterproof container
  • 20 m of corrugated pipe
  • 20m of STP cat  5e cable
  • 2 shielded 5e plugs

The first thing to do was making a hole from a room in the top of the house for the cat 5e cable and the current. I used a 40 cm drill for this dirty job. Luckily I already had an antenna of a wisp.

Hole inside the house

Hole inside the house

Hole from outside

Hole from outside the house

The next step was mounting the waterproof container. I drilled four  holes and mounted the container on the wall outside the room. Inside I’ve mounted 4 sockets for the current.

Later  I’ve isolated the holes for the screws with some silicone and drilled some little holes in the bottom of the container for letting water goes out in case of condensation.

Container with sockets

Container with sockets

Next the roof part. I’ve passed the cat 5e cable in the corrugated pipe, attached the pipe to the container and  the antenna on the roof.

The route of the corrugated pipe

The route of the corrugated pipe

Preparing the antenna for the roof

Preparing the antenna on the roof

The node is now up and running! May the wireless be with you!

By continuing to use the site, or scrolling, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.