Interfacing BH1750 Light Intensity Sensor and 1602 LCD Display with Arduino

Overview

In this tutorial, we will explore how to integrate the I2C LCD 16x2 display with the Light Intensity Module GY-30 with the BH1750 chip. This module measures light intensity in unit lux. We will show its measurements on the LCD, and turn ON/OFF corresponding LED lights depending on the 3 categories of light intensity we identified as "dim", "normal", and "too much".

Hardware Components

    • GY-30 Light sensitivity sensor

  • Robodyn Uno R3
  • 
    
  • I2C LCD Display 16x2
  • 
    
  • LEDs
  • 
    
  • 200 Ohm DIP Resistors
  • 
    
  • Breadboard
  • 
    
  • Jumper Wires
  • 
    

     

    Software Components

    Arduino IDE
    BH1750.h
    LiquidCrystal_I2C.h



    Application Description

    • GY-30 Light Sensitivity Sensor

    The GY-30 or BH1750 Light Intensity Sensor is a module which measures illuminance - or the luminous flux per unit area which is equal to one lumen per square meter (or simply lux). This is a measurement of the intensity of light that strikes or travels through a surface in photometry, as seen by the human eye.
    Depending on the mode of operation chosen, a digital light intensity sensor working between 1 and 65535 Lux (Lux) has a resolution of either 1 lx or 4 lx. It interacts using the I2C interface (TWI), which consists of two lines: SDA for data and SCL for clock. Both interior and outdoor light intensity can be measured with the module.

     

    • I2C LCD 1602 (16x2)

    This is a 2-row by 16 character display with an I2C daughter board interface making up the I2C 1602 LCD module. There are only two data connections needed which is the SDA and SCL, and two power supply connections +5 VDC, and GND.

     

    Hardware Setup

    Software Setup

    NOTE: We must 1st install the BH1750 and Liquidcrystal_I2C libraries mentioned above before we proceed with the coding.

    
    //Light Sensitivity Sensor Library
    #include <BH1750.h>
    //I2C Liquid Crystal Library
    #include <LiquidCrystal_I2C.h>
    //I2C Communication Library
    #include <Wire.h>

    //Required Declarations to use the libraries
    LiquidCrystal_I2C lcd(0x27, 16, 2);
    BH1750 lightMeter;

    //Pin Configurations
    const int redPin = 13;
    const int yellowPin = 12;
    const int greenPin = 11;

    void setup() {
    pinMode(redPin, OUTPUT);
    pinMode(yellowPin, OUTPUT);
    pinMode(greenPin, OUTPUT);

    //Initalizations for the libraries to start
    lcd.begin();
    Wire.begin();
    lightMeter.begin();
    }

    void loop() {
    //Code for reading the measurements by the Light Sensitivity Sensor
    float lux = lightMeter.readLightLevel();
    //Code for the LCD to display the measured values
    lcd.setCursor(0, 0);
    lcd.print("Light: ");
    lcd.print(lux);
    lcd.print(" lux ");
    lcd.setCursor(0, 1);
    lcd.print("Level: ");

    int high = 0;
    //Paramaters to label according to the measurements by the Light Sensor.
    if (lux <= 50) {
    lcd.print("Dim ");
    high = yellowPin;
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, LOW);
    }
    else if (lux >= 50 && lux <= 70) {
    lcd.print("Normal ");
    high = greenPin;
    digitalWrite(redPin, LOW);
    digitalWrite(yellowPin, LOW);
    }
    else if (lux >= 70) {
    lcd.print("Too Much");
    high = redPin;
    digitalWrite(yellowPin, LOW);
    digitalWrite(greenPin, LOW);
    }
    digitalWrite(high, HIGH);
    //A time for the LCD to update the measurements real-time (1 Second)
    delay(1000);
    }

    Code Breakdown:

    • This code tells the compiler to use the Light SensorLibrary, and the I2C LCD Library. Also initializes the I2C library.
      • #include <BH1750.h>
      • #include <LiquidCrystal_I2C.h>
      • #include <Wire.h>
    • Initialize the pins that the LEDs will use
      • const int redPin = 13;
      • const int yellowPin = 12;
      • const int greenPin = 11;
    • These are object instances lcd and lightMeter which will be used to call functions later from the I2C LCD and Light Sensor libraries
      • LiquidCrystal_I2C lcd(0x27, 16, 2);
      • BH1750 lightMeter;
    • Reads the values from the light sensor.
      • float lux = lightMeter.readLightLevel();
    • Tells the LCD display which row the text will appear.
      • lcd.setCursor(0, 0);
      • lcd.setCursor(0, 1);
      • This lines of code is a logical function to "decide" which text will be rendered in the LCD (e.g. be it "dim", "normal", or "too much") and which LED to turn ON or OFF, depending on the intensity of light detected. 
        • if (lux <= 50) {
          lcd.print("Dim ");
          high = yellowPin;
          digitalWrite(redPin, LOW);
          digitalWrite(greenPin, LOW);
          }
        • else if (lux >= 50 && lux <= 70) {
          lcd.print("Normal ");
          high = greenPin;
          digitalWrite(redPin, LOW);
          digitalWrite(yellowPin, LOW);
          }
        • else if (lux >= 70) {
          lcd.print("Too Much");
          high = redPin;
          digitalWrite(yellowPin, LOW);
          digitalWrite(greenPin, LOW);
          }

       

        Video Demo:

         

        Conclusion:

        We can conclude with this project that the GY-30 or BH1750 module is a very straightforward module used to measure illuminance. It can be used in various applications in security, automation, or specially in agriculture. We can use this module to detect if its already in daytime and signal sprinklers to water the plants based on the module`s readings. Imagination is the only limit. 

         

        References:

        https://robojax.com/learn/arduino/?vid=robojax-LCD1602-I2C
        https://robojax.com/learn/arduino/?vid=robojax_BH1750_light_lux_sensor

         

        160216x2 lcdArduino unoBasicColor ledDisplayI2c 1602 lcdI2c lcdLcd moduleLight sensitivity sensorLight sensorLiquid crystal displayModules

        Leave a comment

        All comments are moderated before being published