Leon Anavi
IT Tips && Tricks

Mobile & Embedded

Created: 01.10.2023 06:41 Last Modified: 01.10.2023 08:29 Views: 1906
Keywords: BH1750, GitHub, Linux, Luma, Python, Raspberry Pi, smbus, Light

DIY Light Meter with Raspberry Pi, BH1750 I2C sensor, Python and Linux

In this tutorial you will learn how to make a light meter with Raspberry Pi single board computer and Linux. BH1750 is an affordable ambient light sensor that can be easily integrated with various development boards like Raspberry Pi, Arduino, ESP32, and more. In this step-by-step tutorial, we will show you how to use the BH1750 sensor to measure light intensity in lux using a Python 3 script on a Raspberry Pi. Additionally, we will display the measured light value on a mini OLED yellow-blue display. Both the BH1750 sensor and the OLED display will be connected to the Raspberry Pi using the widely-used I2C bus communication protocol. The following hardware is required:

  • Raspberry Pi single board computer
  • BH1750 Ambient Light Sensor
  • Mini OLED Display (yellow-blue)
  • add-on board such as ANAVI Info uHAT, ANAVI CO2 uHAT or jumper wires and a readboard

Make sure you have your Raspberry Pi set up with Raspberry Pi OS based on the Debian Linux distribution and connected to the internet. Also, ensure that your development environment is ready for Python programming. It is mandatory to enable I2C on Raspberry Pi OS. You can do it using the command-line tool rpi-config as per the user's documentation.

Connect the BH1750 sensor to your Raspberry Pi as follows:

  • VCC to 3.3V (Pin 1 on Raspberry Pi)
  • GND to GND (Pin 6 on Raspberry Pi)
  • SDA to SDA (Pin 3 on Raspberry Pi)
  • SCL to SCL (Pin 5 on Raspberry Pi)

Connect the mini OLED display to your Raspberry Pi:

  • VCC to 3.3V (Pin 1 on Raspberry Pi)
  • GND to GND (Pin 6 on Raspberry Pi)
  • SDA to SDA (Pin 3 on Raspberry Pi)
  • SCL to SCL (Pin 5 on Raspberry Pi)

You will need to install the SMBus library for I2C communication and the Luma library for the OLED display. Open a terminal on your Raspberry Pi and run the following commands:

pip3 install smbus
pip3 install luma.oled

Get the open source code from GitHub and run it:



You will now see the ambient light intensity displayed in lux on your mini OLED display. The script continuously updates the light intensity reading, making it a useful tool for various projects that require light monitoring.

The BH1750 ambient light sensor, when combined with a Raspberry Pi and a mini OLED display, allows you to easily measure and display light intensity in lux. This versatile setup can be used in a variety of applications, including smart lighting systems, environmental monitoring, and more, providing valuable insights into ambient lighting conditions.



  Home | About | Contact | Disclaimer | Sitemap © 2009-2022 Leon Anavi. All rights reserved.