You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include<EduIntro.h>
LM35 lm35(A2); // creating the object 'lm35' on pin A2float C, F; // temperature readings are returned in float formatvoidsetup()
{
// initialize serial communications at 9600 bps
Serial.begin(9600);
}
voidloop()
{
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
}
最近买了个 Arduino nano 兼容版,非官方的,因为 nano 体积比较小,所以做成监控设备比较有优势,这里通过 LM35 测试一下 nano 能否有效工作。
LM35 是一个温度传感器,和 DHT11,DHT22 有点类似,但是精度差一点,引脚图:
需要注意引脚的正反面,接线如图:
对于 LM35 之前网上查了一些资料,都是复制黏贴来的,没有啥可参考性,看了官方示例,有比较简单的编程方法,就是使用官方的
EduIntro
库。在 工具 -> 管理库 中搜索
ediintro
, 安装相应的库,代码:
这里使用
A2
引脚读取温度,然后将其转换成摄氏度和华氏度,然后发送数据给串口,打开串口监视器就能看到有数据输出。The text was updated successfully, but these errors were encountered: