Skip to main content

Meadow.Foundation.Sensors.Temperature.Ds18B20

Ds18B20
StatusStatus badge: in-progress
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Sensors.Temperature.Ds18B20

The DS18B20 is a 1-Wire temperature sensor manufactured by Maxim. The sensor can operate in 9, 10, 11 or 12 bit precision and has a range of -55°C to 125 °C.

Each sensor has a 64-bit unique identifier built in. This allows multiple sensors to be connected to the same 1-Wire bus. So for instance, a project could measure internal and external temperature using a single GPIO pin.

Code Example

/*
Ds18B20 ds18B20;

public override Task Initialize()
{
Console.WriteLine("Initialize...");

ds18B20 = new ds18B20(Device.CreateI2cBus());

var consumer = ds18B20.CreateObserver(
handler: result =>
{
Console.WriteLine($"Temperature New Value { result.New.Celsius}C");
Console.WriteLine($"Temperature Old Value { result.Old?.Celsius}C");
},
filter: null
);
ds18B20.Subscribe(consumer);

ds18B20.TemperatureUpdated += (object sender, IChangeResult<Meadow.Units.Temperature> e) =>
{
Console.WriteLine($"Temperature Updated: {e.New.Celsius:n2}C");
};
return Task.CompletedTask;
}

public override async Task Run()
{
var temp = await ds18B20.Read();
Console.WriteLine($"Temperature New Value {temp.Celsius}C");

ds18B20.StartUpdating();
}*/

Sample project(s) available on GitHub

Wiring Example