How to control servo motor using Leapmotion and Arduino

Control Servomotor For Making Robotic arm with Leapmotion and Arduino

processing leapmotion arduino

Hello everyone,

In this quick tutorial you will learn how to control servo motors with Leapmotion controller using Arduino. The technology of this 3D motion detector sensor made a great change in our projects. The world is now controlling electronic devices with the leapmotion controller.
The aim of this post is to show you how to control a servo motor and then leads it to control a robotic hand with the help of motion detector sensor using with arduino. In this post we will look couple of platforms that can get you to right and easiest way of control and use of 3D sensor technology.

For getting started with it. First of all you should know about the Leap Motion technology. Its all about your hands detects in 3D frame.  It detects your hand, wrist, elbow and also worked for your shoulder while you are making an robotic arm with it. This motion sensor senses your waving hands and show it in 3D form. It tracks 200 frames per second with its cameras. it has ability to detects both hands, fingers and things look like fingers. From the hardware prospective the motion detector sensor is quite simple. It has consist of two cameras and three IR (Infra rays) leds that makes an area of detecting hand, wrist etc.
The charm of this Leapmotion technology increase when its join with real world hardware. These all can be done with the help of microcontrollers like Arduino, Raspberry pi etc.

                                                Link to video https://youtu.be/_fkQL76pp6M

For connecting hardware with leap motion sensor using arduino there will be two software used. The controlling purpose of 3d motion controller device we used Processing software. Processing is a open source computer programming language. Java based software in which we are programming in java language. It has collection of libraries that helps to control the commands of leap motion controller and then sends these all commands to arduino. Download the processing software and its libraries if you don't already have installed Click processing software and library for leap motion and arduino

Here we are using Arduino as microcontroller to communicate Leap motion controller with hardware's like servomotor. The simply work is read data from leap in the form of you hand gestures in X, Y, Z axis and pass it to arduino for arduino basics getting-started-with-arduino you dont't have to install any extra library in arduino software. There is builtin library in it.

For controlling servo motor with leapmotion and arduino we are using the y-axis of leap device to control the angles of servomotor. We are sending the commands via serial ports of processing to Arduino IDE.

In processing you can used leap motion controller of any axis X, Y, Z but we are using x-axis to control our servo angles from 0 to 180 degree. This is seems something out of science fiction to make a movement of physical things by only gestures of your hands but we just made it in reality.

Circuit Diagram

Attach servo with pin # 9 to control it with Hand gesture recognition technology. Make sure that vcc is connected with 5volt and black wire of motor connected with Ground. After uploading the code which is given below it turns first 0 degree then tracks gestures on y-axis and changed its angles as per gestures changes.

Coding For Processing

Firs of all in the coding of processing import the library of leapmotionp5. Remember that the library given in my previous post is only best when you are using it for led blink function. Fro servomotor you have to add new library of motion sensor name leapmotionp5. This library can used for controlling servomotor. Here i am giving you link for downloading the library for servomotor LeapMotionP5 Library 
Download this library and add it to the inside of processing folder libraries. Note that you can use only one library at a time so remove the previous library of named leapmotion for processing. For removing the previous library open you processing software click sketch then in drop down list click add library and remove the library of leapmotion for processing.

Here  import com.onformative.leap.LeapMotionP5; is import all the functions of 3D technology sensor.

 Here import command of fingers. Leapmotion can detect all fingers, wrist angles, palm, pitch, yaw, roll and waving of hands these all the process that can be used for controlling servomotors with leapmotion controller with arduino. With the help of cameras motion detector sensor captures the images and process them to see which gesture is exactly move. It can only works if gestures moving in a limit. Limit of motion control sensor is form 1 inch to 2*2 feet.

Making a class of leap and making an integer of name angle which is used further for storing the angles of servo motor and sens it to arduino. import processing.serial.*; used to communicate the processing software commands and sends it to arduino via serial port. At detection of gestures in motion sensor along Y-AXIS the perticular value assigned to servomotor via leapmotion controller then processing and arduino interchanged the value with each other by serial communication.

In setup when run the program in processing a new windows open. Size of new window is 720*720. In this windows you can see the 5 fingers dots. You can change the size of window its up to you. If you waving your hand gestures after recognizing the movements of gestures your gestures shown in that window.

Here make thw positions of gestures and mount it on angles of servo. As mention above when you run the program a new window open which is 720 height and width. This window is used for controlling position of servo with 3D hand recognition technology. If hands at above the 720 size the servo angle move to 180 degree. If the position of hand gestures are below the zero the angle turns to 0 degree. In between the windows the angle has formula of y-axis divide by 4.

Coding For Arduino

Controlling hardware with motion control technology needed a microcontroller which controls the hardware practically. Arduino has a simplest programming that's why we called it sketch. That's easiest way to control 3D motion controller device with real world hardware.

First include servo library which is already builtin its software. First check your servo with simple examples to know its working or not. Click how-to-control-servomotor-with-arduino Hope your servomotor is running fine. Lets move further with servomotor, Leapmotion and Arduino.

 In setup attach your servomotor in Pin # 9 as shown above in Circuit diagram. Communicate serially with serial.begin command with the baud rate of 9600. Baud rate can also be changed if needed.

Read serial if available means read the angle from processing or whatever values coming from processing via hand detection. Saved in variable named angle and write it to servomotor. Remember that values are within 0 to 720 range. what ever gestures comes to leapmotion controller the processing tracks and send data to arduino that moved servomotor at some particular angles. Full code and video tutorial will be uploaded soon.

Hope You like this How to tutorial (How to control servomotor using leapmotion controller and arduino).

There will be much more so click the Follow Button!

If you have any query so we are always here for your help. Thanks 
Next Post »