Blog Post

Sunlight Sensor with the Grove Sensor Adapter


The Grove sunlight sensor is quite versatile, detecting visible, infrared, and ultraviolet light. Specifically, this example project uses the Grove Sunlight Sensor V1.0 and the Grove Sensor Adapter. As this sensor can do quite a bit more than a basic digital or analog sensor, this will be an example of using the I2C modes from the provided Mindsensors GroveSensorAdapter block.

First let's take a look at some readings from the (attached) example program. As a control, inside we see some pretty standard values with fluorescent lighting. The values are, from top to bottom, visible light, infrared light, and ultraviolet light.

Taking the project outside shows the values you get drastically increase, most notably the detected UV radiation.

Let's take a brief look at the program. This project uses a Grove Sensor Adapter connected to sensor port 1 on the EV3, and the Sunlight Sensor connected on the other end. In our previous few blog posts you've seen examples of using the analog and digital modes of the Mindsensors GroveSensorAdapter block. They make reading single values very convenient, but this sensor uses I2C to provide more functionality.

First we need to check if the sensor is available, and if not wait until it is. The first block enables auto-polling so the Grove Sensor Adapter will continually read from the sensor. The register we chose here will be set to 0x45 (69 in decimal) when it is ready. In a loop we read the value, print it to the screen, and check if it is equal to that value we are looking for.

With the sensor detected and ready we show "Found" on the screen, and drop in the ResetSunlightSensor and DeInitSunlightSensor My Blocks. They will take a second or two to run, but they make all the calls to set up the sensor when the program starts. Then we can start reading values! We enable auto-polling again but on a different register. Previously we were reading the state of the sensor, now we want to poll the light values instead.

Now we have a loop that reads each value and shows it on the screen. We read a value, attach the label, and display it. The UV section has an extra Math block to divide it by 100.


Perhaps try incorporating this with the Plant Moisture Monitor project?

Additional references are available on the wiki page for this sensor.

Downloads and Links

  • EV3 Block
    EV3 Block
  • EV3 Program
    EV3 Program
  • Grove Sensor Adapter product page
    Product Page
  • Grove Sensor Kit product page
    Grove Sensor Kit

Comments (2)

Allen M 05.05.2017
Seth, Thanks for a great I2C example. I was thinking about getting some of the other sensors, but some of them are serial - not I2C. I looked at this one and read the Adapter user guide, but I hadn't bought one yet to give it a try. I guess I will have to buy one now. That makes another 5 or 6 more Grove sensors to get now - which also means more mounting kits. You just have way too many great products to buy - LEGO sensors, EV3 Arduino Shield, PiStorms, etc. I'm going to go broke.
Seth T 05.05.2017
I'm glad you're excited to try out all these sensors! Robotics is so much fun :) I've been having a great time with the PiStorms lately, but I might be a bit biased with how much I work on it. We have a full list of supported sensors linked on the product page, or you can just click here:
Please Login to add your comments

Featured Posts

The mindsensors Grove Sensor Adapter makes it easy to use a variety of unique Grove sensors with the...

Read more

The mindsensors Grove Sensor Adapter makes it easy to use a variety of unique Grove sensors with the...

Read more


  • What do you use to program your FRC Robot?