How to Measuring Temperature in Thermistor with Raspberry Pi
You want to measure temperature using a thermistor. Today I show you How to Measuring Temperature in Thermistor with Raspberry Pi step by step complete process
≡ Components Required :
6. Resistors
7. Thermistor
This book will help you to gain more knowledge of Raspberry pi Software and Hardware Problems and Solutions
Raspberry Pi Cookbook
≡ Circuit diagram Thermistor with Raspberry Pi:
A thermistor could be a resistor whose resistance shifts with temperature. Utilize the step reaction method to measure the resistance of the thermistor and after that calculate the temperature.
once you get your thermistor, make beyond any doubt simply know its values of Beta and R0 (resistance at 25C) which it could be a Negative Temperature Coefficient (NTC) device.
Calculating the temperature from the resistance of the thermistor requires some reasonably bushy math utilizing logarithms called the Steinhart-Hart equation. This equation has to know two things about the thermistor: its resistance at 25 degrees C (called T0 or sometimes T25) and a constant for the thermistor called Beta, or sometimes just B. If you employ a different thermistor, you'll got to plug these values into the factors B and R0 at the top of the program. Note that a capacitor typically only has an accuracy of 10%, and thermistors are similarly wrong in their value of R0, so to induce valuable readings from the thermistor, you may got to change the factors C and R0.
≡ Code Thermistor with Raspberry Pi :
Open an editor (nano or IDLE) and paste in the following code
import RPi.GPIO as GPIO import time, math C = 0.36 # uF R1 = 1000 # Ohms B = 3800.0 # The thermistor constant R0 = 1100.0 # The resistance of the thermistor at 25C GPIO.setmode(GPIO.BCM) # Pin a charges the capacitor through a fixed 1k resistor # and the thermistor in series # Pin b discharges the capacitor through a fixed 1k resistor a_pin = 18 b_pin = 23 # Discharge the capacitor, leaving it ready to start filling up def discharge(): GPIO.setup(a_pin, GPIO.IN) GPIO.setup(b_pin, GPIO.OUT) GPIO.output(b_pin, False) time.sleep(0.1) # Return the time taken (uS) for C to charge # which is 1.65V or higher def charge_time(): GPIO.setup(b_pin, GPIO.IN) GPIO.setup(a_pin, GPIO.OUT) GPIO.output(a_pin, True) t1 = time.time() while not GPIO.input(b_pin): pass t2 = time.time() return (t2 - t1) * 1000000 # Take an analog reading from charge time def analog_read(): discharge() t = charge_time() discharge() return t # Convert the time taken to charge the capacitor into a value of resistance # To reduce errors, do it 10 times and take the average. def read_resistance(): n = 10 total = 0; for i in range(1, n): total = total + analog_read() t = total / float(n) T = t * 0.632 * 3.3 r = (T / C) - R1 return r def read_temp_c(): R = read_resistance() t0 = 273.15 # 0 deg C in K t25 = t0 + 25.0 # 25 deg C in K # Steinhart-Hart equation - Google it inv_T = 1/t25 + 1/B * math.log(R/R0) T = (1/inv_T - t0) return T try: while True: print(read_temp_c()) time.sleep(0.5) finally: GPIO.cleanup()
When you run the program, you will see a series of temperature measurements in degrees C. To convert to degrees F, use the formula Tf =
Tc * 9 / 5 + 32.
35.5040458984
36.7302664759
If you want to know more about raspberry pi then click on the link below
No comments