Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arduino nano 通过 LM35 检测温度 #291

Open
twn39 opened this issue Nov 15, 2019 · 0 comments
Open

Arduino nano 通过 LM35 检测温度 #291

twn39 opened this issue Nov 15, 2019 · 0 comments
Labels

Comments

@twn39
Copy link
Owner

twn39 commented Nov 15, 2019

最近买了个 Arduino nano 兼容版,非官方的,因为 nano 体积比较小,所以做成监控设备比较有优势,这里通过 LM35 测试一下 nano 能否有效工作。

注:因为我买的 nano 非官方,所以在 Arduino IDE 中的处理器选项需要选择:ATmega328p (Old Bootloader), 不同的板子视板子芯片而定。

LM35 是一个温度传感器,和 DHT11,DHT22 有点类似,但是精度差一点,引脚图:

8b13632762d0f7031d64375202fa513d2797c56e jpg

需要注意引脚的正反面,接线如图:

TIM图片20191115143513

对于 LM35 之前网上查了一些资料,都是复制黏贴来的,没有啥可参考性,看了官方示例,有比较简单的编程方法,就是使用官方的 EduIntro 库。

在 工具 -> 管理库 中搜索 ediintro, 安装相应的库,

eduintro

代码:

#include <EduIntro.h>

LM35 lm35(A2);  // creating the object 'lm35' on pin A2
float C, F;  // temperature readings are returned in float format

void setup()
{
  // initialize serial communications at 9600 bps
  Serial.begin(9600);
}

void loop()
{
  C = lm35.readCelsius();       // Reading the temperature in Celsius degrees and store in the C variable
  F = lm35.readFahrenheit();    // Reading the temperature in Fahrenheit degrees and store in the F variable

  // Print the collected data in a row on the Serial Monitor
  Serial.print("Analog reading: "); // Reading the analog value from the thermistor
  Serial.print(lm35.read());
  Serial.print("\tC: ");
  Serial.print(C);
  Serial.print("\tF: ");
  Serial.println(F);

  delay(1000);                // Wait one second before get another temperature reading
}

这里使用 A2 引脚读取温度,然后将其转换成摄氏度和华氏度,然后发送数据给串口,打开串口监视器就能看到有数据输出。

@twn39 twn39 added the arduino label Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant