Projects / Gesture media control

Gesture media control

Beginner1 hGuided buildReviewed

Build it step by step

0 of 6 done
  1. ARDUINOAPDS9960

    Wire the sensor

    Connect power at 3.3 V and the I2C pins.

  2. ARDUINOAPDS9960

    Test gestures

    Print the gesture code on the Serial Monitor first.

  3. ARDUINO

    Match directions

    Rotate the board or swap the mappings so each swipe matches.

  4. ARDUINOAPDS9960

    Add USB keys

    Upload the media sketch and open a music player.

  5. ARDUINO

    Tune

    Swipe smoothly about 5 to 10 cm above the sensor.

  6. ARDUINO

    Mount

    Fix it in a small box under a clear window.

In short

How do you build a gesture media control?

Swipe your hand over an APDS-9960 sensor to change songs or volume on a computer. You need Arduino Leonardo, APDS-9960 gesture, colour and proximity sensor and Jumper wires male to male (40 pcs, 20 cm). It takes 6 steps and about 60 minutes.

Level
Beginner
Time
About 60 min
Parts
3

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
APDS-9960 VCC, GNDLeonardo 3V3 pin, GNDPower (see the note on logic levels)
APDS-9960 SDA, SCLLeonardo SDA, SCL pins (next to AREF)I2C
APDS-9960 INTLeave unconnectedInterrupt not needed
USB cableLeonardo USB portPower and keyboard connection

Code

Arduino IDE, board "Arduino Leonardo" (native USB). Install "Adafruit APDS9960" and "HID-Project". The APDS-9960 is a 3.3 V part: power it from the 3V3 pin, and use a breakout that is level-shifted or tolerates the Leonardo's 5 V I2C lines (the Adafruit board does; bare SparkFun-style boards need a level shifter). Gesture direction depends on how the sensor is mounted, so rotate the board or swap the mappings until up is up. Hold your hand 5 to 10 cm above the sensor and swipe smoothly.

Runs on a virtual Arduino Leonardo in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Wire.h>
#include <Adafruit_APDS9960.h>
#include <HID-Project.h>

Adafruit_APDS9960 apds;

void setup() {
  Serial.begin(9600);
  if (!apds.begin()) { Serial.println("APDS-9960 not found"); while (true); }
  apds.enableProximity(true);
  apds.enableGesture(true);
  Consumer.begin();
}

void loop() {
  uint8_t g = apds.readGesture();
  if (g == APDS9960_RIGHT) Consumer.write(MEDIA_NEXT);              // swipe right: next track
  else if (g == APDS9960_LEFT) Consumer.write(MEDIA_PREVIOUS);      // swipe left: previous track
  else if (g == APDS9960_UP) Consumer.write(MEDIA_VOLUME_UP);       // swipe up: volume up
  else if (g == APDS9960_DOWN) Consumer.write(MEDIA_VOLUME_DOWN);   // swipe down: volume down
  delay(20);
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Swipe rightNext track
Swipe leftPrevious track
Swipe upVolume up
Swipe downVolume down

If it does not work

APDS-9960 not found

Check the 3V3 supply, SDA and SCL pins.

Gestures wrong way

Rotate the sensor or swap the mappings.

Gestures missed

Swipe more slowly and closer, and avoid direct sunlight.

No keys sent

The Leonardo must appear as a USB device; check the cable.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the gesture media control?

Arduino Leonardo, APDS-9960 gesture, colour and proximity sensor and Jumper wires male to male (40 pcs, 20 cm).

How long does the gesture media control take to build?

About 60 minutes for a beginner maker, in 6 steps.

How do I know the gesture media control works?

Swipe right: Next track. Swipe left: Previous track. Swipe up: Volume up.

APDS-9960 not found: what should I check?

Check the 3V3 supply, SDA and SCL pins.

Gestures wrong way: what should I check?

Rotate the sensor or swap the mappings.

Gestures missed: what should I check?

Swipe more slowly and closer, and avoid direct sunlight.

No keys sent: what should I check?

The Leonardo must appear as a USB device; check the cable.