Ambient2 Click Arduino tutorial

Teodor Costachioiu
Aug 21, 2017 · 3 min read

Ambient 2 click is a breakout board for the OPT3001 Ambient Light sensor from Texas Instruments, a single-chip lux meter that measures the intensity of light, as seen by the human eye. It has a strong IR rejection and a spectral response that matches the human vision.

This blog post is inspired from a project I had to complete last week, involving some measurements of the ambient light over an extended period. As the project was focused mainly on the changes in light intensity, I came with the idea of building an ambient light data logger. My approach was to use the Ambient2 click, one microSD card click and one (3.3V) Arduino Pro. Something like this:

The hardware was just a matter of minutes to complete. But the software proved to be a big, nasty issue. A major headache came from the OPT3001 sensor: none of the libraries I found on the Internet worked fine…

While testing my data logger, I had two other devices to compare against: one Mastech MS6610 light meter, and my Sekonic flash meter, which is also able to measure light intensity.

The Mastech is more than ten years old, so it’s probably a bit decalibrated. The newer Sekonic is build mainly to measure short pulses of light, and it’s not so precise on measuring ambient light in lux. Anyway, both instruments have provided measurements that are reasonably close to each other (somewhere in a 20% margin). That was expected, as each instrument has a different spectral sensitivity. The angle of incidence of the light was also different for each instrument. Moreover, the Sekonic has two settings for the incidence angle (I used the wide-angle setting).

And then came the surprise: with several code libraries for OPT3001 the measurements were way off. And when I say way off I mean at least one order of magnitude. Even the code example provided by MikroElektronika didn’t provide the expected results — there’s a mistake in the code that messes up the computation of lux values. Other code libraries had even bigger isues — like computing the lux values as uint16_t instead of casting to float.

So, I had to start from zero — and I wrote my own code. But this time I decided to do a little bit more, and I released the code as a library so that anyone can include it easily into their projects.

I can confirm that my library works fine on Arduino Pro (3.3V version) and the ChipKIT Uno32. It doesn’t with the Arduino Due or the Flip & Click, the reason being the flawed I2C library on SAM3X8E microcontrollers.

The download link is

Using the code library

After downloading and installing the library, one can run the following Arduino IDE code example:

The OPT3001 code is configured in autoscale mode, which is the simplest way to use this sensor.

Some configurations that can be done by commenting/ uncommenting the appropriate lines:

Measurement time can be either 800ms (default) or 100ms. However, running at 100ms will result in some loss of resolution — how much is lost is explained in the datasheet.

Measurement mode is set to continuous. Other options are a single measurement and shut down.

When a measurement is completed, the CRF flag in the CONFIG register of OPT3001 is set. My code example polls this flag, and when a measurement is completed it first checks if the Overflow bit is set.

If an overflow is detected, an error message is shown. If there’s no overflow, we read the result register, compute lux values and the result is shown in the serial terminal. Simple as that.

Originally published at on August 21, 2017. Moved to Medium on May 5, 2020.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store