Remarks

Bh1750
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Light.Bh1750

The BH1750 is a light intensity sensor that communicates over I2C.

Code Example

Bh1750 sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    var i2c = Device.CreateI2cBus();
    sensor = new Bh1750(
        i2c,
        measuringMode: Mode.ContinuouslyHighResolutionMode, // the various modes take differing amounts of time.
        lightTransmittance: 1 // lower this to increase sensitivity, for instance, if it's behind a semi opaque window
        );

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Bh1750.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer: filter satisfied: {result.New.Lux:N2}Lux, old: {result.Old?.Lux:N2}Lux"),

        // only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
        filter: result =>
        {
            if (result.Old is { } old)
            {
                // returns true if > 100lux change
                return ((result.New - old).Abs().Lux > 100);
            }
            return false;
        });
    sensor.Subscribe(consumer);

    // classical .NET events can also be used:
    sensor.Updated += (sender, result) => Resolver.Log.Info($"Light: {result.New.Lux:N2}Lux");

    return Task.CompletedTask;
}

public override async Task Run()
{
    var result = await sensor.Read();
    Resolver.Log.Info("Initial Readings:");
    Resolver.Log.Info($" Light: {result.Lux:N2}Lux");

    sensor.StartUpdating(TimeSpan.FromSeconds(1));
}

Sample project(s) available on GitHub

Wiring Example

To wire a Bh1750 to your Meadow board, connect the following:

Bh1750 Meadow Pin
GND GND
SCL D08 (SCL)
SDA D07 (SDA)
VCC 3V3

It should look like the following diagram:

Characteristic Locus
Inheritance object ObservableBase<Illuminance> SamplingSensorBase<Illuminance> PollingSensorBase<Illuminance> ByteCommsSensorBase<Illuminance> > Bh1750
Implements IObservable<IChangeResult<Illuminance>> IDisposable ILightSensor ISamplingSensor<Illuminance> ISensor<Illuminance> II2cPeripheral
Inherited Members ByteCommsSensorBase<Illuminance>.BusComms ByteCommsSensorBase<Illuminance>.ReadBuffer ByteCommsSensorBase<Illuminance>.WriteBuffer ByteCommsSensorBase<Illuminance>.Init(int, int) ByteCommsSensorBase<Illuminance>.Dispose(bool) ByteCommsSensorBase<Illuminance>.Dispose() PollingSensorBase<Illuminance>.StartUpdating(TimeSpan?) PollingSensorBase<Illuminance>.StopUpdating() SamplingSensorBase<Illuminance>.samplingLock SamplingSensorBase<Illuminance>.Updated SamplingSensorBase<Illuminance>.SamplingTokenSource SamplingSensorBase<Illuminance>.Conditions SamplingSensorBase<Illuminance>.IsSampling SamplingSensorBase<Illuminance>.UpdateInterval SamplingSensorBase<Illuminance>.Read() ObservableBase<Illuminance>.observers ObservableBase<Illuminance>.NotifyObservers(IChangeResult<Illuminance>) ObservableBase<Illuminance>.Subscribe(IObserver<IChangeResult<Illuminance>>) ObservableBase<Illuminance>.CreateObserver(Action<IChangeResult<Illuminance>>, Predicate<IChangeResult<Illuminance>>) object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString()
Namespace Meadow.Foundation.Sensors.Light
Assembly Bh1750.dll

Syntax

public class Bh1750 : ByteCommsSensorBase<Illuminance>, IObservable<IChangeResult<Illuminance>>, IDisposable, ILightSensor, ISamplingSensor<Illuminance>, ISensor<Illuminance>, II2cPeripheral

Constructors

Bh1750(II2cBus, byte, MeasuringModes, double)

Create a new BH1750 light sensor object using a static reference voltage.

Declaration
public Bh1750(II2cBus i2cBus, byte address = 92, Bh1750.MeasuringModes measuringMode = MeasuringModes.ContinuouslyHighResolutionMode, double lightTransmittance = 1)

Parameters

Type Name Description
II2cBus i2cBus
byte address
Bh1750.MeasuringModes measuringMode
double lightTransmittance

Remarks

Bh1750
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Light.Bh1750

The BH1750 is a light intensity sensor that communicates over I2C.

Code Example

