Nexus Electronics
Published © GPL3+

Hand Gesture Volume Control

Use gesture sensing to turn hand movements into keyboard inputs.

BeginnerFull instructions provided1 hour264

Things used in this project

Hardware components

QT Py
Adafruit QT Py
×1
SENSE: Multipurpose Sensor Development Board
×1
Adafruit Monochrome 128x32 SPI OLED graphic display
×1
SparkFun Qwiic Cable Kit
SparkFun Qwiic Cable Kit
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic

Code

SENSE_Gesture_Sensor_Volume_Control.ino

C/C++
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library. 
// On an arduino UNO:       A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO:   2(SDA),  3(SCL), ...
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
  
#include "Adafruit_APDS9960.h"
Adafruit_APDS9960 apds;

#include "HID-Project.h"

int level = 0;

// the setup function runs once when you press reset or power the board
void setup() {
  Serial.begin(115200);
  Wire.begin();

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
  
  if(!apds.begin()){
    Serial.println("failed to initialize device! Please check your wiring.");
  }
  else Serial.println("Device initialized!");

  //gesture mode will be entered once proximity mode senses something close
  apds.enableProximity(true);
  apds.enableGesture(true);

  // Clear the buffer
  display.clearDisplay();

  display.setTextSize(1.5);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println("Volume"); 
  display.display(); 

  Consumer.begin();
}

// the loop function runs over and over again forever
void loop() {
   

  //read a gesture from the device
    uint8_t gesture = apds.readGesture();
    if(gesture == APDS9960_DOWN) {
      Serial.println("v");
      Consumer.write(MEDIA_VOLUME_DOWN);
      level--; 
      changeVolume();

    }
    if(gesture == APDS9960_UP) {
      Serial.println("^");
      Consumer.write(MEDIA_VOLUME_UP);
      level++;
      changeVolume();
    }
}

void changeVolume() {
  Serial.println(level);
  display.clearDisplay();

  display.setCursor(0, 0);
  display.println("Volume");  
  
  display.setCursor(0, 15);
  
  for (int i = 0; i <= level; i++){
    display.print("[]"); 
    display.display();  
  }
}

Credits

Nexus Electronics

Nexus Electronics

1 project • 0 followers
Founded by Zack Seifert, a seventeen-year-old maker and electronics enthusiast.

Comments

Add projectSign up / Login