Knowledge Base

The AB Electronics UK Knowledge Base provides support solutions, tutorials and troubleshooting guides.

Knowledge Base

ADC Differential Pi with NTC Thermistors

Using an ADC Differential Pi with NTC Thermistors

This tutorial will use the ADC Differential Pi or DeltaSigma Pi with a Semitec103AT-11 NTC (Negative Temperature Coefficient) Thermistors 10kohm 1% to make a digital thermometer. You will need your Raspberry Pi, an ADC Differential Pi or DeltaSigma Pi, and a Semitec103AT-11 NTC.

We will use the AB Electronics Python library to talk to the ADC Differential Pi. To download the library, visit our Python Library and Demos knowledge base article.

You must enable I2C on your Raspberry Pi; see our other tutorial on i2c: I2C Part 2: Using I2C on the Raspberry Pi.

 

Parts Used:

ADC Differential Pi

Semitec103AT-11 NTC (Datasheet)

3 x 10K Resistor

Connecting Wire

Connecting the sensor and resistors to the ADC Differential Pi Plus

This circuit uses a "Wheatstone bridge" to return a voltage dependent on the temperature sensor's resistance. Using this, we can then calculate the resistance and then the temperature.

On a breadboard, add the 3 x 10K resistors and the temperature sensor as shown on the circuit mock-up image (you can click to enlarge)

Connect the positive breadboard rail to 3.3V on the GPIO header.

Connect the GND breadboard rail to GND on the GPIO header.

Connect the ADC + input from the breadboard to the + channel on input 1 on the Differential Pi board.

Connect the ADC - input from the breadboard to the - channel on input 1 on the Differential Pi board.

We will create a new Python program file for this tutorial called demo-demo-resistance-thermometer.py. You can use your favourite text editor to write the program. You can find a complete example of demo_resistance_thermometer.py in the ABElectronics_Python_Libraries/ADCDifferentialPi/demos/ folder.

At the top of your program, you must import the ADCDifferentialPi library and time library. We also add variables to hold the values related to the sensor data conversion.

#!/usr/bin/env python
from ADCDifferentialPi import ADCDifferentialPi
import time
import os
import math

The ADCDifferentialPi library is used for all communication with your ADC Differential Pi Plus; it gives you control over almost everything that can be done with the MCP3424 controller.

Next, we need to create an instance of the ADCDifferentialPi class and call it adc

adc = ADCDifferentialPi(0x68, 0x69, 18)

0x68 and 0x69 are the I2C address for the ADC chips. If you have changed the address selection jumpers on your ADC Differential Pi Plus, you must change these numbers to match the new addresses.

Now we add variables which will be used to hold the default values of the resistors and thermometer values from the datasheet.

# the resistor values for the Wheatstone bridge are:
resistor1 = 10000
resistor2 = 10000
resistor3 = 10000
# Input voltage
voltin = 3.3
# Resistance thermometer values from datasheet
bResistance = 3435
t25Resistance = 10000
# Constants
t0 = 273.15;
t25 = t0 + 25;

We need to create a new function to convert the voltage returned into the resistance using the following:

def calcResistance(voltage):
    return (resistor2*resistor3 + resistor3* (resistor1+resistor2)*voltage / voltin )/ (resistor1- (resistor1+resistor2)*voltage / voltin)

We need to create a new function to convert the resistance into the temperature:

def calcTemp(resistance):
    return 1 / ( (math.log(resistance / t25Resistance) / bResistance) + (1 / t25) ) - t0;

We need to loop the same commands over and over. This can be done with a simple while loop.

while True:

As True is always true, the while loop will continue until you exit the program with a Ctrl-C.

Now we read the voltage from the ADC channel and convert it to the values needed:

# read from adc channels and print to screen
bridgeVoltage =  adc.read_voltage(1)
thermresistance = calcResistance(bridgeVoltage)
temperature = calcTemp(thermresistance)

We must issue a clear command to clear the console for each read.

