Light Sensor¶
The BH 1750 ambient light sensor operates on the S2C protocol which much be setup before using this device. To do this, look at the following section:
Setting up I2C¶
First step is to install i2c tools, this makes detecting device addresses much easier. This can be accomplished by running the following command.
sudo apt-get install -y i2c-tools
Next you will need to make sure I2C is enabled on the raspberry.
To do this, run the following command:
sudo raspi-config
You will presented with a menu screen. Select 5. Interfacing Options, and then P5, I2C.
Enable this interface, exit and save configuration.
WiringPi Prerequsites¶
I2C functionality requires WiringPi to be installed on your raspberry pi. In some cases this is pre-installed. To check whether this is installed, run the following command.
gpio readall
If Wiring Pi installed, you will be presented with a chart similar to the following:
+-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+ | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM | +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+ | | | 3.3v | | | 1 || 2 | | | 5v | | | | 2 | 8 | SDA.1 | ALT0 | 1 | 3 || 4 | | | 5v | | | | 3 | 9 | SCL.1 | ALT0 | 1 | 5 || 6 | | | 0v | | | | 4 | 7 | GPIO. 7 | IN | 0 | 7 || 8 | 0 | IN | TxD | 15 | 14 | | | | 0v | | | 9 || 10 | 1 | IN | RxD | 16 | 15 | | 17 | 0 | GPIO. 0 | IN | 0 | 11 || 12 | 0 | IN | GPIO. 1 | 1 | 18 | | 27 | 2 | GPIO. 2 | IN | 0 | 13 || 14 | | | 0v | | | | 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 0 | IN | GPIO. 4 | 4 | 23 | | | | 3.3v | | | 17 || 18 | 0 | IN | GPIO. 5 | 5 | 24 | | 10 | 12 | MOSI | ALT0 | 0 | 19 || 20 | | | 0v | | | | 9 | 13 | MISO | ALT0 | 0 | 21 || 22 | 0 | IN | GPIO. 6 | 6 | 25 | | 11 | 14 | SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT | CE0 | 10 | 8 | | | | 0v | | | 25 || 26 | 1 | OUT | CE1 | 11 | 7 | | 0 | 30 | SDA.0 | IN | 1 | 27 || 28 | 1 | IN | SCL.0 | 31 | 1 | | 5 | 21 | GPIO.21 | IN | 1 | 29 || 30 | | | 0v | | | | 6 | 22 | GPIO.22 | IN | 1 | 31 || 32 | 0 | IN | GPIO.26 | 26 | 12 | | 13 | 23 | GPIO.23 | IN | 0 | 33 || 34 | | | 0v | | | | 19 | 24 | GPIO.24 | IN | 0 | 35 || 36 | 0 | IN | GPIO.27 | 27 | 16 | | 26 | 25 | GPIO.25 | IN | 0 | 37 || 38 | 0 | IN | GPIO.28 | 28 | 20 | | | | 0v | | | 39 || 40 | 0 | IN | GPIO.29 | 29 | 21 | +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+ | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM | +-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+
If you get this chart, proceed to Connecting the Sensor
If you get a no such command error, proceed to installation instructions:
Installing WiringPi¶
Wiring Pi requires that you install git, and then compile the code, therefore you must first install git. To do this from the command line, run the following commands.
First update the pi:
sudo apt-get update && sudo apt-get upgrade
Once this is finished, now install git:
sudo apt-get install git git-core
Then use git to download wiringpi code:
it clone git://git.drogon.net/wiringPi cd wiringPi ./build
Once this is done you can now run the gpio command and verify wiring pi is installed.
Turn off the device to plug in your sensor
sudo shutdown
Connecting the Sensor¶
Use the following wiring diagram to connect your device. Note that SDA and SDC MUST be connected to pins 3 and 5 as I2C devices must communicate on those pins.
Turn on your raspberry Pi and let it boot up. Once you are logged in, run the following command
i2cdetect -y 1
You will presented with a map like the following:
0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- 23 -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
This polls bus 1 of the i2c system, which is the one the model 3 uses.
Devices connected using i2c will be listed in this screen. In this case a device is connected at address 23.
Error from i2cdetect¶
If you result in this error:
Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or directory
You are likely using an older model such as the model 1 and 2 and will need to check bus 0
i2cdetect -y 0
Adding the Sensor¶
Once you've connected the device and booted, now proceed to add the sensor from Light Sensor -> BH1750
Note that the Address and Bus are separate entries. Be sure that you select the proper address as displayed in the graph. In our example it is 23 on bus 1.
Once added, the client will display how many Lux the sensor is being exposed too:
A Note about connections¶
In some cases the BH1750 sensor might not receive enough power from the breakout board or ribbon cables. i2cdetect will show devices if they are receiving enough power, however if none is shown, or you get an entry of 00 someplace in the matrix, your device might not have enough power to run.
Specifications¶
Field | Range |
---|---|
Power | +3v-5v DC |
Lux Sensitivity | 1 - 65535 lx |
Lux Accuracy | +/- 20% |
Lux reference¶
Here is a small chart from Wikipedia that provides some reference for the Lux unit.
Source: Wikipedia (https://en.wikipedia.org/wiki/Lux)
Illuminance (lux) | Surfaces illuminated by |
---|---|
0.0001 | Moonless, overcast night sky (starlight) |
0.002 | Moonless clear night sky with airglow |
0.05–0.3 | Full moon on a clear night |
3.4 | Dark limit of civil twilight under a clear sky |
20–50 | Public areas with dark surroundings |
50 | Family living room lights |
80 | Office building hallway/toilet lighting |
100 | Very dark overcast day |
150 | Train station platforms |
320–500 | Office lighting |
400 | Sunrise or sunset on a clear day |
1000 | Overcast day, typical TV studio lighting |
10,000–25,000 | Full daylight (not direct sun) |
32,000–100,000 | Direct sunlight |