极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 27115|回复: 1

Arduino入门实践之模拟温度感应器

[复制链接]
发表于 2020-12-14 21:12:23 | 显示全部楼层 |阅读模式
材料:
arduino uno
杜邦线
热敏电阻
数据线

引脚连接:
s        ->      5V
out    ->       A0
-        ->       GND

代码:
  1. #include<math.h>
  2. double Thermister(int rawADC)
  3. {
  4.   double tmp;
  5.   tmp = log(((10240000 / rawADC) - 10000));
  6.   tmp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tmp * tmp)) * tmp);
  7.   tmp = tmp - 273.15;
  8.   return tmp;
  9. }

  10. void setup() {
  11.   // put your setup code here, to run once:
  12.   Serial.begin(9600);
  13. }

  14. void loop() {
  15.   // put your main code here, to run repeatedly:
  16.   int raw = analogRead(A5);
  17.   Serial.print("raw:");
  18.   Serial.print(raw);
  19.   Serial.print(",");
  20.   Serial.print(Thermister(raw));
  21.   Serial.println("c");
  22.   delay(500);
  23. }
复制代码

回复

使用道具 举报

发表于 2020-12-15 22:43:28 | 显示全部楼层
支持一个,认真学习和记录
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-20 02:59 , Processed in 0.039901 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表