ISL29125 RGB Light Sensor Hookup Guide

Pages
Contributors: JordanDee
Favorited Favorite 3

Reading RGB Values

Hardware Hookup

Before we dive into the code, we need to connect the Arduino Uno to the ISL29125 breakout board. Connect the 3.3V and GND on the Arduino to the 3.3V pin on the breakout board. Connect SDA on the breakout to A4 on the Uno, SCL to A5 on the Uno. If you're using the Uno or any 5V Arduino, you'll need a logic level converter between SDA/SCL on the breakout and A4/A5 on the Uno. If you don't know how to use the converter, this logic level conversion tutorial explains how.

Now that the hardware is ready, let's move onto the software.

Install the Library

Now that the hardware is set up, you'll need to install the Arduino Library for the ISL29125. Click here to download the library. Or you can grab the most up-to-date version of the code on GitHub.

To install the library unzip and place the library folder in the "libraries" folder in your Arduino sketchbook. For more help installing the library, refer to the Arduino Library Installation Guide.

Basic Example Sketch

In the Arduino IDE, go to File > Examples > SparkFun_ISL29125_Arduino_Library > ISL29125Basics. This will load a simple example that will get you quickly reading light intensity levels in the red, green, and blue spectra. Let's dive into the example sketch.

Setup

To setup the example we simply declare a sensor object and run a basic initialization function that will communicate with the sensor. The init() fuction will command the ISL29125 to start taking readings for red, green, and blue. In addition to calling RGB_sensor.init(), the setup() function also initiates serial communication so we can send information from the sensor to our Serial Monitor (make sure to set your Serial Monitor to 115200 baud).

language:cpp
// Declare sensor object
SFE_ISL29125 RGB_sensor;

void setup()
{
  // Initialize serial communication
  Serial.begin(115200);

  // Initialize the ISL29125 with simple configuration so it starts sampling
  if (RGB_sensor.init())
  {
    Serial.println("Sensor Initialization Successful\n\r");
  }
}

Reading Sensor Values

Now how do we actually acquire those sensor readings? Well that's up next. The sensor readings are stored as 16-bit unsigned integers. Using the library we can call our sensor objects functions readRed(), readGreen(), and readBlue() to get the light intensity readings for red, green, and blue respectively. Each time through loop(), we take these readings, print them to the Serial Monitor, then wait a couple seconds. Here's the code for this functionality:

language:cpp
// Read sensor values for each color and print them to serial monitor
void loop()
{
  // Read sensor values (16 bit integers)
  unsigned int red = RGB_sensor.readRed();
  unsigned int green = RGB_sensor.readGreen();
  unsigned int blue = RGB_sensor.readBlue();

  // Print out readings, change HEX to DEC if you prefer decimal output
  Serial.print("Red: "); Serial.println(red,HEX);
  Serial.print("Green: "); Serial.println(green,HEX);
  Serial.print("Blue: "); Serial.println(blue,HEX);
  Serial.println();
  delay(2000);
}

If you simply want sensor readings to log, view, or use in a further calculation for your project, this is all you really need to know. However, if you'd like to know more about the gritty details of sensor configuration -- or how to trigger a processor interrupt based on a specific sensor reading -- continue to the advanced section.