Arduino与Proteus仿真实例-DS1621温度传感器驱动仿真

DS1621温度传感器驱动仿真

DS1621 数字温度计和恒温器提供 9 位温度读数,指示器件的温度。 当器件温度超过用户定义的温度 TH 时,热报警输出 TOUT 处于活动状态。 输出保持有效,直到温度低于用户定义的温度 TL,允许任何必要的滞后。
用户定义的温度设置存储在非易失性存储器中,因此零件可以在插入一个系统。 温度设置和温度读数都传送到/从DS1621 通过一个简单的 2 线串行接口。

在这里插入图片描述

DS1621的引脚功能如下:

在这里插入图片描述

1、仿真电路原理图

在这里插入图片描述

2、仿真代码实现

本次实例使用到如下开源库:

演示代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <Wire.h> 

#include <DS1621.h>

// DS1621 demo
// based on code from McPhalen published at http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1198065647

// SDA pin is Analog4
// SCL pin is Analog5
// DS1621 has A2, A1, and A0 pins connected to GND

byte addr = 0x48; // replace the 0 with the value you set on pins A2, A1 and A0
DS1621 sensor=DS1621(addr);


void setup()
{
sensor.startConversion(false); // stop if presently set to continuous
sensor.setConfig(DS1621::POL | DS1621::ONE_SHOT); // Tout = active high; 1-shot mode
sensor.setThresh(DS1621::ACCESS_TH, 27); // high temp threshold = 80F
sensor.setThresh(DS1621::ACCESS_TL, 24); // low temp threshold = 75F

Serial.begin(9600);
delay(5);
Serial.println("DS1621 Demo");

int tHthresh = sensor.getTemp(DS1621::ACCESS_TH);
Serial.print("High threshold = ");
Serial.println(tHthresh);

int tLthresh = sensor.getTemp(DS1621::ACCESS_TL);
Serial.print("Low threshold = ");
Serial.println(tLthresh);
}


void loop()
{
int tC, tFrac;

tC = sensor.getHrTemp(); // read high-resolution temperature

if (tC < 0) {
tC = -tC; // fix for integer division
Serial.print("-"); // indicate negative
}

tFrac = tC % 100; // extract fractional part
tC /= 100; // extract whole part

Serial.print(tC);
Serial.print(".");
if (tFrac < 10)
Serial.print("0");
Serial.println(tFrac);

delay(500);
}


3、仿真结果

在这里插入图片描述

文章来源: https://iotsmart.blog.csdn.net/article/details/121573270