Adafruit Bh1750 Ambient Light Sensor
Adafruit Bh1750 Ambient Light Sensor
https://learn.adafruit.com/adafruit-bh1750-ambient-light-sensor
Overview 3
Pinouts 5
• Power Pins
• I2C Logic Pins
Arduino 6
• I2C Wiring
• Library Installation
• Load Example
• Example Code
Arduino Docs 8
Python Docs 12
WipperSnapper 12
• What is WipperSnapper
• Wiring
• Usage
Downloads 19
• Files
• Schematic
• Fab Print
This is the BH1750 16-bit Ambient Light sensor from Rohm. Because of how important
it is to humans and most other living things, sensing the amount of light in an
environment is a common place to get started when learning to work with
microcontrollers and sensors. Should we turn up the brightness of our display or dim
it to save power? Which direction should your robot move to stay in an area with the
most light? Is it day or night? All of these questions can be answered with the help of
the BH1750 (https://adafru.it/MfK). It's a small, capable and inexpensive light sensor
that you can include into your next project to add the detection and measurement of
light.
The BH1750 provides 16-bit light measurements in lux, the SI unit for measuring light
making it easy to compare against other values like references and measurements
Sensors tend to come in small packages and the BH1750 is no different. Not much
bigger than a grain of rice, this handy light sensing friend needs some help to be
used by folks experimenting and without the desire or tools to work with surface
mount parts. We're here to help! Packaged on a PCB in our Stemma QT form factor,
the BH1750 comes integrated with a voltage regulator and level shifting circuitry to
allow it to be used with 3.3V devices like a Feather M4 or Raspberry Pi, or 5V devices
such as an Arduino. Rather than working with the itty bitty little contacts on the
sensor, the PCB it's packaged on breaks out all the pins to a standard 0.1 inch /
2.54mm pitch header.
To make things easier and a bit more flexible, we've also included SparkFun Qwiic (htt
ps://adafru.it/Fpw) compatible STEMMA QT (https://adafru.it/Ft4) connectors for the
I2C bus so you don't even need to solder!
Pinouts
Power Pins
• VIN - this is the power pin. Since the sensor chip uses 3 VDC, we have included
a voltage regulator on board that will take 3-5VDC and safely convert it down.
To power the board, give it the same power as the logic level of your
microcontroller - e.g. for a 5V microcontroller like Arduino, use 5V
• 3Vo - this is the 3.3V output from the voltage regulator, you can grab up to
100mA from this if you like
• GND - common ground for power and logic
Arduino
Using the BH1750 with Arduino is a simple matter of wiring up the sensor to your
Arduino-compatible microcontroller, installing the hp_BH1750 (https://adafru.it/MfD)
library written by Stefan Armborst (https://adafru.it/MfE), and running one of many very
well written examples. Usually we write our own library but we were so impressed by
Stefan's that we didn't think we could possibly improve on it, so use it!
I2C Wiring
Use this wiring if you want to connect via I2C interface. The I2C address address for
the BH1750 is 0x23 and can be switched to 0x5C by pulling the address pin high to
VCC
Here is how to wire up the sensor using one of the STEMMA QT (https://adafru.it/Ft4)
connectors. The examples show a Metro but wiring will work the same for an Arduino
or other compatible board.
Library Installation
You can install the hp_BH1750 (https://adafru.it/MfD) library for Arduino using the
Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for hp BH1750, and select the hp_B
H1750 library:
After opening the demo file, upload to your Arduino wired up to the sensor. Once you
upload the code, you will see the Lux values being printed when you open the Serial
Monitor (Tools->Serial Monitor) at 9600 baud, similar these measurements I got from
waving a flashlight at the sensor
Example Code
Arduino Docs
Arduino Docs (https://adafru.it/M0A)
You can use this sensor with any CircuitPython microcontroller board or with a
computer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-
Python compatibility library (https://adafru.it/BSN).
You can also use the standard 0.100" pitch headers to wire it up on a breadboard:
Here's the Raspberry Pi wired to the sensor using I2C and a STEMMA QT (https://
adafru.it/Ft4) connector:
First make sure you are running the latest version of Adafruit CircuitPython (https://
adafru.it/Amd) for your board.
Before continuing make sure your board's lib folder or root filesystem has the adafruit
_bh1750.mpy file and adafruit_bus_device folder copied over.
Next connect to the board's serial REPL (https://adafru.it/Awz)so you are at the
CircuitPython >>> prompt.
Once that's done, from your command line run the following command:
If your default Python is version 3 you may need to run 'pip' instead. Just make sure
you aren't trying to use CircuitPython on Python 2.x, it isn't supported!
Run the following code to import the necessary modules and initialize the I2C
connection with the sensor:
Now you're ready to read values from the sensor using the lux property to return the
ambient light level in lux, the SI derived unit (https://adafru.it/MfI) for measuring
illuminance (https://adafru.it/MfJ)
# SPDX-License-Identifier: Unlicense
import time
import board
import adafruit_bh1750
while True:
print("%.2f Lux" % sensor.lux)
time.sleep(1)
Python Docs
Python Docs (https://adafru.it/M0B)
WipperSnapper
What is WipperSnapper
WipperSnapper is a firmware designed to turn any WiFi-capable board into an
Internet-of-Things device without programming a single line of code. WipperSnapper
connects to Adafruit IO (https://adafru.it/fsU), a web platform designed (by
Simply load the WipperSnapper firmware onto your board, add credentials, and plug it
into power. Your board will automatically register itself with your Adafruit IO account.
From there, you can add components to your board such as buttons, switches,
potentiometers, sensors, and more! Components are dynamically added to hardware,
so you can immediately start interacting, logging, and streaming the data your
projects produce without writing code.
If you've never used WipperSnapper, click below to read through the quick start guide
before continuing.
Quickstart: Adafruit IO
WipperSnapper
https://adafru.it/Vfd
Wiring
First, wire up a BH1750 to your board exactly as follows. Here is an example of the
BH1750 wired to an Adafruit ESP32 Feather V2 (http://adafru.it/5400) using I2C with a
STEMMA QT cable (no soldering required) (http://adafru.it/4210)
Usage
Connect your board to Adafruit IO Wippersnapper and navigate to the
WipperSnapper board list (https://adafru.it/TAu).
On this page, select the WipperSnapper board you're using to be brought to the
board's interface page.
Next, make sure the sensor is plugged into your board and click the I2C Scan button.
With the sensor detected in an I2C scan, you're ready to add the sensor to your
board.
Click the New Component button or the + button to bring up the component picker.
On the component configuration page, the BH1750's sensor address should be listed
along with the sensor's settings.
The Send Every option is specific to each sensor's measurements. This option will tell
the Feather how often it should read from the BH1750 sensor and send the data to
Adafruit IO. Measurements can range from every 30 seconds to every 24 hours.
For this example, set the Send Every interval to every 30 seconds.
To view the data that has been logged from the sensor, click on the graph next to the
sensor name.
Downloads
Files
• BH1750 Datasheet (https://adafru.it/MfK)
• EagleCAD files on GitHub (https://adafru.it/MfL)
Schematic
Fab Print