As I work within the science realm, I often have a need to monitor environmental conditions. Whilst some of this is conducted on-site, there is also the need to monitor the temperatures of equipment within the laboratory which includes things like Fridges, Freezers, Incubators, and room temperatures.  Whilst there are a number of commercial packages that exist, I have found that the cost of these solutions is fairly significant when there are a number of open-source options that work as well (if not better) at a much lower cost.  Note this is just one way of doing this, but it is certainly not the only way.

In order to monitor temperature, I needed a device that could interrogate temperature sensors, and then post the information from those sensors to a web service, before we get into the code let's look at some of the options.

Temperature Sensors

There are a significant number of different temperature sensors, but at their heart, they are based on a number of different technologies:

  • Thermistors (a temperature dependant resistor, they are able to measure typically – 40°C to 100°C ), these are cost-effective and accurate however, they cannot be daisy-chained.
  • DHT / AHT (a combination of a thermistor and a capacitive humidity sensor capable of measuring -40°C – 80°C ), are fairly cheap and have mixed accuracy (depending on the device) however, they cannot be daisy-chained.
  • 1-wire (i.e. DS18B20) (a digital thermometer capable of measuring between -55°C – 125°C ), these are more expensive than the other devices and have a 0.5°C  accuracy however, they can be daisy-chained across a long cable (i.e. almost like a network)

Whilst each of these options would have worked given the temperature ranges, I settled for the 1-wire option as this allowed me to run a single category 5 twisted pair cable around the building to which the temperature sensors were attached (in parallel), and the cable was then connected into the microcontroller. These sensors send a digital signal through the cable which includes the sensor's unique ID (essentially a serial number) in addition to the temperature value.


There are a number of different microcontrollers that could be used for this project, in my case I used an Arduino Uni with an Ethernet Shield as much because it was what I had, there is a fantastic community around the device, there are countless open source examples, if I was to buy the stuff again I would either buy an Arduino clone with an ethernet shield integrated or consider a wifi Arduino device similar to the ESP32.

The specific requirements of the Microcontroller are fairly simple, it needs to be capable of supplying 3.3V of power through the twisted pair cable (to power the 1-wire sensors), and a single pullup resistor needs to be connected between the data line of the cable and the power line (+). In addition, there needs to be a way for the device to output the information from the sensor to a web platform (usually using an ethernet, WIFI or cellular shield).

It is worth noting that as the 1-wire temperature sensors had their own unique serial numbers, and to poll the device and get the right sensor I had to know the serial number, this project required me to run a small sketch on the microcontroller to determine the serial number of each of the 1-wire devices, then once I knew that I could hard code it into the sketch for the ThingSpeak system.

Web Platform

The platform I settled on was a platform called ThingSpeak, I settled on this platform as there are lots of examples available for Arduino microcontrollers on how to interface to a number of different devices, and subsequently how the information is obtained from these devices can be sent to the web service which collects the information, and subsequently graphs it and lets you take actions based on a specific set of criteria.

Thingspeak ( has an API that allows you to update values using HTTP Post requests, with JSON et al but in my mind, the easiest way was to use an HTTP GET request, this allows you to essentially make a GET request to the server similar to the below, and it will update the fields for the API Key that relates to the Channel you are trying to update.

The above example meant that I could poll all of the 1-wire temperature sensors, store their values in variables then essentially do an HTTP GET request where I filled out the field1 – field8 values (i.e. field1=25.3&field2=13.2) and it would update on ThingSpeak automatically. The biggest downside to this was that I needed to find out the sensor's unique serial number, as the same sensor needed to go to the same field (i.e. Sensor 1 had to go to Field 1).


If I was doing this project again, I think I would consider using a different platform than ThingSpeak, and I would likely use something like a Raspberry Pi rather than an Arduino (unless I specifically wanted to use a web service), the idea behind using the Raspberry pi is that it could directly poll the twisted pair cable (potentially with an adapter) and then the Raspberry Pi could run its own database platform (i.e. InfluxDB) in addition to its own graphing platform (i.e. Grafana), this would reduce reliance on external services, but more importantly, it would get around some restrictions of ThingSpeak.

When you post values to Thingspeak, you can only post up to 8 values in a format like field1=x, field2=x up to field8, this means if you mix up the sensors it does not know they are mixed up and gets posted to the wrong device, furthermore there is the limit of 8 devices. By using something like InfluxDB the code could be changed so that it polls the twisted pair, grabs each of the sensor ID's in addition to the temperature values and stores them in the database, this would mean that the sensors don't need to be hard codes and it would be much easier to add new sensors as needed, or change out sensors without having to modify the sketch.

Useful Links

This post gives you an idea of the concept, but because this is based on open-source principles there are a lot of articles that provide useful guidance on how something like this can be set up, or at least to point you in the right direction on the concept, and then you can modify the code to suit.


Prev GL.iNet GL-AR750S-Ext Gigabit Travel Router
Next Top 10 Photography Blogs to Folow

Comments are closed.