Zio Light Sensor Qwiic Start Guide
This post is part of our Zio Qwiic Start Guide Blog Series.
Table of Contents
- Zio Light Sensor Overview
- Configuring your Zio Light Sensor
- Installing Libraries
- Connection Setup
- Testing Example Codes
- Code Explanation
You will find light sensors ubiquitously used in mobile phones and tablets. Like a thermometer senses temperature, light sensors “sense” light. It is measured as a unit in Lux.
What uses are for light sensors? There are many uses of a light sensor. You can use it to control brightness, measure illuminance to detect placement, use as security to detect intrusion in a room or containers, planning placement for objects that needed more or less sunlight or light, and in Agriculture for example, it could be used to manage a sprinkler system automatically, only watering when the sun is not at its brightest.
This guide will show you a simple overview of what Zio Light Sensor can do with example code to test and demo.
- Power and Logic Pins
- INT - Interrupt Pin (In)
- GND - Ground Pin (Supply)
- 3V3 - 3.3V Supply Pin
- SDA - Signal Data Pin (In/Out)
- SCL - Signal Clock Pin (Out)
- Qwiic Connectors
- TSL2561 Light to Digital Converter
- Selectable Addresses:
- 0x39 (Default)
- Selectable Addresses:
This qwiic guide has a separate post on our development board guides. Check them out below:
You need to install the following libraries to your Arduino IDE before you can start programming your Zuino board with Zio Qwiic RGB Color Sensor.
Download the following libraries and save it on your local Arduino IDE libraries folder:
To install the libraries open your Arduino IDE, go to Sketch tab, select Include Library -> Add .Zip Library. Select the above libraries to be included on your IDE.
Connection with Zuino M Uno
Connection with Zuino XS PsyFi32
We are going to demo our Light sensor using the following example codes. The following examples work with our Zio development boards. Just select the right board and port from the Arduino IDE platform.
Open your Arduino
Go to File > Examples > TSL2561 Arduino Library > tsl2561
Open Serial editor to view the results
The light sensor will measure the values of Infrared light, Full Light, Visible light and Illumination (Lux).
The library is fairly simple to use. The first line of code in the example is the 'constructor' where you can supply the I2C ADDR (in case you want to change it), and a unique ID to attach to this sensor (you can just leave this to the default value for now). By modifying the I2C address we can have up to three TSL2561 sensors connected on the same board:
Next, in the code, you will want to configure the sensor with the gain and integration time.
You can have either a gain of 0 (no extra gain, good in low light situations) or a gain of 16 which will boost the light considerably in dim situations.
You can also change the integration time, which is how long it will collect light data for. The longer the integration time, the more precision the sensor has when collecting light samples.
For simplicity purposes, we have opt to set the Integration time for the sensor at the shortest time following a bright light sample. We also set the gain to be for dim situations by uncommenting the
You will get to manually read the individual photo diodes, by calling the
getLuminosity function. This function will return a reading in SI lux units, which is probably the easiest unit to understand when working with light, to read the infrared, full spectrum diode or 'visible' light channels:
That's it! The example should be easy to understand and work into your own projects from here!
Got questions or suggestions? Or just want to greet us? Drop us a comment below!