Bh1750 sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    var i2c = Device.CreateI2cBus();
    sensor = new Bh1750(
        i2c,
        measuringMode: Mode.ContinuouslyHighResolutionMode, // the various modes take differing amounts of time.
        lightTransmittance: 1 // lower this to increase sensitivity, for instance, if it's behind a semi opaque window
        );

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Bh1750.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer: filter satisfied: {result.New.Lux:N2}Lux, old: {result.Old?.Lux:N2}Lux"),

        // only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
        filter: result =>
        {
            if (result.Old is { } old)
            {
                // returns true if > 100lux change
                return ((result.New - old).Abs().Lux > 100);
            }
            return false;
        });
    sensor.Subscribe(consumer);

    // classical .NET events can also be used:
    sensor.Updated += (sender, result) => Resolver.Log.Info($"Light: {result.New.Lux:N2}Lux");

    return Task.CompletedTask;
}

public override async Task Run()
{
    var result = await sensor.Read();
    Resolver.Log.Info("Initial Readings:");
    Resolver.Log.Info($" Light: {result.Lux:N2}Lux");

    sensor.StartUpdating(TimeSpan.FromSeconds(1));
}

Sample project(s) available on GitHub

Wiring Example

To wire a Bh1750 to your Meadow board, connect the following:

Bh1750 Meadow Pin
GND GND
SCL D08 (SCL)
SDA D07 (SDA)
VCC 3V3

It should look like the following diagram:

Properties

DefaultI2cAddress

The default I2C address for the peripheral

Declaration
public byte DefaultI2cAddress { get; }

Property Value

Type Description
byte

Remarks

Bh1750
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Light.Bh1750

The BH1750 is a light intensity sensor that communicates over I2C.

Code Example

Bh1750 sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    var i2c = Device.CreateI2cBus();
    sensor = new Bh1750(
        i2c,
        measuringMode: Mode.ContinuouslyHighResolutionMode, // the various modes take differing amounts of time.
        lightTransmittance: 1 // lower this to increase sensitivity, for instance, if it's behind a semi opaque window
        );

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Bh1750.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer: filter satisfied: {result.New.Lux:N2}Lux, old: {result.Old?.Lux:N2}Lux"),

        // only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
        filter: result =>
        {
            if (result.Old is { } old)
            {
                // returns true if > 100lux change
                return ((result.New - old).Abs().Lux > 100);
            }
            return false;
        });
    sensor.Subscribe(consumer);

    // classical .NET events can also be used:
    sensor.Updated += (sender, result) => Resolver.Log.Info($"Light: {result.New.Lux:N2}Lux");

    return Task.CompletedTask;
}

public override async Task Run()
{
    var result = await sensor.Read();
    Resolver.Log.Info("Initial Readings:");
    Resolver.Log.Info($" Light: {result.Lux:N2}Lux");

    sensor.StartUpdating(TimeSpan.FromSeconds(1));
}

Sample project(s) available on GitHub

Wiring Example

To wire a Bh1750 to your Meadow board, connect the following:

Bh1750 Meadow Pin
GND GND
SCL D08 (SCL)
SDA D07 (SDA)
VCC 3V3

It should look like the following diagram:

Illuminance

The current illuminance read by the sensor

Declaration
public Illuminance? Illuminance { get; }

Property Value

Type Description
Illuminance?

Remarks

Bh1750
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Light.Bh1750

The BH1750 is a light intensity sensor that communicates over I2C.

Code Example

Bh1750 sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    var i2c = Device.CreateI2cBus();
    sensor = new Bh1750(
        i2c,
        measuringMode: Mode.ContinuouslyHighResolutionMode, // the various modes take differing amounts of time.
        lightTransmittance: 1 // lower this to increase sensitivity, for instance, if it's behind a semi opaque window
        );

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Bh1750.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer: filter satisfied: {result.New.Lux:N2}Lux, old: {result.Old?.Lux:N2}Lux"),

        // only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
        filter: result =>
        {
            if (result.Old is { } old)
            {
                // returns true if > 100lux change
                return ((result.New - old).Abs().Lux > 100);
            }
            return false;
        });
    sensor.Subscribe(consumer);

    // classical .NET events can also be used:
    sensor.Updated += (sender, result) => Resolver.Log.Info($"Light: {result.New.Lux:N2}Lux");

    return Task.CompletedTask;
}

public override async Task Run()
{
    var result = await sensor.Read();
    Resolver.Log.Info("Initial Readings:");
    Resolver.Log.Info($" Light: {result.Lux:N2}Lux");

    sensor.StartUpdating(TimeSpan.FromSeconds(1));
}

Sample project(s) available on GitHub

Wiring Example

To wire a Bh1750 to your Meadow board, connect the following:

Bh1750 Meadow Pin
GND GND
SCL D08 (SCL)
SDA D07 (SDA)
VCC 3V3

