If you like this project please vote for it in the "Sensors Contest 2016" as it took me a lot of time to make it (pressing the top-right button that says "Vote").

* Have you ever wanted to use hand-gestures to control the music, a robot or any other thing but you just didn't know how? Well, now you can! And it is super easy and cheap to build! You can turn on or off some lights, control the speaker volume, open and close an automatic curtain and a lot more - the things you can do are limitless!

You can also transform your speakers, PC, or any other electronic device from something ordinary to an exclusive high-tech gadget! *

I made this sensor because I wanted to add something cool and original to my projects while keeping them cheap and user-friendly. There are a few sensors out there that recognise gestures but they are way too expensive, like the APDS-9960 sensor based breakout board, which costs around US$20.

When I started this project I wanted it to be cheap, easy to build, precise and faster than the APDS-9960 sensor. And I achieved it. By using four IR receiver photodiodes we can make an algorithm to detect the type of gesture by analysing their voltages. Ex. A left-to-right gesture (or right gesture) will make an increment of the values of the top left and bottom left IR receivers which then will decrease, right before the values of the top right and bottom right receivers increases too. This will be analysed by the Arduino which will determine the type of gesture and send it over the serial port.

In the next steps I will be showing how to build this sensor. So, let's move on!

Step 1: Component List

To build this awesome project you need:

  1. 4 IR-emitter LEDs.
  2. 4 IR-receiver photodiodes.
  3. 4 220O resistors (used to limit the emitter LEDs forward current. If you want a higher range then use smaller resistors).
  4. 4 100kO resistors (each one of them used as a pull up to read the receiver photodiodes).
  5. Some black electrical tape.
  6. An Arduino UNO (or any other development board with four analog pins and four digital pins or more).
  7. Python 2.7 to control VLC (Optional).

Step 2: How It Works

When I started this project the most difficult part was finding the moment to store a value and compare it with the current IR value to determine the type of gesture. At first I saved a value every 100ms, but it was very inaccurate. It had a lot of false positives, especially when doing a "down" gesture. So I made a way to auto adjust the sensitivity based on the higher value. That didn't work either.

I was banging my head against the wall. I spent 3 weeks modifying and testing the code until it finally came to my mind the best way to store these values: arrays. The delay needed to completely turn off the IR LEDs (2ms) plus the delay needed to turn them on (1ms) make the perfect interval to store the IR values (100 values per array, 1 value per 3ms, 300ms of values stored in each array). By using this method the gesture detection process has improved a lot. There aren't any false positives now and the "down" gesture is perfectly recognized. This was the main goal: to make a reliable gesture sensor while keeping it cheap and easy to build.

The way it works is the following: The Arduino reads all the sensors and, if any value is greater than 0 then it is stored in the arrays. When there are two or more elements in those arrays the Arduino starts looking for a pattern in the IR values to determine the type of gesture. For example: if the Top Left and Bottom Left IR sensors detect something then the booleans "rising_TL" and "rising_BL" will be true and the expected gesture will be "east". After that, if the Top Right and Bottom Right IR sensors detect something but the TL and BL don't (so "decreasing_TL" and "decreasing_BL" will be true) then the gesture IS "east" and the Arduino sends this over the serial port.

If you can't understand this try to imagine your hand moving from left to right. When it is above the left sensors a lot of IR light will be reflected, thus they detect that there is something above them. When you keep moving your hand and it is above the right sensors they will detect that there is something above them, but the left sensors won't detect anything. Based on this the Arduino can accurately tell the type of gesture made.

Step 3: Diagram & Tips

You need to connect all the components as they are in the diagram. Depending on the distance between the sensors you will need to twist them a little bit so their angle is less than 90°, pointing outwards. The recommended distance between them is 5cm*5cm or 6cm*6cm. You can separate them more but you will need to use more powerful IR LEDs. If there isn't sufficient distance between the sensors you will need to twist them. Otherwise, the Arduino won't accurately detect the type of gesture.

Note: the IR sensors are connected in a reverse biased way (5V---100kO---A0 and IR photodiode CATHODE (-), IR photodiode ANODE (+)---GND)

Step 4: The Code

The Arduino code is attached in this step.

Note: It doesn't require any type of adjustment unless you want to change the calibration variable or the "hold action" timer.


Step 5: PC Program (Optional)

In this step I attached the source code (.py) and the .exe. You don't need Python to execute the .exe, but you do need it (with the requests and pyserial library) if you are going to use the source code. You will also need VLC. Tested with Python 2.7

Note: You need to change the VLC password (set up in the LUA configuration) and the serial port. To set up LUA in VLC go to:

AMSC, step #4


Step 6: That's All!

That's all! Enjoy this sensor as I enjoyed creating it! The next time you are with your friends or family they will be astonished!

If you like this project please vote for it in the "Sensors Contest 2016" as it took me a lot of time to make it (pressing the top-right button that says "Vote").

Hello Nicolas Sir!<br>I am Aman Kushwaha, and I am a absolute arduino beginner,<br>And,.. this is a awesome instructable, but i need some help...<br> i am making a project with LDR &amp; IR sensors &amp; 16x2 LCD and i just need simple coding help.<br>So, how can I contact you sir?<br>Thanks. Any reply will help me a lot!
Hi. Already sent you an email.
How to connect it to rpi 3?
<p>Hi. </p><p>You have two ways of connecting this sensor to a raspberry pi. The most easy one, using an arduino (or similar microcontroller) as the brain of the sensor, and connect it to the rpi via any bus (I2C, SPI, 1WI, UART, or even your own protocol). </p><p>The other way that I think of is using the rpi as the brain, but for that you will need at least 6 pins (if you charlieplex or multiplex the IR LEDs) or 8 pins and you need to port the code. </p><p>As I have never had a rpi, I can't help you coding, but I can answer any question you may have.</p><p>This is my email if you want to contact me:</p><p>iosnicoib@hotmail.com</p><p>Nicolas.</p>
<p>This is an amazing build. Do you have plans to implement this in a future project?</p>
Thank you! I am going to implement this in a future project, but it is a secret! When I finished it I will upload an instructable.
Awesome build!
Thank you very much! I would really appreciate it if you vote for this instructable in the Sensors contest 2016!

About This Instructable




More by Nicolas Britos:RGB LED VUMeter Python Library LPD8806 VUMeter with PC & Arduino + GUI DIY Arduino 3D IR Gesture Sensor 
Add instructable to: