Let's Workshop: GY-30 Light Intensity Sensor Module


Here is a quick introduction to using the GY-30 light intensity sensor module. This will provide you with an entry point to using the module to accurately monitor light levels.

This example will demonstrate the use of an Arduino UNO in selecting the module from the i2c bus and reading the sensor output. Once stored, it will check and pass them to the serial monitor. This will use the BH1750 sensor library created by Claws to interface with the chipset.

Components

Wiring

Wire the two boards together as can be seen in the image below, taking care to match the pin numbers.

Coding

The code consists of includes, initialisations, a simple setup and loop. First the Wire.h standard library and BH1750 sensor library are linked to the code. These are then used to initialise a sensor object and event object that will interact with the module. Next the setup launches the serial monitor, which provides a simple method to debug our output. In the loop we first poll the sensor for fresh data. With the data in hand we can perform further functions on it. In this case simply displaying it on the serial monitor.

Load the code below into the Arduino IDE and upload it to your board.

/*
  A simple program designed to setup and demonstrate the GY-30 (BH1750) sensor library and 
  the module - BDAA100002
 
  The program uses Claws BH1750 library to interact and monitor the output from the module
  through an I2C communication channel. On reading from the module it to outputs the result to 
  the serial monitor.
  
  modified 12th July 2019
  by Sebastian Karam - Flux Workshop
  
  The Adafruit Unified Sensor Driver library created by Claws
  https://github.com/claws/BH1750
*/ 

#include  // include the standard Wire library
#include  // include the BH1750 library

BH1750 GY30; // instantiate a sensor event object

void setup(){
  Serial.begin(9600); // launch the serial monitor
  Wire.begin(); // Initialize the I2C bus for use by the BH1750 library  
  GY30.begin(); // Initialize the sensor object
  Serial.println("Flux Workshop Example");
}
void loop() {
  float lux = GY30.readLightLevel(); // read the light level from the sensor and store it in a variable
  Serial.println((String)"Light: " + lux + " lx"); // print the data to the serial monitor
  delay(1000); // Pause for a second before repeating the sensor poll
}

Running

With the board loaded with the program and all the connections made the serial monitor will begin to show the data output by the module. In the example, I start with the module covered with my hand, then remove it. Following that I turn the sensor to the window and back, before covering it once again.

What to try next?

  • Use the values to track sunrise and sunset.
  • Detect the opening times of a cupboard or box, where ambient light is constant until disturbed.
  • Investigate other library modes, to allow for a lower power operation rather than constant polling.
Previous article Let's Workshop: 3 Line Sensor Module
Next article Let's Workshop: UVM-30A Ultraviolet Sensor Module

Leave a comment

* Required fields