概述
模擬溫度傳感器非常容易解釋?zhuān)男酒梢愿嬖V您環(huán)境溫度!
這些傳感器使用固態(tài)技術(shù)來(lái)確定氣溫。也就是說(shuō),它們不使用汞(例如舊溫度計(jì)),雙金屬條(例如在某些家用溫度計(jì)或火爐中),也不使用熱敏電阻(對(duì)溫度敏感的電阻器)。取而代之的是,他們利用溫度升高的事實(shí),二極管兩端的電壓以已知的速率增加。 (從技術(shù)上講,這實(shí)際上是晶體管的基極和發(fā)射極之間的電壓降-Vbe。)通過(guò)精確地放大電壓變化,很容易生成與溫度成正比的模擬信號(hào)。該技術(shù)已有一些改進(jìn),但本質(zhì)上是如何測(cè)量溫度。
好消息是,所有復(fù)雜的計(jì)算都在內(nèi)部進(jìn)行 芯片-它只是吐出溫度,供您使用!
因?yàn)檫@些傳感器沒(méi)有活動(dòng)部件,所以它們精確,永不磨損,不需要校準(zhǔn),在許多環(huán)境條件下工作且在傳感器之間保持一致和閱讀。此外,它們非常便宜并且易于使用。
一些基本統(tǒng)計(jì)數(shù)據(jù)
這些統(tǒng)計(jì)數(shù)據(jù)適用于Adafruit商店中的溫度傳感器,即TMP36(-40至150C)。它與LM35/TMP35(攝氏輸出)和LM34/TMP34(華氏輸出)非常相似。我們使用‘36而不是’35或‘34的原因是該傳感器具有非常寬的范圍,并且不需要負(fù)電壓即可讀取低于零的溫度。否則,功能基本相同。
尺寸: TO-92封裝(約0.2“ x 0.2” x 0.2“),帶有三根引線(xiàn)
價(jià)格:在Adafruit商店中為1.50美元
溫度范圍::-40°C至150°C/-40°F至302° F
輸出范圍: 0.1V(-40°C)至2.0V(150°C),但在125°C之后精度會(huì)降低
數(shù)據(jù)表
如何測(cè)量溫度
使用TMP36很簡(jiǎn)單,只需連接左引腳接電源(2.7-5.5V),右引腳接地,然后中間引腳將具有與溫度成正比(線(xiàn)性)的模擬電壓,該模擬電壓與電源無(wú)關(guān)。

要轉(zhuǎn)換電壓電壓只需使用以下基本公式即可:
以°C為單位的溫度= [(以VV為單位的Vout)-500 ] /10
因此,例如,如果輸出電壓為1V,則表示溫度為((1000 mV-500)/10)= 50°C
如果使用LM35或類(lèi)似產(chǎn)品,在上圖中使用“ a”行和公式:以°C為單位的溫度=(以mV為單位的Vout) /10
多個(gè)傳感器可能遇到的問(wèn)題:如果,添加更多傳感器時(shí),您會(huì)發(fā)現(xiàn)溫度不一致,這表明在將模擬讀取電路從一個(gè)引腳切換到另一個(gè)引腳時(shí),傳感器會(huì)相互干擾。您可以通過(guò)延遲閱讀兩次并扔掉第一個(gè)閱讀器來(lái)解決此問(wèn)題
有關(guān)更多信息,請(qǐng)參閱此帖子
測(cè)試溫度傳感器
測(cè)試這些傳感器非常容易,但是您需要電池組或電源。
連接2.7-5.5 V電源(2-4節(jié)AA電池工作出色),以便將接地線(xiàn)連接到第3針(右引腳),并且將電源連接到第1針(左引腳)
然后用直流電壓連接萬(wàn)用表模式接地,其余引腳2(中間)。如果您擁有TMP36及其大約室溫(25°C),則電壓應(yīng)約為0.75V。請(qǐng)注意,如果您使用的是LM35,則電壓為0.25V
傳感器指示溫度為26.3°C,也稱(chēng)為79.3°F
您可以通過(guò)用手指按壓傳感器的塑料外殼來(lái)更改電壓范圍,您將看到溫度/電壓升高。
用我的手指在傳感器上加熱一點(diǎn),現(xiàn)在溫度讀數(shù)為29.7°C/85.5°F
或者您可以用冰塊觸摸傳感器,最好將其放在塑料袋中,以免電路上積水,并查看溫度/電壓降。
我將冰塊壓在傳感器上,以將溫度降至18.6°C/65.5°F
使用溫度傳感器
溫度傳感器。這些傳感器中幾乎沒(méi)有芯片,盡管它們不那么精密,但確實(shí)需要正確處理。處理靜電時(shí)要小心靜電,并確保電源正確連接并且在2.7至5.5V DC之間-因此,請(qǐng)勿嘗試使用9V電池!
它們帶有“ TO”字樣-92英寸封裝,這意味著芯片被封裝在具有三個(gè)支腳的塑料半圓柱體內(nèi)。支腳可以輕松彎曲,以將傳感器插入面包板。您也可以焊接到引腳以連接長(zhǎng)導(dǎo)線(xiàn)。如果您需要對(duì)傳感器進(jìn)行防水處理,則可以在下面看到有關(guān)如何制作出色保護(hù)套的說(shuō)明。
讀取模擬溫度數(shù)據(jù)與我們研究過(guò)的FSR或光電傳感器不同,TMP36和朋友并不像電阻器那樣工作。因此,實(shí)際上只有一種方法可以從傳感器讀取溫度值,即將輸出引腳直接插入模擬(ADC)輸入。

