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 mindsensors.com 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.