Measuring Temperature with an ADC in Raspberry pi
You need to measure temperature using a TMP36 - Temperature Sensor and an analog-to-digital converter. Today I show you how to Measuring Temperature with an ADC in Raspberry pi Use an MCP3008 ADC chip. unless you would like more than one analog channel, you should consider utilizing the DS18B20 digital temperature sensor, which is more accurate and doesn’t require a separate ADC chip.
≡ What is TMP36 - Temperature Sensor
These sensors utilize a solid-state strategy to decide the temperature. That's to say, they do not utilize mercury, bimetallic strips, nor do they utilize thermistors. Instead, they utilize the truth as temperature increases, the voltage over a diode increases at a known rate. By accurately increasing the voltage change, it is simple to create an analog signal that's directly proportional to temperature. There have been a few improvements on the strategy but, basically, that's how temperature is measured. The great news is all that complex calculation is done inside the chip - it fair spits out the temperature, ready for you to utilize!
Since these sensors have no moving parts, they are exact, never wear out, do not require calibration, work under many natural conditions, and are consistent between sensors and readings. In addition, they are exceptionally cheap and very simple to utilize.
More about this https://learn.adafruit.com/tmp36-temperature-sensor
≡ Components Required
For this project, we suggest that you simply have the following parts.
6. Resistors
7.MCP3008
8.TMP36 - Temperature Sensor
This book will help you to gain more knowledge of Raspberry pi Software and Hardware Problems and Solutions
Raspberry Pi Cookbook
≡ Circuit diagram Temperature ADC Raspberry pi:
Shows the arrangement of components on the breadboard , You will need to set up SPI on your Raspberry Pi, so if you haven’t already
done so, follow Setting Up SPI on your Raspberry pi
MCP3008 chip | Raspberry Pi |
VDD | 3.3V |
VREF | 3.3V |
AGND | GND |
CLK | SCLK |
DOUT | MISO |
DIN | MOSI |
CS | GPIO Pin 22 |
≡ Code Temperature ADC Raspberry pi:
Open an editor (nano or IDLE) and paste in the following code
import spidev, time spi = spidev.SpiDev() spi.open(0,0) def analog_read(channel): r = spi.xfer2([1, (8 + channel) << 4, 0]) adc_out = ((r[1]&3) << 8) + r[2] return adc_out while True: reading = analog_read(0) voltage = reading * 3.3 / 1024 temp_c = voltage * 100 - 50 temp_f = temp_c * 9.0 / 5.0 + 32 print("Temp C=%f\t\tTemp f=%f" % (temp_c, temp_f)) time.sleep(1)
The program is based on that of Follow How to Interface MCP3008 with raspberry Pi . A little bit of additional math calculates the temperature in degrees Celsius and Fahrenheit:
Temp C=29.287109 Temp f=90.716797
Temp C=29.642578 Temp f=90.556641
The TMP36 outputs a voltage that's proportional to the temperature. According to the datasheet for the TMP36, the temperature in degrees C is calculated as the voltage (in volts) times 100 minus 50. The TMP36 is fine for measuring the inexact temperature but is specified as having a precision of as it were 2 degrees C. This will as it got worse on the off chance that you connect long leads to it. To some extent, you'll be able to calibrate an individual device, but for better exactness, utilize a DS18B20 (Formula 13.11), which incorporates an expressed precision of 0.5% over a temperature run of -10 to +85 degrees C. Being an advanced gadget, it ought to not suffer any loss of accuracy when joined to long leads.
If you want to know more about raspberry pi then click on the link below
No comments