請(qǐng)記住,您可以使用2.7V至5.5V之間的任何電壓作為電源供應(yīng)。在此示例中,我顯示的是5V電源,但請(qǐng)注意,您可以輕松地將其與3.3v電源一起使用。無(wú)論您使用哪種電源,模擬電壓讀數(shù)的范圍都將在大約0V(地)到大約1.75V之間。
如果您使用的是5V Arduino,并將傳感器直接連接到模擬引腳,您可以使用以下公式將10位模擬讀數(shù)轉(zhuǎn)換為溫度:
引腳上的電壓,單位為毫伏=(從ADC讀取)*(5000/1024 )
此公式將ADC的數(shù)字0-1023轉(zhuǎn)換為0-5000mV(= 5V)
如果您使用的是3.3V Arduino,則需要使用
引腳上的電壓(單位為毫伏)=(從ADC讀取)*(3300/1024)
此公式將數(shù)字轉(zhuǎn)換為0- 1023從ADC轉(zhuǎn)換為0-3300mV(= 3.3V)
然后將毫伏轉(zhuǎn)換為溫度,請(qǐng)使用以下公式:
攝氏度溫度= [(模擬電壓mV)-500]/10
Arduino Sketch-簡(jiǎn)單溫度計(jì)
此示例代碼顯示了Arduino一種快速創(chuàng)建溫度傳感器的方法,它只需在串行端口上打印攝氏溫度和華氏溫度的當(dāng)前溫度即可。
下載:文件
復(fù)制代碼
//TMP36 Pin Variables
int sensorPin = 0; //the analog pin the TMP36’s Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures
/*
* setup() - this function runs once when you turn your Arduino on
* We initialize the serial connection with the computer
*/
void setup()
{
Serial.begin(9600); //Start the serial connection with the computer
//to view the result open the serial monitor
}
void loop() // run over and over again
{
//getting the voltage reading from the temperature sensor
int reading = analogRead(sensorPin);
// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 5.0;
voltage /= 1024.0;
// print out the voltage
Serial.print(voltage); Serial.println(“ volts”);
// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((voltage - 500mV) times 100)
Serial.print(temperatureC); Serial.println(“ degrees C”);
// now convert to Fahrenheit
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(temperatureF); Serial.println(“ degrees F”);
delay(1000); //waiting a second
} //TMP36 Pin Variables
int sensorPin = 0; //the analog pin the TMP36‘s Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures
/*
* setup() - this function runs once when you turn your Arduino on
* We initialize the serial connection with the computer
*/
void setup()
{
Serial.begin(9600); //Start the serial connection with the computer
//to view the result open the serial monitor
}
void loop() // run over and over again
{
//getting the voltage reading from the temperature sensor
int reading = analogRead(sensorPin);
// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 5.0;
voltage /= 1024.0;
// print out the voltage
Serial.print(voltage); Serial.println(“ volts”);
// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((voltage - 500mV) times 100)
Serial.print(temperatureC); Serial.println(“ degrees C”);
// now convert to Fahrenheit
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(temperatureF); Serial.println(“ degrees F”);
delay(1000); //waiting a second
}
獲得更高的精度為獲得更好的結(jié)果,使用3.3v參考電壓作為ARef而不是5V會(huì)更精確,并且少噪音
光照和溫度數(shù)據(jù)記錄教程中的此示例有一個(gè)光電管,但是您可以忽略它
請(qǐng)注意,我們已將TMP36更改為A1

