Arduino Projects

BH1750 Light Sensor with Arduino and Oled display and Nokia 5110 LCD

BH1750 light sensor with Arduino:

Light Intensity Sensor BH1750 is the sensor that is commonly used in mobile phones to control the screen brightness according to the environment lighting. BH1750 sensor can accurately measure the LUX value. 

In this article, we will discuss how to build a sensitive and accurate light meter. We are going to use the BH1750 sensor with outputs illuminance in the Lux SI unit. We will get the data of the luminance when the light will fall on the sensor. When we place a finger on the sensor the luminance will decrease and when we remove the finger from the sensor the luminance will increase. By reading this article you will be able to interface the BH1750 sensor with the Arduino and OLED display.


Amazon Links:

BH1570 Light Sensor

Arduino Uno

SH1106 Oled display

Nokia 5110 LCD display

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!



BH1750 Light Sensor:

BH1750 Light Sensor

BH1750 Features:

  • Power Supply: 2.4V-3.6V (typically 3.0V)
  • 0.12mA is equal to the Less current consumption
  • The measuring range of the light sensor is 1-65535lx
  • I2C is bus Communication
  • Accuracy in this sensor +/-20%
  • It has a built-in A/D converter. This converter is for converting analog illuminance in the digital data.
  • A very small effect of IR radiation
  • IR radiations put very less effect on the sensor’s result.
  • It is highly responsive.


Pin Connection: 

  • VCC pin can be connected with 2.4V to 3.6Vots. Normally it’s connected with 3.3v pin of the Arduino or other 3.3 volts compatible controller boards like ESP32 and ESP8266.
  • GND is connected with controller board ground pin.
  • SCL stands for the Serial Clock Line which is used to provide a clock pulse for I2C communication.
  • SDA stands for Serial Data Address, which is used to transfer the data through I2C communication.
  • ADDR is the Device address pin and it is used to select the address when more than two modules are connected.

Applications of LUX Sensor:

  • BH1750 adjusts brightness in mobile phones.
  • Cars headlights turn ON/OFF control based on surrounding lighting conditions.
  • It controls the brightness of Display screens.

Now we will discuss how to connect the Arduino with the light sensor BH1750. For this project we will require:

  • Arduino board
  • BH1750 Light Sensor


Interfacing BH1750 Light Sensor with Arduino:

BH1750 Light Sensor

  • Connect the SDA pin of the BH1750 with the Arduino analog pin A4
  • Connect the SCL pin of the BH1750 with the Arduino analog pin A5
  • Connect the VCC of the bBH1750 with the 5V
  • Connect the ground pin of the sensor with the ground of the Arduino
  • Connect the ADDR pin of the BH1750 with the ground of the Arduino

Now for programming first of all we will install BH1750 library. First we will click on the sketch Menu then click on the include library and select the manage library.

BH1750 Light Sensor

Then we will write BH1750 in the search box, you will see multiple results, but select the one as shown in the picture below.

BH1750 Light Sensor

After installing the library we will upload the following code:

BH1750 Light Sensor Arduino Code:

#include <Wire.h>
#include <BH1750.h>

BH1750 lightMeter;

void setup(){
  Wire.begin();
  Serial.begin(9600);
  lightMeter.begin();
  Serial.println("Sensing started!...");
  delay(500);
  
}

void loop() {
  uint16_t intensity= lightMeter.readLightLevel();
  Serial.print("Light intesnsity: ");  
  Serial.print(intensity);
  Serial.println(" lx");
  delay(500);
}

BH1750 Light Sensor with Oled display and Arduino:

Now if we want to show the sensor data on the OLED display we will perform the following steps:

  • Connect the SDA of both the OLED display and BH1750 Light Sensor with the analog pin A4 of the Arduino.
  • Connect the SCL pin of both the OLED and BH1750 Light Sensor with the analog pin A5 of the Arduino.
  • Connect the VCC of both OLED and BH1750 with the 5V of the Arduino.
  • Connect the ground of both OLED and BH1750 with the ground of the Arduino

BH1750 Light Sensor



BH1750 Light Sensor with Oled display and Arduino Code:

#include "U8glib.h"
#include <Wire.h>
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE);
int BH17_add = 0x23;
byte buff[2];
 
void setup() {
  Wire.begin();
  BH750_Init(BH17_add);
  delay(200);
}
 
