Sensor – BH1750 – Lichtintensiteit sensor
Hardware
This is a BH1750 light intensity sensor breakout board with a 16 bit AD converter built-in which can directly output a digital signal, there is no need for complicated calculations. This is a more acurate and easier to use version of the simple LDR which only outputs a voltage that needs to be calculated in order to obtain meaningful data. With the BH1750 Light Sensor intensity can be directly measured by the luxmeter, without needing to make calculations. The data which is output by this sensor is directly output in Lux (Lx). When objects which are lighted in homogeneous get the 1 lx luminous flux in one square meter ,their light intensity is 1lx. Sometimes to take good advantage of the illuminant, you can add a reflector to the illuminant.So that there will be more luminous flux in some directions and it can increase the ilumination of the target surface.
For example:
Night: 0.001–0.02;
moonlightnight:0.02–0.3;
cloudy indoor:5–50;
cloudy outdoor:50–500;
Sunny indoor:100–1000;
under the sunlight in summer afternoon: about 10*6 power;
reading books for intensity of illumination:50–60;
home video standard intensity of illumination:1400.
Properties:
- I2C bus Interface
- Spectral responsibility is approximately human eye response
- Illuminance to Digital Converter
- Wide range and High resolution. ( 1 – 65535 lx )
- Low Current by power down function
- 50Hz / 60Hz Light noise reject-function
- Light source dependency is little. ( ex. Incandescent Lamp. Fluorescent Lamp. Halogen Lamp. White LED. Sun Light)
- It is possible to select 2 type of I2C slave-address
- Adjustable measurement result for influence of optical window
- Small measurement variation (+/- 20%)
- The influence of infrared is very small
- Operating Voltage: 3.3V-5V
- Dimensions: 0.85*0.63*0.13″(21*16*3.3mm)
Pinout
BH1750 Pin (bovenkant en van links naar rechts): | Functie |
---|---|
1 | ADDR |
2 | SDA (Serial Data) |
3 | SDL (Serial Clock) |
4 | GND |
5 | VCC (3.3v - 5v) |
Er zijn ook andere varianten zoals de BH1750FVI, deze heeft wel een andere pinout!
Arduino
Wat heb je nodig?
1) BH1750 (Gy-302) bibliotheek
Sluit de lichtsensor module aan volgens onderstaand overzicht:
BH1750 pin (bovenkant en van links naar rechts): | Arduino pin: |
---|---|
2 - SDA (Serial Data) | A4 |
3 - SDL (Serial Clock) | A5 |
4 - GND | GND |
5 - VCC (3.3v - 5v) | +5v |
Script
Sluit de lichtsensor module aan zoals hierboven aangegeven.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include <Wire.h> #include <BH1750.h> BH1750 lichtMeter; void setup(){ Serial.begin(9600); lichtMeter.begin(); } void loop() { uint16_t lux = lichtMeter.readLightLevel(); Serial.print("Licht: "); Serial.print(lux); Serial.println(" lux"); delay(500); } |
Het resultaat
Een ander script zonder gebruik van een “extra” bibliotheek:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include <Wire.h> //BH1750 IIC Mode #include <math.h> int BH1750_Device = 0x23; // I2C address for light sensor unsigned int Lux, Scaled_FtCd; float FtCd, Wattsm2; void setup() { Wire.begin(); Serial.begin(9600); Wire.beginTransmission(BH1750_Device); Wire.write(0x10); // Set resolution to 1 Lux Wire.endTransmission(); delay(200); } void loop() { int i; Lux = BH1750_Read(); FtCd = Lux/10.764; Wattsm2 = Lux/683.0; Serial.print(Lux,DEC); Serial.println("[lx]"); Serial.print(FtCd,2); Serial.println("[FC]"); Serial.print(Wattsm2,4); Serial.println("[Watts/m^2]"); delay(1000); } unsigned int BH1750_Read() { unsigned int i=0; Wire.beginTransmission(BH1750_Device); Wire.requestFrom(BH1750_Device, 2); while(Wire.available()) // { i <<=8; i|= Wire.read(); } Wire.endTransmission(); return i/1.2; // Convert to Lux } |
Resultaat:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
670[lx] 62.24[FC] 0.9810[Watts/m^2] 650[lx] 60.39[FC] 0.9517[Watts/m^2] 548[lx] 50.91[FC] 0.8023[Watts/m^2] 16[lx] 1.49[FC] 0.0234[Watts/m^2] 14[lx] 1.30[FC] 0.0205[Watts/m^2] 19[lx] 1.77[FC] 0.0278[Watts/m^2] |
Arduino Library
BH1750 (GY-302)
An Arduino library for digital light sensor breakout boards containing the BH1750FVI IC.
– The board uses I2C for communication.
– 2 pins are required to interface to the device.
Raspberry Pi
Sluit de lichtsensor module aan volgens onderstaand overzicht:
Ps. Altijd de pinout van je Raspberry Pi controleren, deze kan verschillen per versie.
Script
Wat heb je nodig?
1) I2C bus gebruiken op de Raspberry Pi
Met onderstaande Python code kan de Bh1750 module uitgelezen worden, maak een bestand aan genaamd bh1750.py met deze inhoud:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
#!/usr/bin/python import smbus import time # Define some constants from the datasheet DEVICE = 0x23 # Default device I2C address POWER_DOWN = 0x00 # No active state POWER_ON = 0x01 # Power on RESET = 0x07 # Reset data register value # Start measurement at 4lx resolution. Time typically 16ms. CONTINUOUS_LOW_RES_MODE = 0x13 # Start measurement at 1lx resolution. Time typically 120ms CONTINUOUS_HIGH_RES_MODE_1 = 0x10 # Start measurement at 0.5lx resolution. Time typically 120ms CONTINUOUS_HIGH_RES_MODE_2 = 0x11 # Start measurement at 1lx resolution. Time typically 120ms # Device is automatically set to Power Down after measurement. ONE_TIME_HIGH_RES_MODE_1 = 0x20 # Start measurement at 0.5lx resolution. Time typically 120ms # Device is automatically set to Power Down after measurement. ONE_TIME_HIGH_RES_MODE_2 = 0x21 # Start measurement at 1lx resolution. Time typically 120ms # Device is automatically set to Power Down after measurement. ONE_TIME_LOW_RES_MODE = 0x23 #bus = smbus.SMBus(0) # Rev 1 Pi uses 0 bus = smbus.SMBus(1) # Rev 2 Pi uses 1 def convertToNumber(data): # Simple function to convert 2 bytes of data # into a decimal number return ((data[1] + (256 * data[0])) / 1.2) def readLight(addr=DEVICE): data = bus.read_i2c_block_data(addr,ONE_TIME_HIGH_RES_MODE_1) return convertToNumber(data) def main(): while True: print "Light Level : " + str(readLight()) + " lux" time.sleep(0.5) if __name__=="__main__": main() |
En start dit bestand met het commando: sudo python bh1750.py
Output:
Schema
Teardown
GEEN GEGEVENS
Datasheet
Fritzing
Downloads
GEEN GEGEVENS