要將3.3v引腳用作模擬參考,請(qǐng)不要忘記在設(shè)置中像代碼中那樣指定“ analogReference(EXTERNAL)”下方:
下載:文件
復(fù)制代碼
/* Sensor test sketch
for more information see http://www.ladyada.net/make/logshield/lighttemp.html
*/
#define aref_voltage 3.3 // we tie 3.3V to ARef and measure it with a multimeter!
//TMP36 Pin Variables
int tempPin = 1; //the analog pin the TMP36’s Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures
int tempReading; // the analog reading from the sensor
void setup(void) {
// We‘ll send debugging information via the Serial monitor
Serial.begin(9600);
// If you want to set the aref to something other than 5v
analogReference(EXTERNAL);
}
void loop(void) {
tempReading = analogRead(tempPin);
Serial.print(“Temp reading = ”);
Serial.print(tempReading); // the raw analog reading
// converting that reading to voltage, which is based off the reference voltage
float voltage = tempReading * aref_voltage;
voltage /= 1024.0;
// print out the voltage
Serial.print(“ - ”);
Serial.print(voltage); Serial.println(“ volts”);
// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((volatge - 500mV) times 100)
Serial.print(temperatureC); Serial.println(“ degrees C”);
// now convert to Fahrenheight
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(temperatureF); Serial.println(“ degrees F”);
delay(1000);
} /* Sensor test sketch
for more information see http://www.ladyada.net/make/logshield/lighttemp.html
*/
#define aref_voltage 3.3 // we tie 3.3V to ARef and measure it with a multimeter!
//TMP36 Pin Variables
int tempPin = 1; //the analog pin the TMP36’s Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures
int tempReading; // the analog reading from the sensor
void setup(void) {
// We‘ll send debugging information via the Serial monitor
Serial.begin(9600);
// If you want to set the aref to something other than 5v
analogReference(EXTERNAL);
}
void loop(void) {
tempReading = analogRead(tempPin);
Serial.print(“Temp reading = ”);
Serial.print(tempReading); // the raw analog reading
// converting that reading to voltage, which is based off the reference voltage
float voltage = tempReading * aref_voltage;
voltage /= 1024.0;
// print out the voltage
Serial.print(“ - ”);
Serial.print(voltage); Serial.println(“ volts”);
// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((volatge - 500mV) times 100)
Serial.print(temperatureC); Serial.println(“ degrees C”);
// now convert to Fahrenheight
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(temperatureF); Serial.println(“ degrees F”);
delay(1000);
}
帶有CircuitPython的TMP36
使用CircuitPython,可以使用板載內(nèi)置的模擬I/O模塊和模數(shù)轉(zhuǎn)換器輕松讀取TMP36傳感器。您只需使用幾行Python代碼就可以輕松地將TMP36輸出電壓轉(zhuǎn)換為精確的溫度讀數(shù)。
要遵循此頁(yè)面,請(qǐng)確保如上圖所示將TMP36傳感器連接到CircuitPython板上頁(yè)。 A0模擬輸入將用作TMP36溫度輸出的輸入。這是一個(gè)在A0模擬輸入上連接到TMP36的Feather M0的示例:
注意:發(fā)現(xiàn)以下簡(jiǎn)單電路給出了錯(cuò)誤的提示由于CircuitPython讀取模擬值的速度很快,因此可以使用CircuitPython進(jìn)行讀數(shù)。要解決此問(wèn)題,請(qǐng)?jiān)赥MP36的輸出和接地引腳之間添加一個(gè)0.01uF或0.1uF的電容以及一個(gè)47k的電阻。

div》
Fritzing Source
首先連接到開(kāi)發(fā)板的串行REPL,因此您位于CircuitPython的》》》 提示符下。
接下來(lái)導(dǎo)入必要的 board 和 analogio 模塊:
下載:文件
復(fù)制代碼
import board
import analogio import board
import analogio
現(xiàn)在為板上的A0引腳創(chuàng)建一個(gè)模擬輸入:
下載:文件
復(fù)制代碼
tmp36 = analogio.AnalogIn(board.A0) tmp36 = analogio.AnalogIn(board.A0)
這時(shí),您可以讀取TMP36傳感器輸出的原始ADC值。就像模擬I/O指南中提到的那樣,該值的范圍將與傳感器輸出的電壓成正比,范圍是0到65535(從0到電路板的模擬參考電壓,通常是3.3V到5V)。例如,嘗試讀取原始ADC值:
下載:文件
復(fù)制代碼
tmp36.value tmp36.value

您可以使用上一頁(yè)中提到的類(lèi)似公式將此值轉(zhuǎn)換為電壓(以毫伏為單位)。但是,有一個(gè)很小的變化將值的范圍從1023增加到65535-這是必要的,因?yàn)镃ircuitPython為ADC輸入使用了更大范圍的值。此外,通過(guò)CircuitPython,您可以直接訪(fǎng)問(wèn)電路板的模擬參考電壓,因此一個(gè)簡(jiǎn)單的公式對(duì)于3.3V和5V參考均適用:
下載:文件
復(fù)制代碼
tmp36.value * (tmp36.reference_voltage * 1000 / 65535) tmp36.value * (tmp36.reference_voltage * 1000 / 65535)

一旦TMP36輸出了模擬電壓值,就可以將其轉(zhuǎn)換為溫度就像上一頁(yè)顯示的那樣:
下載:文件
復(fù)制代碼
millivolts = tmp36.value * (tmp36.reference_voltage * 1000 / 65535)
(millivolts - 500) / 10 millivolts = tmp36.value * (tmp36.reference_voltage * 1000 / 65535)
(millivolts - 500) / 10

讓我們?yōu)槲覀儓?zhí)行此函數(shù)并返回以攝氏度為單位的溫度:
下載:文件
復(fù)制代碼
def tmp36_temperature_C(analogin):
millivolts = analogin.value * (analogin.reference_voltage * 1000 / 65535)
return (millivolts - 500) / 10
tmp36_temperature_C(tmp36) def tmp36_temperature_C(analogin):
millivolts = analogin.value * (analogin.reference_voltage * 1000 / 65535)
return (millivolts - 500) / 10
tmp36_temperature_C(tmp36)


您也可以將其變成一個(gè)完整的程序,該程序也每秒讀取和打印溫度。將其另存為板上的 main.py 并檢查串行輸出:
下載:文件
復(fù)制代碼
import board
import analogio
import time
TMP36_PIN = board.A0 # Analog input connected to TMP36 output.
# Function to simplify the math of reading the temperature.
def tmp36_temperature_C(analogin):
millivolts = analogin.value * (analogin.reference_voltage * 1000 / 65535)
return (millivolts - 500) / 10
# Create TMP36 analog input.
tmp36 = analogio.AnalogIn(TMP36_PIN)
# Loop forever.
while True:
# Read the temperature in Celsius.
temp_C = tmp36_temperature_C(tmp36)
# Convert to Fahrenheit.
temp_F = (temp_C * 9/5) + 32
# Print out the value and delay a second before looping again.
print(“Temperature: {}C {}F”.format(temp_C, temp_F))
time.sleep(1.0) import board
import analogio
import time
TMP36_PIN = board.A0 # Analog input connected to TMP36 output.
# Function to simplify the math of reading the temperature.
def tmp36_temperature_C(analogin):
millivolts = analogin.value * (analogin.reference_voltage * 1000 / 65535)
return (millivolts - 500) / 10
# Create TMP36 analog input.
tmp36 = analogio.AnalogIn(TMP36_PIN)
# Loop forever.
while True:
# Read the temperature in Celsius.
temp_C = tmp36_temperature_C(tmp36)
# Convert to Fahrenheit.
temp_F = (temp_C * 9/5) + 32
# Print out the value and delay a second before looping again.
print(“Temperature: {}C {}F”.format(temp_C, temp_F))
time.sleep(1.0)
這是將TMP36與CircuitPython一起使用的全部?jī)?nèi)容!
示例項(xiàng)目
遠(yuǎn)程溫度傳感器
視頻使用生物反饋(體溫)的編輯器
如何為用于遙控車(chē)輛(機(jī)器人潛艇)的LM35傳感器防水
一個(gè)“智能杯墊”可讓您知道何時(shí)可以安全飲用咖啡/茶。其中一些項(xiàng)目使用熱敏電阻(根據(jù)溫度改變電阻的電阻溫度),但很容易適應(yīng)TMP36等固態(tài)傳感器。
責(zé)任編輯:wv
-
溫度傳感器
+關(guān)注
關(guān)注
48文章
3255瀏覽量
163481
發(fā)布評(píng)論請(qǐng)先 登錄
TMP36溫度傳感器的使用
評(píng)論