Introduction: Interactive Handrail With Arduino

What is this project about ?

The concept is quite simple : a downlight that follows the steps of the user.

Now, I applied it to a handrail, but once you understand the principle, you will be able to put it pretty much anywhere.

My demarch was to mimic the move of a living creature, a kind of a "pet made of light" that will accompany you during your trip... in the staircase. In order to achieve that, a perfectly clean and fluid move of the light is absolutely necessary.

let's get started

Step 1: Body Sensing Principle

In order to get a smooth displacement of the lighting spot, you will need a clean, noiseless way to detect where the user is. If the readings are not perfectly stable, the light will jump around, even a little, breaking the "magic touch" of the device.


ultrasound and infrared ranging sensors ?

I first tried with ultrasound ranging sensors, several types (generic ones and also a more pricey from maxbotics), with very little success : It kind of works, but there is quite some physical limitation to this method. First, depending on the clothes you are wearing, the sensors works more or less well (especially the ultrasound ones). Second, for the IR ranging sensors, there is a max range and a min range at which the device will measure the distance, meaning that you will need a least 2 different models. Plus, either way, the readings are quite jumpy, and that is a real love killer for this project.

my way to go : a serie of DIY proximity sensors

Instead of trying to measure the distance from the user to one end of the handrail, I will put in place several contactless switches (16) along the handrail. You can do it by several methods, in my case I used infrared phototransistors : those are cheap, easy to understand and mount and very discrete. They will "see" the infrared reflected to them from the user. And to emit those infrared, you just have to put some infrared LEDs parallel to the phototransistors and pointing toward the user's body. You can use a infrared LED tape as well I suppose, it will be even easier to make!

16 ON/OFF contactless switches

As a arduino uno or nano doesn't have that much input, you will have to multiplex all the sensors data.

A multiplexer, despite a seemingly complicated name, does something very easy to understand : it will link a unique pin to another one (among 16). The path unlocked will depend on a binary code you will send to 4 other specifics pins.

those are the codes to send to the pins, in order (from pin 1 to pin 16):

0000, 0001,0010,0011,0100,0101,0110,0111,1000,1001,1010,1011,1100,1101,1110,1111

Yes, those are the numbers from 0 to 15 in binary.

All multiplexers work the same way, you can use the one you want, you just need a 16 channels.

Step 2: The Circuit

Material list

  • 1 arduino, I used Nano but any will do
  • 16 IR phototransistors (5mm)
  • 32 IR LEDs 5mm (use the same wavelength as you phototransistors) OR a IR LED tape
  • 1 multiplexer 16 channels (I used HF 4067)
  • 1 blank PCB
  • 1 power plug (or screw terminal)
  • 1 power supply (5V with a lot of amps : 7 or 8A )
  • a ribbon cord at least 16 wires.
  • 16x 27 ohms resistors (for the IR LEDS)
  • 16x 47 Kohms resistors (for the phototransistors)
  • a 6V1000uF capacitor
  • a LED addressable strip (APA102 or WS2812B)
  • wires...

Luckily, the PCB will be very simple. You just need to be aware of the order of the cables from the sensors to connect to the multiplexer. Using a rainbow ribbon cable will help a lot!

Then, from the output of the multiplexer, only one cable will be needed to connect to a arduino analog input (the pink one on the picture). And this is very neat!

Then the 4 control wires (the orange ones) will go from arduino pins 7,6,5 and 4 to the multiplexer control pins. Why 7,6,5 and 4? because we will be able to activates those pins in a single line of program, sending the binary code via the port manipulation method.

to read about port manipulation ( don't fear the word, it is pretty simple to understand) : https://www.arduino.cc/en/Reference/PortManipulati...

next you will need an addressable LED strip.

Any will do, I used APA102 (the good old WS2812B will work as well, and with just 3 pins). Link it up to the arduino, data pin (and clock pin if your LED strip needs it), and the power (5V). Last thing, adding a 1000uF to the power input of the strip is a wise decision.

Step 3: The Build

Obviously, the first thing you have to find is a rail of sort. I used a plank of flooring, 12mm thick Merbau. I just glued a slice of it on the upper part to make a thicker part for the hand to grip on.

The LED strip can be secured on a plastic extruded profile L shape on the bottom of the rail, all along.

Every sensor is just composed of 3 holes (5mm) for the LEDS to fit in (phototransistor in the middle, one IR LED on each side)

The PCB can be enclosed in a plastic box, or let free, just secured to the inner side of the handrail with screws.

Last, to fix the whole thing to the wall, I used L metal brackets that I screwed to a cubic wooden block I put on the wall with screws. This part is very specific to my home, you may have to be a little bit creative here.

Step 4: The Code

You can access it here : https://github.com/Benn25/handrail

I won't go in depth with it, just highlight a few things

Every sensor state, triggered (1) or not (0), will populate an array of 16 elements. Typically, the result will be something like 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0 if the user is close to the left end of the hand rail. now, imagine that the user moves just a bit toward the other end, now the result is 0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0. Yes, 2 sensors are triggered now because the user is between 2 sensors. The location of the light is computed every loop after reading all the sensors : the average position is where the light aims at. This method will virtually double the number of sensors increasing dramatically the density of the sensing apparatus, increasing at the same time the fluidity of the movement of the light!

Second thing : the dynamic of the movement is also computed every loop, this way I can track the speed of the displacement of the light, and it will also allows me to smooth down the movement of the light by a predefined factor to avoid any erratic jumping of the light.Thanks to those data, I have the speed of the user, and I can change the color of the light depending on this!

Last : the threshold at which the data from sensor will be interpreted as 1 or 0 is floating. meaning that the system adapts itself permanently to the level of environmental IR in the room. so you can have the sun directly hitting only a part of the rail, the system will auto correct after a while (around 5 sec).

Step 5: Going Further

want to add options?

I experimented with a folding model. I used a barometric sensor to change the light when nobody is detected according to the atmospheric pressure : high pressure = reddish, low = blue. The video is self explanatory.

If you have other idea, please do tell me in the comments !

one last thing : the way I chose to program the thing do NOT allow 2 people to use the device at the same time, the light will go between the 2 users (average position).

It is a choice, I did it this way by using the average position of the triggered sensor in order to reduce the noise in the move as much as possible, but you can totally make a 1 : 1 detection/enlightenment pattern where the triggered sensor will light up the corresponding area without any post process.

Arduino Contest 2019

Participated in the
Arduino Contest 2019