ESP8266 and Ambient light Shield example

This was another new shield for the Wemos called the Ambient light Shield , this time its based around the BH1750FVI digital Ambient Light Sensor

Lets look at some info about the sensor

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. ( 1 – 65535 lx ).

●Features

1) I2C bus Interface ( f / s Mode Support )
2) Spectral responsibility is approximately human eye response
3) Illuminance to Digital Converter
4) Wide range and High resolution. ( 1 – 65535 lx )
5) Low Current by power down function
6) 50Hz / 60Hz Light noise reject-function
7) 1.8V Logic input interface
8) No need any external parts
9) Light source dependency is little. ( ex. Incandescent Lamp. Fluorescent Lamp. Halogen Lamp. White LED. Sun Light )
10) It is possible to select 2 type of I2C slave-address.
11) Adjustable measurement result for influence of optical window ( It is possible to detect min. 0.11 lx, max. 100000 lx by using this function. )
12) Small measurement variation (+/- 20%)
13) The influence of infrared is very small.

Being an I2C device it uses D1 and D2 on the Wemos mini

Code

You need to install the following library for this example :  https://github.com/claws/BH1750 

[codesyntax lang=”cpp”]

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


BH1750 lightMeter(0x23);

void setup(){

  Serial.begin(9600);

  // Initialize the I2C bus
  Wire.begin();

  if (lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) 
  {
    Serial.println(F("BH1750 Advanced begin"));
  }
  else 
  {
    Serial.println(F("Error initialising BH1750"));
  }

}


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

[/codesyntax]

 

Output

Open the serial monitor, cover the sensor, shine light on the sensor and so on to see the readings change, you can see where I covered it completely reading 0 lx

Light: 29 lx
Light: 29 lx
Light: 22 lx
Light: 0 lx
Light: 0 lx
Light: 20 lx
Light: 18 lx
Light: 28 lx
Light: 27 lx

 

Link

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here