PHPackages                             dept-of-scrapyard-robotics/bh1750 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. dept-of-scrapyard-robotics/bh1750

ActiveLibrary[Framework](/categories/framework)

dept-of-scrapyard-robotics/bh1750
=================================

Drive BH1750 ALS sensors over I2C with PHP

0.4.0(1mo ago)04MITPHPPHP ^8.3

Since Jun 2Pushed 1mo agoCompare

[ Source](https://github.com/DeptOfScrapyardRobotics/BH1750)[ Packagist](https://packagist.org/packages/dept-of-scrapyard-robotics/bh1750)[ Docs](https://dosr.projectsaturnstudios.com)[ RSS](/packages/dept-of-scrapyard-robotics-bh1750/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

Introduction
============

[](#introduction)

PHP Package for the BH1750 ambient light sensor.

Compatible I2C Interfaces
=========================

[](#compatible-i2c-interfaces)

The BH1750 communicates with your device over I2C, the InterIntegrated Circuit Protocol.

You can interface with a BH1750 with this package the following ways:

- A Linux Single-Board Computer's exposed GPIO pins using the dedicated I2C SDA/SCL pins
- An MPSSE-enabled USB-to-Serial device such as an FT232H generally using D0 and SCL and D1 for SDA connected to nearly any Linux or MacOS USB port.

Dependencies
============

[](#dependencies)

This package makes use of modules within:

- [The ScrapyardIO Framework](https://github.com/ScrapyardIO/framework)

This package also requires one of the following extensions in order to interface with I2C

- [POSI Extension v^0.4.0 or newer](https://github.com/php-io-extensions/posi)
- [FTDI Extension v^0.4.0 or newer](https://github.com/php-io-extensions/ftdi)

In addition, an extension wrapper package is needed

For ext-posi

- [Microscrap POSIX Package v0.4.0 or newer](https://github.com/microscrap/posix)
- [Microscrap Native I2C Package v0.4.0 or newer](https://github.com/microscrap/gpio)

For ext-ftdi

- [Microscrap FTDI Package v0.4.0 or newer](https://github.com/microscrap/ftdi)
- [Microscrap MPSSE Package v0.4.0 or newer](https://github.com/microscrap/mpsse)

Installing from Composer
========================

[](#installing-from-composer)

Inside the root of your PHP Project, simply require the BH1750 package from composer

```
composer require dept-of-scrapyard-robotics/bh1750
```

Framework Configuration
=======================

[](#framework-configuration)

If you would like to use the ScrapyardIO Framework to bootstrap your sensor without wasting lines configuring your sensor right in the script you can add your desired configuration to scrapyard-io.php, such as in this example:

```
use DeptOfScrapyardRobotics\Sensors\BH1750\BH1750\BH1750;

return [
    'boards' => [
        'bh1750-native' => [
            'class_name' => BH1750::class,
            'connection' => [
                'driver' => 'native',
            ],
            'startup' => [
                'i2c' => [
                    'chip_device' => 1,
                    'slave_address' => 0x23,
                ],
            ],
        ],
        'bh1750-usb' => [
            'class_name' => BH1750::class,
            'connection' => [
                'driver' => 'usb',
            ],
            'startup' => [
                'i2c' => [
                    'chip_device' => 'ft232h',
                    'slave_address' => 0x23,
                ],
            ],
        ]
    ]
];
```

The keys you choose to represent the integrated circuit's definition are up to you.

To bootstrap quickly using a ScrapyardIO `AmbientLightSensor` object you can start with the following:

```
use RealityInterface\Sensors\Applied\AmbientLighting\AmbientLightSensor;

$bh1750 = AmbientLightSensor::using('bh1750-native');

$lux = $bh1750->getLuminance();
```

Basic Usage
===========

[](#basic-usage)

To use the sensor directly without the framework simply do the following:

```
use DeptOfScrapyardRobotics\Sensors\BH1750\BH1750\BH1750;
use DeptOfScrapyardRobotics\Sensors\BH1750\BH1750\Enums\BH1750I2CAddress;

$native_sensor = BH1750::connection('native')
    ->i2c(1, BH1750I2CAddress::ADDR_GROUNDED->value)
    ->create();

$lux = $native_sensor->lux;
```

Advanced Usage
==============

[](#advanced-usage)

Mode and resolution both influence how the BH1750 takes readings:

- Mode controls whether the device is continuously sampling, in one-shot, or shutdown.
- Resolution controls measurement precision and conversion behavior.

The BH1750 packs mode and resolution into a settings byte. You can directly read and write that settings value, or send control commands to the chip:

```
use DeptOfScrapyardRobotics\Sensors\BH1750\BH1750\Enums\BH1750WriteRegister;

$settings = $native_sensor->_settings;

$native_sensor->_settings = 0x10;
$native_sensor->_write = BH1750WriteRegister::RESET;
```

When using the sensor directly, you can also inspect the raw reading:

```
$raw = $native_sensor->_raw_reading;
```

Injected into the Framework
===========================

[](#injected-into-the-framework)

To inject into the framework, that is, bootstrap the device directly then pass it off to an `AmbientLightSensor` object simply do the following:

```
use DeptOfScrapyardRobotics\Sensors\BH1750\BH1750\BH1750;
use DeptOfScrapyardRobotics\Sensors\BH1750\BH1750\Enums\BH1750I2CAddress;
use RealityInterface\Sensors\Applied\AmbientLighting\AmbientLightSensor;

$usb_sensor = BH1750::connection('usb')
    ->i2c('ft232h', BH1750I2CAddress::ADDR_GROUNDED->value)
    ->create();

$als = AmbientLightSensor::as($usb_sensor);

$lux = $als->getLuminance();
```

Calibration
===========

[](#calibration)

To calibrate the sensor on the chip, you will need a reference sensor, that is shown to give out reliable Luminance readings.

- Bootstrap or inject the sensor into an `AmbientLightSensor` object.
- Make sure your sensor and the reference sensor are looking at the same target
- use the getLuminance method on the BH1750 at the same time as you pull a measurement from the reference.
- Use the `AmbientLightSensor`'s calibrate method

Refer to this simulated example

```
use RealityInterface\Sensors\Applied\AmbientLighting\AmbientLightSensor;

$bh1750 = AmbientLightSensor::using('bh1750-native');

// Simulated out-of-scope event measuring both sensors at the same time
$current_lux = $bh1750->getLuminance();
$ref = (int) "your-reference-lux";

// Add the values from your calibration session here.
$bh1750 = $bh1750->calibrate($ref, $current_lux);

// The output of getLuminance() will now be adjusted with your compensation factor
// computed from the calibration.
$adjusted_lux = $bh1750->getLuminance();
```

Sensor API
==========

[](#sensor-api)

The getters and setters in this API interface with the device directly (register reads/writes), so you can use simple property access while still working against the chip itself.

Readable Properties (Getters)
-----------------------------

[](#readable-properties-getters)

- `$sensor->lux`
    Reads the sensor and calculates lux from the measurement output.
- `$sensor->_settings`
    Reads the current settings byte used for mode and resolution.
- `$sensor->_raw_reading`
    Reads and returns the raw 16-bit light value from the device.

Writable Properties (Setters)
-----------------------------

[](#writable-properties-setters)

- `$sensor->_settings = 0x10;`
    Writes a settings byte directly to the device.
- `$sensor->_write = BH1750WriteRegister::RESET;`
    Sends a direct command register write (`POWER_DOWN`, `POWER_ON`, `RESET`).

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance90

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

52d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10563160?v=4)[Angel Gonzalez](/maintainers/projectsaturnstudios)[@projectsaturnstudios](https://github.com/projectsaturnstudios)

---

Top Contributors

[![projectsaturnstudios](https://avatars.githubusercontent.com/u/10563160?v=4)](https://github.com/projectsaturnstudios "projectsaturnstudios (2 commits)")

---

Tags

frameworkscrapyard-ioambient-list-sensorlux-sensor

### Embed Badge

![Health badge](/badges/dept-of-scrapyard-robotics-bh1750/health.svg)

```
[![Health](https://phpackages.com/badges/dept-of-scrapyard-robotics-bh1750/health.svg)](https://phpackages.com/packages/dept-of-scrapyard-robotics-bh1750)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
