Introduction
This guide will help you read light intensity data from your PiicoDev® Ambient Light Sensor and a Raspberry Pi Pico
To follow along, it's best to have:
- A Raspberry Pi Pico with pins soldered (pointing down)
- A PiicoDev Ambient Light Sensor VEML6030
- A PiicoDev Expansion Board for Raspberry Pi Pico
- A PiicoDev Cable
In the video we use a PiicoDev Platform to keep everything safe and secure.
If you prefer not to use the Expansion Board for Raspberry Pi Pico, there are other connection options in our PiicoDev Connection Guide.
Connect the PiicoDev sensor to your Pico
Plug your Pico into the Expansion Board, connect your light sensor to the Expansion Board via the PiicoDev cable, and finally connect your Pico to your computer with a USB lead.
If you're unfamiliar with connecting PiicoDev modules, read the PiicoDev Connection Guide before proceeding.
Download the PiicoDev Modules and Example Code
Download the following files and save them to your working directory (Right Click > "Save Link As")
- PiicoDev_Unified.py - The PiicoDev Unified Libraries: Drives I2C communications for PiicoDev modules
- PiicoDev_VEML6030.py - The device driver.
- main.py - an example script for the PiicoDev Atmospheric Sensor
It will be best to keep this file wherever you like to keep your coding projects eg. make a directory Documents > PiicoDev
Example Code
Open Thonny, connect to your Pico and upload the three files from the previous step.
Press Ctrl+D to restart your Pico and run the main script - light data should begin streaming up the shell
If you're unfamiliar with Thonny, read our setup guide.
Above: Light data streams up the shell. The plotter shows historic light data, which starts at about 175lux, then ramps down as the sensor is gradually covered. Finally, the sensor is uncovered and the light data jumps back to ambient levels.
Now we can easily read light data with our Pico.
Tip: Open the Plotter (View > Plotter) to see a nice plot of your temperature data
Remix - Day/Night message
In the final part of the video, we modify the example code to keep track of whether it is day or night (bright/dark). When light data transitions between bright and dark, we can print an appropriate greeting eg. "Good Morning" or "Goodnight". You can use this structure for decision-making in your own projects - be sure to code along!
If you have any questions or uncertainty, start the discussion below. We're full-time makers and here to help!
In the video we use a PiicoDev Platform to keep everything safe and secure.