☀️ Home-made light meter (luxmeter) on the BH1750, ARDUINO and Nokia 5110

☀️ Home-made light meter (luxmeter) on the BH1750, ARDUINO and Nokia 5110

Daniil Zhuk
Today we will continue creating cool devices based on the Nokia 5110 LCD display. This time we will assemble a luxmeter (the light meter) using a high-sensitive BH1750 lux meter.


Illumination (measured in lux) - luminous flux incident on the surface of a unit area. It shows the amount of light perceived by man. This value is reduced - unlike energy values, such values ​​are adjusted according to the different sensitivity of the human eye to radiation with different wavelengths. (See - spectral light efficiency of monochromatic radiation.)

Illumination can be measured at any point in space, at any distance from the light source. And this value characterizes the luminous flux from the point of view of perception by the human eye. Thus, the light meter can determine how well this or that space is lit. And it is this device that we will create in the course of this guide.

In the figure to the right is the already assembled device, which measures the illumination outside on a bright morning.

FOR THE PROJECT WE WILL NEED THE FOLLOWING COMPONENTS:

  • Arduino Uno Board
  • Light Sensor BH1750
  • Nokia 5110 LCD Display
  • Breadboard
  • Wires

The BH1750 is a digital light sensor with excellent accuracy and measurement range. It connects to the microcontroller or processor via the I²C bus.

This module is most useful for obtaining data on ambient light and is widely used to adjust LCD displays and keyboard backlighting for mobile devices.

Some characteristics of the sensor BH1750:

  • I²C bus (Fast and Standard speeds supported)
  • Spectral sensitivity roughly corresponds to the sensitivity of the human eye.
  • Illumination converter to digital data. Wide range and high resolution (1–65535 lux)
  • Low current due to off function
  • Suppression of noise of lighting 50 and 60 Hz
  • Ability to choose from 2 types of the slave address
  • Measurements with and without the influence of the optical window (using this function it is possible to measure a minimum of 0.11 lux, a maximum of 100 000 lux)
  • Small measurement fluctuations (± 20%).

SCHEME
Connect the elements as shown in the diagram below created using the Fritzing program.

 

 The BH1750 sensor has a built-in 16-bit ADC that can directly transmit a digital signal using the I²C protocol, so the sensor is connected to the I²C interface of the Arduino (analog 4 (SDA) and 5 (SCL)).

The connection table is shown below:

BH1750  Arduino Uno
VCC 5V
GND GND
SCL A5
SDA A4

 Just in case, the connection table of the outputs of the display and the board (according to the diagram) used in this particular project is shown below: 

LCD Nokia 5110 Arduino Uno
Pin 1(RST) D12
Pin 2(CE) D11
Pin 3(DC) D10
Pin 4(DIN) D9
Pin 5(CLK) D8
Pin 6(VCC) VCC
Pin 7(LIGHT) GND
Pin 8(GND) GND

Recheck the connection of all elements before proceeding with the code.

CODE
As in many of our projects, in order to simplify work with the BH1750 light sensor, we will need a library for it. In this project, we will use the library BH1750.h, which can be found here. Download the library and install it in the Arduino IDE development environment, unpacking and copying it into the folder of the environment in which the libraries are located.

For the display of the Nokia 5110, we need the LCD5110_Graph.h library, which can be downloaded from here. It also needs to be installed in the development environment. Further information on the Nokia 5110 display can be found in the guide mentioned above.

After installing the libraries, you can launch the Arduino IDE and get to work.

The first thing we do in our code is to include the libraries that we are going to use: for the BH1750 sensor and the Nokia 5110 display, as well as the library for the I²C interface.

//Written by Nick Koumaris
//info@educ8s.tv
//educ8s.tv
 
#include "LCD5110_Graph.h"
#include "Wire.h"
#include "BH1750.h"

Next, we determine the conclusions to which the display is connected, and also indicate the font and file names with images.

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

Next, create a BH1750 sensor object and declare a line that will contain all the information received from the sensor.

BH1750 lightSensor;
String light;
Now you can go to the setup () function. It seems to me that the assignment of commands in this function is easy to understand. Communication on the I²C bus starts, then the LCD display is initialized, the font is adjusted and the start image is displayed on the screen.

void setup() {

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

}

The system waits for a couple of seconds (so that the start image is displayed for a while) and goes to the loop () function.

Now consider the loop () function. The loop () function is pretty simple. The first command initializes the string, setting its length to 0. The next command reads the readings from the light sensor. Then the display is cleared. The display shows the image of the user interface, and then, after the conversion, the sensor data is displayed.

The delay is needed to pause between reading the sensor.

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);
}

The last part of the code is a function that serves to display data from a string.

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;
}
}

The full code is listed below and is also available in the file.

#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;
}
}

If you have made all the necessary preparations in advance (installation of libraries, for example), you can freely copy this code into the Arduino IDE and flash the Arduino into your board.

DEMONSTRATION

Copy the code into the Arduino IDE development environment and load it into the Arduino board. The image should appear on the display, as in the figure below. Do not forget to copy the image files to the folder with the Arduino IDE example.

Add a comment

* Comments must be approved before being displayed.