Arduino作为服务器显示温度,基于Arduino 带LCD显示的电子温度计
原創博文,轉載請注明出處
前言
作為一名嵌入式系統的初學者,我常常用手中的板子做一些能夠讓生活更加簡便的小應用。但是往往在一段時間后,當我想對這些小應用做些升級的時候,總是由于之前開發的過程中沒有做過系統的記錄,對整個系統的升級過程是十分困難的。甚至個別復雜的應用我直接放棄閱讀冗長的代碼和分析雜亂的焊接電路,直接進行重新開發。
為了改變這個情況,我想在這里對我做過的小應用進行系統的記錄。方便自己以后對應用的升級,也希望對其他的嵌入式愛好者有所幫助。同時如果各位朋友發現我的錯誤,我也樂于接受大家對我的指摘。
準備
Arduino Nano 開發板 *1(其他系列的Arduino開發板也可共享我的代碼)
按鈕 *1
1.5kΩ 電阻 *1
510Ω 電阻 *1
DS18B20 溫度傳感器 *1
LCD1602 液晶屏 *1
電線 若干
以下器件如果您要在面包板上做,可省略:
電工工具
公口排針15pin *2
公口排針3pin *1
母口排針16pin *1
PCB版 5*7cm *1
亞克力板(做保護膜用的,可省略)
電路圖
面包板線路圖
代碼
// for thermometer
#include?
#include?
// for LCD
#include?
#define ONE_WIRE_BUS 6
// Set up a oneWire instance to communicate with any
OneWire device
OneWire ourWire(ONE_WIRE_BUS);
// Tell Dallas Temperature Library to use oneWire
Library
DallasTemperature sensors(&ourWire);
const int backlight = 8; // pin for backlight of LCD
screen
// initialize the library with the numbers of the
interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int outputState = HIGH; ?//
variable for reading the output status
const int button_in = 9;
int buttonState = 0;
int preState = 0;
void setup()
{
// Serial port
// Start serial port to see
results
Serial.begin(9600);
Serial.println("Thermometer with LCD
Test Program");
Serial.println("Temperature Sensor
DS18B20");
// Themometer
// Start up the DallasTemperature
library
sensors.begin();
// LCD
// Set up the LCD's number of columns
and rows:
lcd.begin(16, 2);
// Print a message to the
LCD.
lcd.print("Temperature");
// PIN
pinMode(backlight,OUTPUT);
pinMode(button_in,INPUT);
}
void loop()
{
//Button
// read the state of the pushbutton
value:
preState = buttonState;
buttonState =
digitalRead(button_in);
// check if the pushbutton
is pressed.
// if it is, the
buttonState is HIGH:
if (buttonState == HIGH) {
//
while(buttonState == HIGH)buttonState =
digitalRead(button_in);
if (preState !=
HIGH)
outputState =
!outputState;
}
digitalWrite(backlight, outputState); // turn the LED on (HIGH is the
voltage level)
//Thermometer
Serial.println();
Serial.print("Requesting
temperature...");
sensors.requestTemperatures();
// Send the command to get
temperatures
Serial.println("DONE");
Serial.print(sensors.getTempCByIndex(0));
Serial.println(" Degrees
C");
//LCD
// set the cursor to column 0, line
1
// (note: line 1 is the
second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of
seconds since reset:
lcd.print(sensors.getTempCByIndex(0));
lcd.setCursor(5, 1);
lcd.print("C");
delay(100);
}
焊接與組裝
焊接
我也是剛剛開始學習焊接,焊接的水平十分有限,成品的外觀不怎么美觀,但是功能還是沒問題的。
組裝
總結
以上是生活随笔為你收集整理的Arduino作为服务器显示温度,基于Arduino 带LCD显示的电子温度计的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: his系统存储服务器,关于HIS服务器及
- 下一篇: 畅玩mt3单机游戏服务器维护,【梦幻西游