Arnaud TaffanelKristoffer Richardsson
Published

Touchless Mouse

Using an optical flow sensor to turn gestures in the air into mouse movements.

BeginnerFull instructions provided30 minutes12,958
Touchless Mouse

Things used in this project

Story

Read more

Schematics

Touchless mouse schematic

Code

Touchless mouse

Arduino
Works on Arduino that has USB device capabilitie. Tested on Arduino Leonardo.
#include "Bitcraze_PMW3901.h" 
#include <Wire.h> 
#include <VL53L0X.h> 
#include <Mouse.h> 

VL53L0X rangeSensor; 

// Using digital pin 10 for chip select 
Bitcraze_PMW3901 flow(10); 

void setup() { 
 Serial.begin(9600); 
 // Initialize flow sensor 
 if (!flow.begin()) { 
   Serial.println("Initialization of the flow sensor failed"); 
   while(1) { } 
 } 
 // Initialize range sensor 
 Wire.begin(); 
 rangeSensor.init(); 
 rangeSensor.setTimeout(500); 
 // Initialize Mouse 
 Mouse.begin(); 
} 

int16_t deltaX,deltaY; 

void loop() { 
 // Get motion count since last call 
 flow.readMotionCount(&deltaX, &deltaY); 
 // Get single range measurement 
 float range = rangeSensor.readRangeSingleMillimeters(); 

 // Send motion as mouse movement when the hand is between 80 and 200mm
 if (range < 200 && range > 80) { 
   Mouse.move(deltaX, -deltaY, 0); 
 }

 // Press the left mouse button when the hand is bellow 50mm
 if (range < 50) { 
   Mouse.press(); 
 } else { 
   Mouse.release(); 
 } 
} 

Credits

Arnaud Taffanel

Arnaud Taffanel

2 projects • 14 followers
Kristoffer Richardsson

Kristoffer Richardsson

3 projects • 8 followers
Developer at Bitcraze

Comments