# clear the console
os.system('clear')

Next, we print the values to the screen.

# print values to screen
print("Bridge Voltage: %02f volts" % bridgeVoltage)
print("Resistance: %d ohms" % thermresistance)
print("Temperature: %.2fC" % temperature)

Using the time.sleep method, we add a 0.5 second delay before repeating the read.

time.sleep(0.5)

time.sleep takes one variable, a number representing the number of seconds to wait. 1 will make the program sleep for 1 second while 0.1 would wait for 100ms.

That is everything we need to make read from the Thermistor sensor using your ADC Differential Pi or Delta Sigma Pi; your program should now look like this.

#!/usr/bin/env python
from ADCDifferentialPi import ADCDifferentialPi
import time
import os
import math

"""
================================================
ABElectronics ADC Differential Pi 8-Channel ADC read Resistance thermometer 
using a Wheatstone bridge.
This demo uses a Semitec NTC (Negative Temperature Coefficient) Thermistors
10kohm 1%, Manufacturer Part No: 103AT-11
Purchased from Mouser Electronics, Part No: 954-103AT-11
The circuit is connected to the + and - inputs on channel 7 on the 
ADC Differential Pi. This can also be used on the Delta Sigma Pi
The Wheatstone bridge is comprised of three 10K resistors and the 
Resistance thermometer
Version 1.0 Created 30/10/2015
Requires python3 smbus to be installed
run with: python3 demo_resistance_thermometer.py
================================================
Initialise the ADC device using the default addresses and 18 bit sample rate, 
change this value if you have changed the address selection jumpers
Bit rate can be 12,14, 16 or 18
"""

adc = ADCDifferentialPi(0x68, 0x69, 18)

# the resistor values for the Wheatstone bridge are:
resistor1 = 10000
resistor2 = 10000
resistor3 = 10000

# Input voltage
voltin = 3.3

# Resistance thermometer values from datasheet
bResistance = 3435
t25Resistance = 10000

# Constants
t0 = 273.15;
t25 = t0 + 25;

def calcResistance(voltage):
    return (resistor2*resistor3 + resistor3* (resistor1+resistor2)*voltage / voltin )/ (resistor1- (resistor1+resistor2)*voltage / voltin)

def calcTemp(resistance):
    return 1 / ( (math.log(resistance / t25Resistance) / bResistance) + (1 / t25) ) - t0;

# loop forever reading the values and printing them to screen
while (True):
    # read from adc channels and print to screen
    bridgeVoltage =  adc.read_voltage(1)
    thermresistance = calcResistance(bridgeVoltage)
    temperature = calcTemp(thermresistance)

    # clear the console
    os.system('clear')

    # print values to screen
    print("Bridge Voltage: %02f volts" % bridgeVoltage)
    print("Resistance: %d ohms" % thermresistance)
    print("Temperature: %.2fC" % temperature)

    # wait 0.5 seconds before reading the pins again
    time.sleep(0.5)

Save your program as "demo_resistance_thermometer.py" and run it in a command terminal using the following.

python3 demo_resistance_thermometer.py

You will now have a reading from your sensor on the console, which will repeat every 0.5 seconds.


(images created with Fritzing)


Was this article helpful? Yes No

Please tell us how we can improve this article:

Submit
Created 30/10/2015 | Last Updated: 04/07/2024

Related Expansion Boards

Order a ADC Differential Pi Photo of ADC Differential Pi
ADC Differential Pi

8 Channel 18-bit Differential Analogue to Digital converter for the Raspberry Pi

£17.99 Ex VAT: £14.99

Related Articles

ADC Differential Pi with ADXL335 Accelerometer
ADC Differential Pi with ADXL335 Accelerometer from Analog Devices
ADC Differential Pi with NTC Thermistors
Using an ADC Differential Pi with NTC Thermistors
ADC Differential Pi with Raspberry Pi Pico
Using the ADC Differential Pi with Raspberry Pi Pico and MicroPython