It should look like the following diagram:

LightTransmittance

BH1750 Light Transmittance (27.20-222.50%)

Declaration
public double LightTransmittance { get; set; }

Property Value

Type Description
double

Remarks

Bh1750
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Light.Bh1750

The BH1750 is a light intensity sensor that communicates over I2C.

Code Example

Bh1750 sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    var i2c = Device.CreateI2cBus();
    sensor = new Bh1750(
        i2c,
        measuringMode: Mode.ContinuouslyHighResolutionMode, // the various modes take differing amounts of time.
        lightTransmittance: 1 // lower this to increase sensitivity, for instance, if it's behind a semi opaque window
        );

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Bh1750.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer: filter satisfied: {result.New.Lux:N2}Lux, old: {result.Old?.Lux:N2}Lux"),

        // only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
        filter: result =>
        {
            if (result.Old is { } old)
            {
                // returns true if > 100lux change
                return ((result.New - old).Abs().Lux > 100);
            }
            return false;
        });
    sensor.Subscribe(consumer);

    // classical .NET events can also be used:
    sensor.Updated += (sender, result) => Resolver.Log.Info($"Light: {result.New.Lux:N2}Lux");

    return Task.CompletedTask;
}

public override async Task Run()
{
    var result = await sensor.Read();
    Resolver.Log.Info("Initial Readings:");
    Resolver.Log.Info($" Light: {result.Lux:N2}Lux");

    sensor.StartUpdating(TimeSpan.FromSeconds(1));
}

Sample project(s) available on GitHub

Wiring Example

To wire a Bh1750 to your Meadow board, connect the following:

Bh1750 Meadow Pin
GND GND
SCL D08 (SCL)
SDA D07 (SDA)
VCC 3V3

It should look like the following diagram:

MeasuringMode

BH1750 Measuring Mode

Declaration
public Bh1750.MeasuringModes MeasuringMode { get; set; }

Property Value

Type Description
Bh1750.MeasuringModes

Remarks

Bh1750
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Light.Bh1750

The BH1750 is a light intensity sensor that communicates over I2C.

Code Example

Bh1750 sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    var i2c = Device.CreateI2cBus();
    sensor = new Bh1750(
        i2c,
        measuringMode: Mode.ContinuouslyHighResolutionMode, // the various modes take differing amounts of time.
        lightTransmittance: 1 // lower this to increase sensitivity, for instance, if it's behind a semi opaque window
        );

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Bh1750.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer: filter satisfied: {result.New.Lux:N2}Lux, old: {result.Old?.Lux:N2}Lux"),

        // only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
        filter: result =>
        {
            if (result.Old is { } old)
            {
                // returns true if > 100lux change
                return ((result.New - old).Abs().Lux > 100);
            }
            return false;
        });
    sensor.Subscribe(consumer);

    // classical .NET events can also be used:
    sensor.Updated += (sender, result) => Resolver.Log.Info($"Light: {result.New.Lux:N2}Lux");

    return Task.CompletedTask;
}

public override async Task Run()
{
    var result = await sensor.Read();
    Resolver.Log.Info("Initial Readings:");
    Resolver.Log.Info($" Light: {result.Lux:N2}Lux");

    sensor.StartUpdating(TimeSpan.FromSeconds(1));
}

Sample project(s) available on GitHub

Wiring Example

To wire a Bh1750 to your Meadow board, connect the following:

Bh1750 Meadow Pin
GND GND
SCL D08 (SCL)
SDA D07 (SDA)
VCC 3V3

It should look like the following diagram:

Methods

RaiseEventsAndNotify(IChangeResult<Illuminance>)

Raise events for subscribers and notify of value changes

Declaration
protected override void RaiseEventsAndNotify(IChangeResult<Illuminance> changeResult)

Parameters

Type Name Description
IChangeResult<Illuminance> changeResult

The updated sensor data

Overrides

Remarks

Bh1750
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Light.Bh1750

The BH1750 is a light intensity sensor that communicates over I2C.

Code Example

Bh1750 sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    var i2c = Device.CreateI2cBus();
    sensor = new Bh1750(
        i2c,
        measuringMode: Mode.ContinuouslyHighResolutionMode, // the various modes take differing amounts of time.
        lightTransmittance: 1 // lower this to increase sensitivity, for instance, if it's behind a semi opaque window
        );

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Bh1750.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer: filter satisfied: {result.New.Lux:N2}Lux, old: {result.Old?.Lux:N2}Lux"),

        // only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
        filter: result =>
        {
            if (result.Old is { } old)
            {
                // returns true if > 100lux change
                return ((result.New - old).Abs().Lux > 100);
            }
            return false;
        });
    sensor.Subscribe(consumer);

    // classical .NET events can also be used:
    sensor.Updated += (sender, result) => Resolver.Log.Info($"Light: {result.New.Lux:N2}Lux");

    return Task.CompletedTask;
}

