Featured

Search

LED DIMMER with Leapmotion Arduino and Processing

leap motion tutorials                      

     Led Dimmer With Arduino and LeapMotion controller              


Hello In this quick tutorial we will learn to control the intensity of LED by using our hand gesture with Leap motion controller and arduino. If we are going to closed our hand the intensity (light) of an led is going to dim bit by bit. When we completely closed our hand grip the led is turn OFF.
Similarly when we open our hand in front of leap motion device the led will be turned ON and when we fully open our hand the led will  glow with full intensity.
Its the same as using Duty cycle (pulse width modulation) of Arduino for fading Led. But here is the concept of using hand gesture to control the fading led instead of using duty cycle ( Pulse width modulation).
If you are get used with Leapmotion technology then its very easy to understand the programming about hand gestures. If you didn't get used with it yet so don't worry about it. See that link what-is-leap-motion-controller   it will help you to understand the basics.

As in PWM we are using duty cycle from 0% to 100% to controlling anything for analog but here in this case we are not using the commands of pwm for any percent but we makes the hands gestures to do the same work of pwm foe fadding lamp.If the hand is half open its mean 50% pwm goes to the output and this process is same for 25 % or 75% and others.

Components  

  1. Leap motion controller
  2. Arduino uno
  3. Led
  4. 220 ohm resistor 







Circuit diagram and video are shown 
                                         https://www.youtube.com/watch?v=Q-PasppInoQ

For Interfacing 3D gesture technology (leapmotion controller ) with arduino we are using Processing software for leapmotion device and Arduino IDE software for arduino controller. By serial communication of both device we are controlling the fading led by hand gestures.
For understanding the basics of how to communicate the leap motion to arduino Click how-Integrate-leapmotion-controller-with-arduino 

Programming of Processing for Leap motion



 First of all use the command to import the library of leapmotion. With this library the leap motion works otherwise it will not works. For download the library Click How to download leapmotion library



Import the serial processing for serial communication of arduino with the leap motion technology. For this command if there is changing thr grip open or closed the communication will move to arduino and arduino change the brightness of led. Its same like pwm. When we uses PWM for fading it can fad bitween 0 to 255 means 0% to 100% of pwm but in our case this process will goes with hands. Hand closed means 0% and hand fully open means 100% and in the middle it will depend on you how much your hand open like 25% or 50% its same as done in pwm. 








 Here we are making class of leap and giving the port to arduino for serial communication with leapmotion and also set the baud rate 9600. Remember if it isn't working or giving error change "[0]" to you port number in which your microcontroller is connected.

void draw() {
  background(0);
  for (Hand hand : leap.getHands()) {
      pushMatrix();
      float handSize = hand.getSphereRadius();
      int handSize2 = int(handSize);
      myPort.write(handSize2);
      println(handSize2);
      popMatrix();
    }
}

Here setting the background color black. Get the size of hand sphere radius and write it to the port. 

Programming of Arduino

int val;
int led = 13;           // the pin that the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup()  {
  Serial.begin(9600);
  pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop()  {
   if (Serial.available() == '\n') { //  Check if there is a new message
      val= Serial.read();
  val = map(val, 30, 165, 0, 255); // map(value, fromLow, fromHigh, toLow, toHigh)
    analogWrite(led, val);
   }
}

     Connect the Led with pin # 13 of Arduino. Read from processing port of leapmotion controller and get the size of radius of palm of hand. Map the value of radius of  hands palm to duty cycle of led and write it by analog command. That's the program for controlling 3D technology to hardware using microcontroller.

Hope you Learn a lot from this.
If you have any query please inform us so our team can help you thanks.
Previous
Next Post »

Featured