How to Build a BeagleBone Black Temperature Sensor
Overview
Is it hot in here?
This simple temperature measurement project gets you started with a low cost sensor. A thermistor is a resistor that changes its value based on temperature. These sensors are commonly used in rechargeable battery packs and are very accurate. Temperature range for the sensor is from 50C to 110C. You can record, display, graph and control a variety of heat or cold related devices, starting with weather, fish tank, egg incubator and of course a dog house heater!
The thermistor has a nonlinear response, so math is used to obtained the correct reading. This can be a challenging part of using this sensor. This project is a stepbystep guide with the source code provided. How cool is that?
What You Will Need
 BeagleBone Black
 BeagleBone expandable case Orange or Black (recommended)
 AC adapter 5 Volts, 2 Amp (optional)
 Medium Breadboard and Jumper Wire Pack for Breadboards or Proto Cape
 A 10 Kilohms resistor (Brown, Black, Orange, Gold)
 A Semitec 103AT2 Thermistor (sensor)
Instructions
Step 1
Wire the circuit as shown in the diagram. (Or make a permanent version with a proto cape.)
Operation
The sensor circuit is a simple voltage divider. A reference voltage of 1.8V (P932) is applied to the thermistor. This voltage is split proportionately between the sensor and a 10K resistor connected to ground (P934). The mid point will vary based on temperature, and is measured using the BeagleBone analog input. Increasing temperature reduces the resistance of the sensor. This results in a greater voltage at the input (P936).
Step 2
Project Software Program
Program Listing
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

// Logic Supply Inc // Workshop and Tutorials visit inspire.logicsupply.com // Temperature Sensor Demo Program for the BeagleBone Black ARM Cortex A8 // Author : Richard StPierre // Sensor Type : Semitec 103AT2 // Version : 0.0 May 22, 2014 Initial creation // // var b = require( 'bonescript' ); var adcPin = "P9_36" ; // AIN5 max 1.8V //var adcPin = "P9_39"; //AIN0 //var adcPin = "P9_40"; //AIN1 //var adcPin = "P9_37"; //AIN2 //var adcPin = "P9_38"; //AIN3 //var adcPin = "P9_33"; //AIN4 //var adcPin = "P9_36"; //AIN5 //var adcPin = "P9_35"; //AIN6 var adcValue = 0.00; // Analog input (0100) var r_bias = 10000; // Bias resistor (to GND) var r_therm = 0; // Calculated thermistor resistance (to Vref) var t_c = 0; // Temperature (Celsius) var t_f = 0; // Temperature (Fahrenheit) var r_alpha = 0.09919; // Ro * e^(B/To) in K, To= 298K var c2kelvin = 273.15; // Celsius to Kelvin offset var Bvalue = 3435; // from thermistor datasheet loop(); function loop(){ //adcValue = Math.round(b.analogRead(adcPin)* 100); // scale from 0100% adcValue = b.analogRead(adcPin); r_therm = Math.round(((1/adcValue)1)*r_bias); t_c = Math.round(10*((Bvalue/(Math.log(r_therm/r_alpha)))c2kelvin))/10; t_f = (t_c * 9/5) +32; console.log( 'ADC = %d, resistance = %d, tempC = %d, tempF = %d' ,adcValue,r_therm,t_c, t_f); setTimeout(loop, 500); } 
Program Overview
First we request to use the bonescript library. Second we declare the pin we want to use AIN5 (P9_36).
Next we declare some variables we will need to calculate the temperature.
“Ralpha” is calculated using a reference data point for the thermistor (from the datasheet).
“B” is the material constant for the thermistor (from datasheet).
“Ro” is the resistance of the thermistor (in ohms) at temperature To.
“To” is the temperature which corresponds to the value of Ro (typically 25C).
25C equals 298 degrees Kelvin.
The equation uses the exponential function (e^x) with the natural base “e”.
As part of the measurement, we need to convert the voltage we read on the analog pin AIN5 to a resistance value. Inside the function loop(), we first read the voltage on AIN5. From this voltage reading we can now calculate the corresponding resistance value. To do this, we take the voltage across the bias resistor (10 kilohms) and derive the current flowing in this resistor (I = V/R). Knowing the current flowing in the circuit, we can calculate the resistance of the thermistor (R=V/I). Where V = Vref – Vmeasured, the voltage present across the thermistor. Finally we can calculate the temperature from the resistance value of the thermistor.
Note: Math.log() computes the natural logarithm and all temperature values are in Kelvin (Kelvin = C + 273.15). We use the Math.round() to manage the number of digits being displayed. The result from the equation is in Kelvin, so we subtract 273.15 to obtain a Celsius value. To make everyone happy, a conversion to Fahrenheit. Finally we display all our results to the console.
The program will call loop continuously.