# Processing + Leap Motion data + Arduino LED pins

**URL:** <https://discourse.processing.org/t/processing-leap-motion-data-arduino-led-pins/1689>\
**Category:** Beginners\
**Created:** [July 11, 2018, 1:53pm UTC](https://discourse.processing.org/t/processing-leap-motion-data-arduino-led-pins/1689 "2018-07-11T13:53:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamamiwhoami91](https://avatars.discourse-cdn.com/v4/letter/i/df705f/32.png) [@iamamiwhoami91](https://discourse.processing.org/u/iamamiwhoami91)\
**Post date:** [July 11, 2018, 1:53pm UTC](https://discourse.processing.org/t/processing-leap-motion-data-arduino-led-pins/1689/1 "2018-07-11T13:53:40Z")

</div>

Dear all,

I am trying use the Leap Motion sensor data to turn LED pins on and off using Arduino. Right now I am using a processing code that controls LED pins according to the hand position (x). I am trying to figure out how to make the LED pins turn on according to how many fingers are being detected. Can you please help me?

PROCESSING code I am using:

```auto
// An array of LEDs lit up by LEAP motion on an ARDUINO
// LEAP libraries
import de.voidplus.leapmotion.*;
LeapMotion leap;
// Serial Port Output
import processing.serial.*; // Serial libraries, send OUTPUT through USB
Serial myPort;
int ledPin;
int checkPin;
void setup() {
  size(800, 500, P3D);
  background(255);
  noStroke();
  fill(50);
  // New port object
  myPort = new Serial(this, Serial.list()[3], 9600);
  // New leap object
  leap = new LeapMotion(this);
}
void draw() {
  background(255);
  // Leap magic
  int fps = leap.getFrameRate();
  // Clean LEAP Hand position
  for (Hand hand : leap.getHands()) {
    hand.draw();
    PVector hand_position = hand.getPosition();
    // println(“Hand on X: ” + hand.getPosition().x );

    // Determine ledPin according to mapped hand x position
    checkPin = (int) map(hand.getPosition().x, 0, 700, 8, 14);
    if (ledPin != checkPin) {
      assignPin();
    }
    // Send ledPin number through port
  }
}

void assignPin() {
  ledPin = checkPin;
  myPort.write(ledPin);
  println("Serial Output: " + ledPin);
}

void leapOnInit() {
  // println(“Leap Motion Init”);
}
void leapOnConnect() {
  // println(“Leap Motion Connect”);
}
void leapOnFrame() {
  // println(“Leap Motion Frame”);
}
void leapOnDisconnect() {
  // println(“Leap Motion Disconnect”);
}
void leapOnExit() {
  // println(“Leap Motion Exit”);
}

```

ARDUINO code:

```auto
// Arduino sketch turn LED on via serial input from Processing
// Define main variables
int ledPin = 0;
int currentRead;
// Slowing down the process
//unsigned long millisCounter = 0;
//int interval = 10;
// activate the pins I want to use on my board
int myPins[5] = {
9, 10, 11, 12, 13};
void setup() {
// Activate all Digital pins on my board
for (int i = 0; i < 5; i++) {
pinMode(myPins[i], OUTPUT);
}
Serial.begin(9600);
}

void loop() {
if (Serial.available()) {
currentRead = Serial.read();
if(currentRead != ledPin) {
digitalWrite(ledPin, LOW);
ledPin = currentRead;
digitalWrite(ledPin, HIGH);
}
}
}

```

I tried using the hand.countFingers function but it does not work, I would appreciate if someone could help me out with this 😊

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [July 11, 2018, 2:37pm UTC](https://discourse.processing.org/t/processing-leap-motion-data-arduino-led-pins/1689/2 "2018-07-11T14:37:30Z")

</div>

For starters, drop the arduino part. Instead, make sure you get the leapMotion’s functionality that you want to use working first. Have a look at previous discussions: [https://forum.processing.org/two/search?Search=leapmotion](https://forum.processing.org/two/search?Search=leapmotion)

Kf
