Taking the temperature

FLOSS ,Open Hardware ,Weather Station
August 3, 2018

We want to be able to record the temperature of the outside air for our weather station.

We can do this using a Thermistor.  This is a resistor that changes resistance relative to its temperature.  Unfortunately we are unable to measure resistance directly, we can however measure a voltage.

Consider the circuit below:

____ Vcc
|
#
#   R1
#
|
+—– Vadc
|
#
#   R2 (Thermistor)
#
|
__|__ 0V

(Action replace with png just as soon as I can fix word press config)
If R2 is our thermistor then we do not know what it’s current resistance is, but if we apply a known voltage at Vcc, and have a fixed resistor (R1) then when we measure Vadc then we have all the parameters required to work out the resistance of the thermistor (which we can then use to determine the temperature)

Ohms law tells us that R = V / I so if we know Vadc (the voltage across R2) and we know I then we can derive the value of R2.

Right now we do not know the value of I, but given that R2 is in series with R1, we know that the current through R2 will be the same as that through R1.  ok so we don’t know what the value for I in R1 is either, but we can derive that!

I = VR1 / R1

Where VR1 = Vcc – Vadc

So I = (Vcc – Vadc) / R1

which in turn enables us to derive R2:

R2 = Vadc / I

R2 = Vadc / [ (Vcc – Vadc) / I ]

 

Given a little scaling work to ensure that the ADC input voltage is within safe ranges, we can now determine the resistance of our thermistor and from that (and the data-sheet for the thermistor) derive the current temperature…

Unfortunately by this stage Alys’ eyes had glased over and she had lost all interest in determining how we might measure Temperature.

Time for a different approach…

What if we were to use a device that has done all that tedious maths for us already, and not only that has converted into Si units (in this case the offset unit degree centigrade)?  Enter the Dallas / Maxim 1-Wire DS18B20.

This is a simple three pin device that measures Temperatures from -55°C to +125°C (with ±0.5°C Accuracy from -10°C to +85°C).   Better yet there is already Arduino Library support meaning that we needed only to download the libraries and knock up a very quick and simple sketch to get the first part of our project working.

Hardware:

We are using an Arduino Uno with a breadboard cape for the development.  We simply connected the DS18B20 as shown below:

(Stolen image – replace with our own schematic ASAP)

Finally we connected a FTDI USB/TTL-Serial adapter to the Arduino (Pin 0 and Pin 1) so that we can send the temperature data to a serial console for now (minicom running on my laptop)

(Insert photo here)

Software setup

  • Arduino IDE and programming environment
    apt-get install arduino
  • Ensure user is in the dialout group for permissions to talk to /dev/ttyAM0 which is what the Arduino presents it self as (at least on our hardware)

Libraries:

Application:

Our Arduino sketch is simplicity itself

/********************************************************************/
// First we include the libraries
#include <OneWire.h> 
#include <DallasTemperature.h>
/********************************************************************/
// Data wire is plugged into pin 2 on the Arduino 
#define ONE_WIRE_BUS 2 
/********************************************************************/
// Setup a oneWire instance to communicate with any OneWire devices  
// (not just Maxim/Dallas temperature ICs) 
OneWire oneWire(ONE_WIRE_BUS); 
/********************************************************************/
// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);
/********************************************************************/ 
void setup(void) 
{ 
 // start serial port 
 Serial.begin(9600); 
 Serial.println("Dallas Temperature IC Control Library Demo"); 
 // Start up the library 
 sensors.begin(); 
} 
void loop(void) 
{ 
 Serial.print("Requesting temperatures..."); 
 sensors.requestTemperatures(); // Send the command to get temperature readings (from all 1-wire temperature devices)
 Serial.println("DONE"); 

 Serial.print("      Temperature is: "); 
 Serial.println(sensors.getTempCByIndex(0)); // Why "byIndex"?  
   // You can have more than one DS18B20 on the same bus.  
   // 0 refers to the first IC on the wire 
   delay(1000); 
} 

 

Output:

Requesting temperatures...DONE
            Temperature is: 29.50 
Requesting temperatures...DONE
            Temperature is: 29.50

It is somewhat warm here!  We validated the sensor using a bag of iced water, and also by heating the sensor.  Everything looked good.  We should perhaps ensure calibration using known temperatures and a known thermometer – but for now this is enough…