micro:bit and BH1750FVI Ambient Light Sensor example

The BH1750FVI is an digital Ambient Light Sensor IC for I2C bus interface. This IC is the most suitable to obtain the ambient light data for adjusting LCD and Keypad backlight power of Mobile phone. It is possible to detect wide range at High resolution.

This is the module I used

For those that are interested I found this schematic online for the module

 

Connection

A fairly standard connection being an I2C device.

VCC  –  Micro:bit 3.3v
GND – Micro:bit  Gnd
SCL – Micro:bit P19
SDA – Micro:bit P20

 

Code

You will need this modified library, I could not get the original Arduino one to work – BH1750-master

[codesyntax lang=”cpp”]

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

[/codesyntax]

 

Output

Open the serial monitor and cover the sensor, shine some light on it and so on. You should see the lux value change

Light: 19 lx
Light: 22 lx
Light: 17 lx
Light: 9 lx
Light: 2 lx
Light: 8 lx
Light: 9 lx

 

 

Links
You can pick these sensors up for about $4 a piece
BH1750FVI light intensity illumination module for arduino 3V-5V

Leave a Comment

This div height required for enabling the sticky sidebar
Ad Clicks : Ad Views : Ad Clicks : Ad Views :