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!

temperature_tmp36pinout

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.

1.Raspberry pi

2.Breadboard

3. Connecting wire

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

Using a TMP36 with an ADC Using a TMP36 with an ADC

VDD (power) and DGND (digital ground) to power the MCP3008 chip. We moreover require four “SPI” data pins: DOUT (Data Out from MCP3008), CLK (Clock stick), Din (Information In from Raspberry Pi), and /CS (Chip Select). At long last of course, a source of analog data. We’ll be utilizing the fundamental 10k trim pot.
 
The MCP3008 has a few more pins we got to interface: AGND (analog ground, utilized now and then in precision circuitry, which typically not) interfaces to GND, and VREF (analog voltage reference, utilized for changing the “scale” – we want the total scale, so tie it to 3.3V). Below could be a wiring chartInterface the 3.3V cobbler pin to the left + rail and the GND pin to the correct – rail. Interface the taking after pins for the MCP chip
MCP3008 chipRaspberry Pi
VDD3.3V
VREF3.3V
AGNDGND
CLKSCLK
DOUTMISO
DINMOSI
 CSGPIO Pin 22
 
Next, connect up theTMP36 - Temperature Sensor.
    1 (left) goes to 3.3v
    2 (middle) connects to MCP3008 CH0 (analog input #0)
    3 (right) connects to GND

≡ 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 exactnessutilize 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

RASPBERRY PI TUTORIALS FOR BEGINNERS

No comments

Theme images by Dizzo. Powered by Blogger.