Beer IoT: Measuring temperature with Windows 10 IoT Core and Raspberry Pi

I have RaspberryPi 2 with Windows 10 IoT Core and I plan to use it for some brewing activities. In this blog post I introduce you how to measure temperature with RaspberryPi using DS18B20 thermal sensors. This post is also example about how easy it is to get started with your IoT stuff using Microsoft tooling.

In practice I use this solution to monitor the freezing of eisbock beer. Making 20l of beer freeze takes time. Depending on weather outside it’s 10-18 hours. Using this solution I don’t have to open the bucket after every couple of hours to see if ice is coming and also I can estimate how long it takes for beer to freeze.

Update. Source code of my TemperatureStation solution is available at Github. The solution contains IoT background service and web application you can use right away. Readings are reported to MSSQL or Azure IoT Hub. Documentation is available at TemperatureStation wiki. Feel free to try out the solution.


I don’t stop here on deep details of my solution. It’s pretty easy if you know at least something about electronics. For electronics part I used blog post Thermal sensor connected via I2C by Tomáš Greňo. It describes all stuff in great detail and if you are using Linux on RaspberryPi then you can find there everything you need to read temperatures.

RaspberryPi 2 and two thermal sensors solution to control freezing of beer.
RaspberryPi 2 and two thermal sensors solution to control freezing of beer.
Solution is also ready for my conference trips and it survives travelling.

Some advice:

  1. All components used are cheap and I found these from local online electronic stores.
  2. DS2482S-100 and MS-DIP to SO-8 reduction are so small components that you better use right tools for such a small electronics or ask help from a friend who has tools and who knows how to use these.
  3. If you plan to connect more sensors to DS2482S-100 make sure the DS2482S-100 chip you buy supports the number of sensors you have.
  4. Colors of DS18B20 wires are described in component documentation.
  5. When connecting your solution to Raspberry make sure you connect wires to GPIO pins correctly.
  6. If possible then pack your sensor well so there’s not much chance you accidentally break it.

From this point on I assume you have your sensors solution done and connected to RaspberryPi. Also I assume you have development box running on Windows 10 and you have also Visual Studio with Universal Windows Applications and Windows 10 IoT templates installed.

Reading temperatures

Run Visual Studio and create new IoT background application project.

Visual Studio 2015: Create new Windows IoT Core application

When project is created open NuGet package manager and add Rinsen.OneWire package to your solution. Rinsen.OneWire is implementation of OneWire protocol by Fredrik Rinsén. It’s written in C# and it has built-in support for DS18B20 and DS18S20 sensors.

Now let’s write some code. In short we have to write something like this:

  1. When background application is run then initialize everything to read sensors.
  2. Add code for application shutdown so we leave application the polite way.
  3. Use timer to read values from sensors.
  4. Write values somewhere (debug window in our case).

Here’s the sample code for StartupTask class that Visual Studio creates automatically.

public sealed class StartupTask : IBackgroundTask
    private Timer _timer;
    private OneWireDeviceHandler _handler;
    private IEnumerable<DS18B20> _devices;
    private bool _isClosing = false;
    public void Run(IBackgroundTaskInstance taskInstance)
        taskInstance.Canceled += TaskInstance_Canceled;
        _handler = new OneWireDeviceHandler(false, false);
        _devices = _handler.OneWireDevices.GetDevices<DS18B20>();
        _timer = new Timer(TemperatureCallback, null, 0, 5000);
        while (!_isClosing)
    private void TemperatureCallback(object state)
        var now = DateTime.Now;
        foreach (var device in _devices)
            var result = device.GetTemperature();
            Debug.WriteLine(now + " " + device.OneWireAddressString + 
": " + result);
    private void TaskInstance_Canceled(IBackgroundTaskInstance sender, 
BackgroundTaskCancellationReason reason)
        _isClosing = true;
        if (_timer != null)
            _timer = null;
        if (_handler != null)
            _handler = null;

Build it, deploy it to RaspberryPi and run on Visual Studio. You should see output like this:

Temperature readings from sensors

If you get the following error:

Exception thrown: 'System.IO.FileNotFoundException' in Rinsen.IoT.OneWire.dll
WinRT information: Slave address was not acknowledged.

then try to play with ad0 and ad1 arguments of OneWireDeviceHandler class. By default these boolean arguments are true. I had to set these to false to make my solution work.

Wrapping up

Windows 10 IoT Core and Visual Studio tooling make it very easy to build IoT solutions. Of course, we don’t away from problems so easy like we did right now as there are no libraries for everything we want to do but still we have very good tooling that makes development way easier. Although we wrote temperature readings to debug window we can go further and send the values to some database or Microsoft Azure service.

See also

7 thoughts on “Beer IoT: Measuring temperature with Windows 10 IoT Core and Raspberry Pi

  • Boris says:

    Nice project ! Kinda exactly what I’m trying to achieve.
    Could you please provide the full diagram of your installation ?
    I don’t understand how to wire the 2 temperature sensors.

    Thank you!

  • Boris says:

    Nevermind, I did stop reading Tomáš Greňo’s article at the Linux part.

  • Gunnar says:

    Tomáš Greňo’s article provides all technical details. If you are like me and don’t know much about electronics then any of your friends with more knowledge about electronics can help you when looking at Tomáš Greňo’s article.

  • Boris says:

    Thanks Gunnar, I have everything to start working… except this PCB adapter I just ordered of Ebay.
    I tried to glue it to pin extension, but I only lost 2 hours trying…
    In the mean time, I have time to work on the software part 🙂

  • Richie Rogers says:

    How many temperature sensors will this support?
    I’m looking for some way of handling 6-8 temperature sensors.


  • Gunnar says:

    32 or 64 sensors are supported. Can’t remember the correct number. For your case the same solution should work fine.

  • Richie Rogers says:

    That’s just enough for my requirements then 😀

Leave a Reply

Your email address will not be published. Required fields are marked *