Measure Light with arduino and BH1750 module

In this post I will expose how to measure luminosity with arduino and a BH1750 module

 

Needed Hardware.

ArduinoUno_r2_front450px

Arduino Uno

Price: less than $30 (Amazon)

51QAdBqHdcLBH1750 Module

Price: less than $10 (Amazon)

Arduino to Module connection

modulo-i2c-bh1750-sensor-de-luz-ideal-arduino-pic-etc-625-MEC3740317867_012013-O

The module can also be powered by 3.3V.

ADD should be connected to ground to select this device. ADD is the equivalent to not(CS)

Code

I found out an good library to play with this device: https://github.com/claws/BH1750. Download and add this library to your arduino library folder and then you can run the code:

 

/*
 
Example of BH1750 library usage.
 
This example initalises the BH1750 object using the default
high resolution mode and then makes a light level reading every second.
 
Connection:
 VCC-5v
 GND-GND
 SCL-SCL(analog pin 5)
 SDA-SDA(analog pin 4)
 ADD-NC or GND
 
*/
 
#include <Wire.h>
#include <BH1750.h>
 
 
BH1750 lightMeter;
 
 
void setup(){
  Serial.begin(9600);
  lightMeter.begin();
  Serial.println("Running...");
}
 
 
void loop() {
  uint16_t lux = lightMeter.readLightLevel();
  Serial.print("Light: ");
  Serial.print(lux);
  Serial.println(" lx");
  delay(1000);
}

Console output

Moving the sensor from the dark to the window gives me the following output:

Light: 99 lx
Light: 99 lx
Light: 101 lx
Light: 101 lx
Light: 101 lx
Light: 99 lx
Light: 46 lx
Light: 1344 lx
Light: 1665 lx
Light: 17 lx
Light: 5 lx
Light: 1485 lx

7 Comments

Leave a Comment.