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

亚克力板(做保护膜用的,可省略)

a4c26d1e5885305701be709a3d33442f.png

电路图

a4c26d1e5885305701be709a3d33442f.png

面包板线路图a4c26d1e5885305701be709a3d33442f.png

代码

// 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);

}

焊接与组装

焊接

我也是刚刚开始学习焊接,焊接的水平十分有限,成品的外观不怎么美观,但是功能还是没问题的。

a4c26d1e5885305701be709a3d33442f.png

组装

这是一款有DHT11温度/湿度传感器的Arduino Uno,并有由电源供电的LCD屏幕。 这个项目需要以下内容: 所有零件都可以在sparkfun或adafruit购买。或者你可以像我一样做,并尽可能地从旧设备中拯救。 Arduino(我使用了UNO R3,但任何5V都可以工作) 面包板 DHT11温湿度传感器 10k欧姆电位器 16x2液晶屏幕 触觉按钮 USB AB电缆 充电宝 跳线 现在是把所有电线连接到设备的时候了。请参阅Fritzing原理图(请注意,我在面包板上的两个电源导轨之间没有跳线,如果同时使用这两个电源导轨,您将需要它们): 我使用的LCD显示器是从一个旧的火灾报警器面板中恢复的。引脚15和16位于引脚1之前,而引脚16不是Gnd,实际上是5v,引脚15是Gnd。请仔细检查你自己的显示器,并确保你的引脚是正确的。由于我的显示器引脚排列几乎与其他人不同,所以我使用“标准”显示屏制作了Fritzing原理图,而不是我的确切引脚。 Gnd - >面包板上的负电源 5v - >面包板上的正轨 DTH11 Pin1 - > 5v和10k欧姆电阻 Pin2 - > Arduino Pin8和10k欧姆电阻 Pin3 - >无连接 Pin4 - > Gnd 16x2液晶屏幕 Pin1 - > Gnd Pin2 - > 5v Pin3 - > 10k欧姆电位器刮水器针(中间针,POT上的另外两个针变为5v和Gnd) Pin4 - > Arduino Pin12 Pin5 - > Gnd Pin6 - > Arduino Pin11 Pin7 - >没有连接 Pin8 - >没有连接 Pin9 - >没有连接 Pin10 - >没有连接 Pin11 - > Arduino Pin5 Pin12 - > Arduino Pin4 Pin13 - > Arduino Pin3 Pin14 - > Arduino Pin2 Pin15 - > 5v Pin16 - >触觉按钮(另一侧的按钮去Gnd) 完成所有接线后,将电源插入Arduino。 您的液晶显示器和DHT11应该启动。按下圆润按钮,LCD背光应该点亮。 现在你有一个有实时显示的便携式温度和湿度传感器。 这帮助我确定了我家中最有野味的窗户,以及如何最好地设置房屋通风。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值