Use an APDS-9930 Ambient Light and Proximity Sensor with Arduino/AVR

A few months ago I was looking for a sensor that was able to detect light color. I stumbled into this page and thought well, that seems good to me, so I bought it. When I got it, I was going to throw it away. It just wouldn’t work. I hooked it up to my Arduino Uno with a level shifter, and it didn’t work. I hooked it up to an ATmega8 microcontroller on a breadboard, powered it with my USB serial adaptor using the 3.3V output, and it would still tell me that white light was red, and so was blue light. I checked better and found out I didn’t have an APDS-9960, but an APDS-9930.

I decided to keep it, and write a new library for it 😉

APDS-9930 Arduino Library at GitHub

I didn’t actually write it from scratch: it’s based off the library for the APDS-9960 written by SparkFun. In fact, the usage is very similar. Few things have changed, other than removing the unneeded code (for color detection and gestures) and adding some device specific code (this specific device has two photodiodes: one that detects the visible spectrum + the infrared, called channel 0, and one that detects only infrared, channel 1). I added a method that uses the channel 1 value to filter infrared noise from the channel 0 value and turn it to Lux, but I don’t guarantee it returns the correct value.

Interrupts use channel 0 anyways, so use that value if not sure 🙂

My examples are self-explanatory, so make sure you check them if you don’t know where to start.

I took a picture to help you hook it up to an Arduino Uno, in case you were having issues. You already knew you needed a logic level shifter (like the one I’m using), right? Well, if you didn’t, go buy one now before you burn your sensor! It can only work between 2.5V and 3.8V, and most Arduino boards (except for the Arduino Pro Mini) work at 5V. The bidirectional logic level shifter translates inputs from both sides to the opposite voltage, so that Arduino’s 5V are seen as 3V from the sensor, and the sensor’s 3V are seen as 5V from the Arduino.

Here’s the picture:

APDS-9930 to Arduino Uno hook up
APDS-9930 to Arduino Uno hook up

The picture isn’t really clear. Basically the interrupt (INT) pin from the sensor goes to an interrupt pin on the board through the shifter (digital pins 2 and 3 correspond to interrupts 0 and 1 on Arduino Uno, read more here) and can be safely left disconnected if not needed. SCL and SDA are the I2C data bus pins, and are always needed. SDA goes to analog pin 4 and SCL goes to analog pin 5. Some level shifters (like the one I use) are hard-wired to shift from 3V to 5V, while the one from SparkFun can translate between any two voltages. If you have this model, connect 5V to VCCB and 3V3 to VCCA; the rest does not change.

Let me know if you have any issues! Either comment below or use the contact form!

P.S.: If you’re also looking for an APDS-9960 with RGB and gesture detection support, you can buy one from eBay.

There is a mobile optimized version of this page, view mobile Version.

6 Replies to “Use an APDS-9930 Ambient Light and Proximity Sensor with Arduino/AVR”

  1. Thank you for your library. I have tried your library. The val has shown in com port, but it don’t change by any thing approaching the sensor. Any idea for me trying sensor? (I use Arduino Nano)

    1. Please use the contact form for following replies, as I don’t get a notification for comments on the blog.
      Try one of the examples included; make sure DUMP_REGS is defined. In the serial console you should receive a list of numbers. Email me all that stuff, so I can see whether it’s a hardware, software or connection problem.

Leave a Reply