void light(){
  float valf=0;
  u8g.setFont(u8g_font_unifont);
  u8g.setPrintPos(0, 50); 
if (BH1750_Read(BH17_add)==2){
  valf=((buff[0]<<8)|buff[1])/1.2;
  if (valf<0)u8g.print("> 65535");
else
  u8g.setPrintPos(0, 20);
  u8g.print("BH11750 sensor with the OLED");
  u8g.setPrintPos(0, 30);
  u8g.print("--------------");
  u8g.setPrintPos(0, 40);
  u8g.print("Flux Meter");
  u8g.setPrintPos(0, 60);
  u8g.print((int)valf,DEC);
  u8g.print(" LX/SI");
}
  delay(100);
}
 
void loop() {
 u8g.firstPage();
  do {
    light();
  }while (u8g.nextPage());
  
}
 
void BH750_Init(int address){
 Wire.beginTransmission(address);
 Wire.write(0x10);
 Wire.endTransmission();
}
 
byte BH1750_Read(int address){
byte i=0;
Wire.beginTransmission(address);
Wire.requestFrom(address, 2);
while(Wire.available()){
  buff[i] = Wire.read();
  i++;
}
Wire.endTransmission();
return i;
}

After uploading the code to the Arduino we will be able to see the output of the BH1750 sensor on the OLED display. The intensity of the sensor can be changed by placing the finger on the sensor.


BH1750 sensor interfacing with the Nokia 5110 LCD:

As we have already discussed, how to connect the BH1750 sensor with the Arduino. Now we will connect this sensor with the Nokia 5110 LCD. In order to build this light meter, we are going to need: Arduino UNO, BH1750 sensor, and Nokia 5110 LCD display. Now will connect the BH1750 sensor and Nokia 5110 LCD with the Arduino.

  • Connect the VCC of the BH1750 with the 5V of the Arduino
  • Connect the GND of the BH1750 with the ground of the Arduino
  • Connect the SCL of the BH1750 to the analog pin A5 of the Arduino
  • Connect the SDA of the BH1750 to the analog pin A4 of the Arduino
  • Now we will connect the VCC of the Nokia 5110 with 3.3v
  • Connect the ground of the LCD with the ground of the Arduino
  • Connect the led out pin to the ground if we want LCD backlight and if we not want LCD backlight hen we should connect this pin with the 5V
  • Connect the SCE pin of the display with the digital pin 11 of the Arduino
  • Connect the RST pin of the display with the digital pin 12 of the Arduino
  • Connect the D/C pin of the display with the digital pin 10 of the Arduino
  • Connect the DN pin of the display with the digital pin 9 of the Arduino
  • Connect the SCLK pin of the display with the digital pin 8 of the Arduino

BH1750 Light Sensor

After connecting the LCD and BH1750 sensor with the Arduino we will upload the code.


BH1750 Sensor and Nokia 5110 LCD Arduino Code:

#include <LCD5110_Graph.h>
#include <Wire.h>
#include <BH1750.h>

LCD5110 lcd(8,9,10,12,11);
extern unsigned char BigNumbers[];
extern uint8_t splash[];
extern uint8_t ui[];

BH1750 lightSensor;
String light;

void setup() {
 
 lightSensor.begin();
 lcd.InitLCD();
 lcd.setFont(BigNumbers);
 lcd.clrScr();
 lcd.drawBitmap(0, 0, splash, 84, 48);
 lcd.update();  
 delay(3000);
 
}

void loop() {
  
 int stringLength=0;
 
 uint16_t lux = lightSensor.readLightLevel();
 
 light = String(lux);
 stringLength = light.length();
 
 lcd.clrScr();
 lcd.drawBitmap(0, 0, ui, 84, 48);
 printLight(stringLength);
 lcd.update();
 
 delay(150);
}

void printLight(int length)
{
  switch(length)
  {
    case 1:  lcd.print(light,68,22); break;
    case 2:  lcd.print(light,54,22); break;
    case 3:  lcd.print(light,40,22); break;
    case 4:  lcd.print(light,26,22); break;
    case 5:  lcd.print(light,12,22); break;
    default:  lcd.print(light,0,22); break;
  }
}

After uploading the code to the Arduino we will be able to see the output of the sensor on the Nokia display.

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

One Comment

  1. The article on “BH1750 Light Sensor with Arduino and OLED Display and Nokia 5110 LCD” offers a practical and informative guide on utilizing the BH1750 light sensor with Arduino and various display options. The step-by-step instructions and code examples make it easy to follow and implement for readers interested in working with light sensors and displays. The combination of clear explanations and visuals enhances the overall understanding of the process, making it a helpful resource for beginners and enthusiasts in the field of electronics and programming.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button