public override async Task Run()
{
    var result = await sensor.Read();
    Resolver.Log.Info("Initial Readings:");
    Resolver.Log.Info($" Light: {result.Lux:N2}Lux");

    sensor.StartUpdating(TimeSpan.FromSeconds(1));
}

Sample project(s) available on GitHub

Wiring Example

To wire a Bh1750 to your Meadow board, connect the following:

Bh1750 Meadow Pin
GND GND
SCL D08 (SCL)
SDA D07 (SDA)
VCC 3V3

It should look like the following diagram:

ReadSensor()

Read the current luminosity

Declaration
protected override Task<Illuminance> ReadSensor()

Returns

Type Description
Task<Illuminance>

The current Illuminance value

Overrides

Remarks

Bh1750
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Light.Bh1750

The BH1750 is a light intensity sensor that communicates over I2C.

Code Example

Bh1750 sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    var i2c = Device.CreateI2cBus();
    sensor = new Bh1750(
        i2c,
        measuringMode: Mode.ContinuouslyHighResolutionMode, // the various modes take differing amounts of time.
        lightTransmittance: 1 // lower this to increase sensitivity, for instance, if it's behind a semi opaque window
        );

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Bh1750.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer: filter satisfied: {result.New.Lux:N2}Lux, old: {result.Old?.Lux:N2}Lux"),

        // only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
        filter: result =>
        {
            if (result.Old is { } old)
            {
                // returns true if > 100lux change
                return ((result.New - old).Abs().Lux > 100);
            }
            return false;
        });
    sensor.Subscribe(consumer);

    // classical .NET events can also be used:
    sensor.Updated += (sender, result) => Resolver.Log.Info($"Light: {result.New.Lux:N2}Lux");

    return Task.CompletedTask;
}

public override async Task Run()
{
    var result = await sensor.Read();
    Resolver.Log.Info("Initial Readings:");
    Resolver.Log.Info($" Light: {result.Lux:N2}Lux");

    sensor.StartUpdating(TimeSpan.FromSeconds(1));
}

Sample project(s) available on GitHub

Wiring Example

To wire a Bh1750 to your Meadow board, connect the following:

Bh1750 Meadow Pin
GND GND
SCL D08 (SCL)
SDA D07 (SDA)
VCC 3V3

It should look like the following diagram:

Events

IlluminanceUpdated

Raised when a new Illuminance value is read by the sensor

Declaration
public event EventHandler<IChangeResult<Illuminance>> IlluminanceUpdated

Event Type

Type Description
EventHandler<IChangeResult<Illuminance>>

Remarks

Bh1750
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Light.Bh1750

The BH1750 is a light intensity sensor that communicates over I2C.

Code Example

Bh1750 sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    var i2c = Device.CreateI2cBus();
    sensor = new Bh1750(
        i2c,
        measuringMode: Mode.ContinuouslyHighResolutionMode, // the various modes take differing amounts of time.
        lightTransmittance: 1 // lower this to increase sensitivity, for instance, if it's behind a semi opaque window
        );

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Bh1750.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer: filter satisfied: {result.New.Lux:N2}Lux, old: {result.Old?.Lux:N2}Lux"),

        // only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
        filter: result =>
        {
            if (result.Old is { } old)
            {
                // returns true if > 100lux change
                return ((result.New - old).Abs().Lux > 100);
            }
            return false;
        });
    sensor.Subscribe(consumer);

    // classical .NET events can also be used:
    sensor.Updated += (sender, result) => Resolver.Log.Info($"Light: {result.New.Lux:N2}Lux");

    return Task.CompletedTask;
}

public override async Task Run()
{
    var result = await sensor.Read();
    Resolver.Log.Info("Initial Readings:");
    Resolver.Log.Info($" Light: {result.Lux:N2}Lux");

    sensor.StartUpdating(TimeSpan.FromSeconds(1));
}

Sample project(s) available on GitHub

Wiring Example

To wire a Bh1750 to your Meadow board, connect the following:

Bh1750 Meadow Pin
GND GND
SCL D08 (SCL)
SDA D07 (SDA)
VCC 3V3

It should look like the following diagram: