概述
在本課程中,您將基于在第11課中學(xué)到的內(nèi)容并使用LCD顯示屏顯示溫度和光強(qiáng)度。
使用第9課中使用的同一光電管測量光強(qiáng)度。
要測量溫度,您將使用溫度測量芯片。該設(shè)備只有3條導(dǎo)線,兩條分別用于5V和GND,第三條導(dǎo)線直接連接到Arduino上的模擬輸入。
零件
零件 數(shù)量
LCD顯示(16x2個字符)
1
1
1kΩ電阻(棕色,黑色,紅色條紋)
1
光電管(光敏電阻)
1
TMP36溫度傳感器
1
半面包板
1
Arduino Uno R3
1
跳線包
1
TMP36的外觀類似于PN2222晶體管,但是如果看封裝體的平坦側(cè)面,則應(yīng)該看到它被標(biāo)記為TMP36。
面包板布局
面包板布局基于第11課的布局,因此,如果您仍將其放在面包板上,它將大大簡化操作。

有一些跳線在此版式上已稍有移動。尤其是鍋底附近的那些。
光電管,1kΩ電阻和TMP36都是板子的新添加。 TMP36的曲面朝向顯示器。
Arduino代碼
此草圖基于第11課的草圖。將其加載到Arduino上,您應(yīng)該發(fā)現(xiàn)將手指放在上面即可加熱溫度傳感器會增加溫度讀數(shù)。
此外,如果您將手放在光電管上,遮擋了一些光,讀數(shù)也會降低。
下載:文件
復(fù)制代碼
/*
Adafruit Arduino - Lesson 12. Light and Temperature
*/
#include
int tempPin = 0;
int lightPin = 1;
// BS E D4 D5 D6 D7
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup()
{
lcd.begin(16, 2);
}
void loop()
{
// Display Temperature in C
int tempReading = analogRead(tempPin);
float tempVolts = tempReading * 5.0 / 1024.0;
float tempC = (tempVolts - 0.5) * 100.0;
float tempF = tempC * 9.0 / 5.0 + 32.0;
// ----------------
lcd.print(“Temp F ”);
lcd.setCursor(6, 0);
lcd.print(tempF);
// Display Light on second row
int lightReading = analogRead(lightPin);
lcd.setCursor(0, 1);
// ----------------
lcd.print(“Light ”);
lcd.setCursor(6, 1);
lcd.print(lightReading);
delay(500);
} /*
Adafruit Arduino - Lesson 12. Light and Temperature
*/
#include
int tempPin = 0;
int lightPin = 1;
// BS E D4 D5 D6 D7
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup()
{
lcd.begin(16, 2);
}
void loop()
{
// Display Temperature in C
int tempReading = analogRead(tempPin);
float tempVolts = tempReading * 5.0 / 1024.0;
float tempC = (tempVolts - 0.5) * 100.0;
float tempF = tempC * 9.0 / 5.0 + 32.0;
// ----------------
lcd.print(“Temp F ”);
lcd.setCursor(6, 0);
lcd.print(tempF);
// Display Light on second row
int lightReading = analogRead(lightPin);
lcd.setCursor(0, 1);
// ----------------
lcd.print(“Light ”);
lcd.setCursor(6, 1);
lcd.print(lightReading);
delay(500);
}
I
下載:文件
復(fù)制代碼
// BS E D4 D5 D6 D7
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // BS E D4 D5 D6 D7
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
如果您決定更改使用的引腳,這將使事情變得更容易。
在“循環(huán)”功能中,現(xiàn)在發(fā)生了兩個有趣的事情。首先,我們必須將溫度傳感器的模擬量轉(zhuǎn)換為實(shí)際溫度,其次,我們必須弄清楚如何顯示它們。
首先,讓我們看一下計(jì)算溫度。
下載:文件
復(fù)制代碼
int tempReading = analogRead(tempPin);
float tempVolts = tempReading * 5.0 / 1024.0;
float tempC = (tempVolts - 0.5) * 100.0;
float tempF = tempC * 9.0 / 5.0 + 32.0; int tempReading = analogRead(tempPin);
float tempVolts = tempReading * 5.0 / 1024.0;
float tempC = (tempVolts - 0.5) * 100.0;
float tempF = tempC * 9.0 / 5.0 + 32.0;
首先將溫度傳感器的原始讀數(shù)乘以5,然后除以1024,以得到‘tempPin處的電壓(0至5之間)模擬輸入。
要將TMP36的電壓轉(zhuǎn)換為攝氏度,必須從測量值中減去0.5V,然后乘以100。
要將其轉(zhuǎn)換為溫度。在華氏溫度下,您必須將其乘以9/5,然后再加上32。
在LCD顯示屏上顯示變化的讀數(shù)可能很棘手。主要的問題是讀數(shù)不一定總是相同的位數(shù)。因此,如果溫度從101.50變?yōu)?9.00,則舊讀數(shù)的多余數(shù)字有留在顯示器上的危險。/p》
下載:文件
復(fù)制代碼
// ----------------
lcd.print(“Temp F ”);
lcd.setCursor(6, 0);
lcd.print(tempF); // ----------------
lcd.print(“Temp F ”);
lcd.setCursor(6, 0);
lcd.print(tempF);
一個相當(dāng)奇怪的注釋用來提醒您顯示屏的16列。然后,您可以打印該長度的字符串,并在其中帶有實(shí)際讀數(shù)的空格。
要填充空格,請?jiān)O(shè)置光標(biāo)所在位置,然后顯示讀數(shù)。
完全相同的方法用于顯示光照水平。光線水平?jīng)]有單位,我們只顯示模擬讀數(shù)的原始讀數(shù)。
其他要做的事情
嘗試更改示例,使其以攝氏度而不是華氏度顯示溫度。
責(zé)任編輯:wv
-
溫度傳感器
+關(guān)注
關(guān)注
48文章
3223瀏覽量
163176 -
lcd
+關(guān)注
關(guān)注
36文章
4621瀏覽量
177447
發(fā)布評論請先 登錄
淺談液晶顯示屏的七大特色技術(shù)
淺談液晶顯示屏的產(chǎn)品結(jié)構(gòu)與連接方式
LED與液晶顯示屏的抗干擾光模擬測試
LCD液晶顯示屏在強(qiáng)光模擬下的性能測試
基于RK3568開發(fā)板顯示屏調(diào)試適配方法(1)-如何在Uboot界面切換顯示屏
碩博電子7寸觸摸顯示屏,支持CAN通信和Codesy編程#工業(yè)顯示屏 #汽車CAN總線? #觸摸顯示屏
TFT顯示屏環(huán)境溫度設(shè)計(jì)指南
液晶顯示屏出廠要做哪些安全檢測
如何使用LCD顯示屏顯示溫度和光強(qiáng)度
評論