The sensor APDS-9960, a little gem of engineering, is an amazing component that allows for gesture and proximity detection, as well as measuring ambient light and color. Used in cutting-edge electronic devices such as the Samsung Galaxy S5, it is now within reach of any electronics enthusiast working with platforms such as Arduino. With its ability to detect gestures in a range of 5 to 20 cm and its easy integration with other devices, it is the ideal choice for those looking to incorporate gesture control into their projects.
In this article we will explore in depth how this sensor works and how to connect it to an Arduino, paying attention to the multiple uses it can have and offering code examples that will allow you to start working with it quickly.
What is the APDS-9960 sensor?
El APDS-9960 It is a sensor that combines four main functionalities: gesture detection, proximity, color and ambient light. It is a device that communicates its readings using the I2C communication protocol, which greatly facilitates its use with microcontrollers such as Arduino. Among its virtues, it stands out for its ability to measure color and ambient light and detect gestures without contact, recognizing movements such as left, right, up, down, near and far.
This sensor works thanks to the integration of a infrared emitter and four directional photodiodes, which allows you to detect and calculate the direction of movement of nearby objects. In addition, it has the ability to measure the amount of ambient light and detect RGB color.
Connecting APDS-9960 sensor with Arduino

To connect the APDS-9960 With Arduino, you simply need to establish communication via the bus I2C. This sensor works at a voltage of 3.3V, so it is crucial to make the appropriate connections to avoid damaging it, especially if you work with a 5V Arduino. In this case, it is advisable to use a logic level adapter to lower the I2C bus voltage.
- GND to the Arduino GND pin.
- Vcc to the 3.3V pin of Arduino.
- SDA to the Arduino SDA pin.
- SCL to the Arduino SCL pin.
If your Arduino model is 5V, then obviously you have to take extra precautions, although in some cases it has been reported that the sensor could operate without being damaged. However, this is not a completely safe long-term solution.
Libraries and code for Arduino
To use the APDS-9960 with Arduino, one of the easiest ways is to use the library developed by Adafruit, which simplifies its use. You can download it from GitHub and install it directly into the Arduino development environment.
Basic example: Display gestures via serial port
In this first example, the detected gestures will be read and displayed over the serial port. Simply move your hand over the sensor at a distance between 5 and 20 cm for the gestures to be detected:
#include "Adafruit_APDS9960.h"
Adafruit_APDS9960 apds;
void setup() {
Serial.begin(115200);
if (!apds.begin()) {
Serial.println("Error al inicializar el sensor, comprueba el cableado");
while (1);
}
apds.enableGesture(true);
}
void loop() {
uint8_t gesture = apds.readGesture();
if (gesture == APDS9960_DOWN) Serial.println("Abajo");
if (gesture == APDS9960_UP) Serial.println("Arriba");
if (gesture == APDS9960_LEFT) Serial.println("Izquierda");
if (gesture == APDS9960_RIGHT) Serial.println("Derecha");
}
This code is just a sample of what you can do with a gesture sensor like the APDS-9960. When you move your hand over the device, the program will detect the gesture and display the result on the serial port console.
Advanced example: Flash LED based on gesture
For this second example, we will combine the detected gestures with the LED integrated into the plate. Depending on the gesture detected, we will flash the LED a specific number of times:
#include "Adafruit_APDS9960.h"
Adafruit_APDS9960 apds;
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
if (!apds.begin()) {
Serial.println("Error al inicializar el sensor");
while (1);
}
apds.enableGesture(true);
}
void loop() {
uint8_t gesture = apds.readGesture();
if (gesture == APDS9960_DOWN) blink(1);
if (gesture == APDS9960_UP) blink(2);
if (gesture == APDS9960_LEFT) blink(3);
if (gesture == APDS9960_RIGHT) blink(4);
}
void blink(int times) {
for (int i = 0; i < times; i++) {
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
}
}
Common problems and solutions
Although the APDS-9960 It is a fairly robust sensor, but it is true that in environments with a lot of light or interference, the readings may fail. Also, if used in non-ideal conditions, it may fail to detect movements or even generate false positives.
Another thing to keep in mind is that this sensor is quite dependent on proper ambient lighting and, while it is very sensitive, it may not work well with objects in conditions such as shiny surfaces or with gloves, since these may not correctly reflect the emitted infrared light.
The I2C protocol used by this device is fairly simple, but it is still critical to ensure that the connections are correct and that there are no voltage issues.
The APDS-9960 sensor is an excellent tool for projects looking to integrate gesture and proximity detection. It is inexpensive, easy to integrate via I2C, and features libraries that simplify its use. While it may present issues in some environments, its adjustable sensitivity and ability to operate behind glass make it a versatile choice. With the code examples provided, you can start working with this sensor and discover its full potential in your projects.