DS18B20温度传感器 - arduino

DS18B20测量温度范围是-55℃至125℃,精度为0.5℃。采用单总线进行数据及命令传输,可在同一总线上连接多个DS18B20,并采用地址进行器件选择与数据传输
产品封装
DS18B20产品封装
时序图
DS18B20时序图
典型应用电路

  1. 典型电路
    典型外部供电方式取电
  2. 寄生供电方式
    寄生供电方式

支持命令集
命令集
复位时序
复位
读写时序
读写


arduino 程序

#ifndef DS18B20_h
#define DS18B20_h

#include <inttypes.h>

#if ARDUINO >= 100
#include "Arduino.h"       // for delayMicroseconds, digitalPinToBitMask, etc
#else
#include "WProgram.h"      // for delayMicroseconds
#include "pins_arduino.h"  // for digitalPinToBitMask, etc
#endif

// You can exclude certain features from DS18B20.  In theory, this
// might save some space.  In practice, the compiler automatically
// removes unused code (technically, the linker, using -fdata-sections
// and -ffunction-sections when compiling, and Wl,--gc-sections
// when linking), so most of these will not result in any code size
// reduction.  Well, unless you try to use the missing features
// and redesign your program to not need them!  DS18B20_CRC8_TABLE
// is the exception, because it selects a fast but large algorithm
// or a small but slow algorithm.



// You can exclude CRC checks altogether by defining this to 0
#ifndef DS18B20_CRC
#define DS18B20_CRC 1
#endif

// Select the table-lookup method of computing the 8-bit CRC
// by setting this to 1.  The lookup table enlarges code size by
// about 250 bytes.  It does NOT consume RAM (but did in very
// old versions of DS18B20).  If you disable this, a slower
// but very compact algorithm is used.
#ifndef DS18B20_CRC8_TABLE
#define DS18B20_CRC8_TABLE 1
#endif


#define FALSE 0
#define TRUE  1



class DS18B20
{
  private:
    uint8_t PIN;
    byte bitmask;

    // global search state
    byte ROM_NO[8];//search到的最新地址暂存

    uint8_t LastDiscrepancy;
    uint8_t LastDeviceFlag;
    byte search_new();
    byte senser_number; 

    void write(uint8_t v);    
    void write_bytes(const uint8_t *buf, uint16_t count);
    // Read a byte.
    uint8_t read(void);
    void read_bytes(uint8_t *buf, uint16_t count);
    // Write a bit. The bus is always left powered at the end, see
    // note in write() about that.
    void write_bit(uint8_t v);
    // Read a bit.
    uint8_t read_bit(void);
    // Issue a 1-Wire rom select command, you do the reset first.
    void select(const uint8_t rom[8]);
    // Perform a 1-Wire reset cycle. Returns 1 if a device responds
    // with a presence pulse.  Returns 0 if there is no device or the
    // bus is shorted or otherwise held low for more than 250uS
    uint8_t reset(void);
    // Clear the search state so that if will start from the beginning again.
    void reset_search();
    void search();    
  public:
    void<
  • 2
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: DS18B20温度传感器是一种数字式温度传感器,它可以与Arduino等微控制器进行连接。它通过单总线接口进行通信,可以在相对较长的距离内进行通信,并具有高精度的温度测量能力。在Arduino上使用DS18B20传感器,需要先下载并安装OneWire库,然后编写相应的代码来读取传感器的温度数据。通过使用DS18B20传感器,可以实现精确的温度监测和控制,适用于各种应用场景。 ### 回答2: DS18B20是一种数字式温度传感器,可以与Arduino等单片机进行通信,实现温度测量和控制。DS18B20具有精度高、精度稳定、响应速度快、适应广泛的特点,因此在各种工业、农业、医疗、环保等领域都有广泛应用。 DS18B20的通信协议采用1-Wire总线协议,只需要一个数据引脚就可以完成数据的收发。在使用DS18B20进行温度测量时,需要将其连接到Arduino板上。接口一般是将DS18B20的信号引脚连接到Arduino的数字输入口,同时需要使用某些库函数来进行测量和显示数据。 使用DS18B20进行测量时,需要注意如下几个问题。首先,需要为DS18B20提供电源,一般是在5V-12V的范围内才能正常工作。其次,需要在程序中设置正确的测量分辨率,一般分辨率可以设置为9位、10位、11位或者12位。分辨率越高,精度越高,但是测量时间会变长。最后,在程序中还需要设置温度数据的格式和显示方式。 总之,DS18B20是一种非常方便和实用的数字式温度传感器,在各种应用场合都可以发挥很好的作用。通过连接到Arduino等单片机上,可以轻松地实现温度测量和控制功能,为各种工程和项目的实现提供了便利。 ### 回答3: DS18B20温度传感器是一种数字温度传感器,与Arduino等单片机相配合,可以测量环境温度。该传感器具有高精度、低功耗、运行稳定和成本低廉等特点。 DS18B20温度传感器有3个引脚:VDD(电源正极)、GND(电源负极)和DQ(数据引脚)。其中,数据引脚可以通过1-Wire总线与其他DS18B20温度传感器连接,从而建立一个多节点系统。 在Arduino中,使用DS18B20温度传感器需要先导入OneWire.h和DallasTemperature.h两个库。然后,通过OneWire库操作数据引脚,读取DS18B20传感器返回的温度数据。最后,通过DallasTemperature库进行温度的转换和显示。 DS18B20温度传感器的温度测量范围为-55℃至+125℃,分辨率可以达到0.0625℃。在Arduino中,可以通过在代码中设置不同的精度参数来调整温度的精度,从而满足不同应用场景的需求。 因为DS18B20表现出良好的精度、稳定性和低功耗,适用于许多应用领域,如冷链物流、气象监测、温室控制、食品加工和制药等行业。此外,DS18B20的低成本和易用性,也让普通创客和物联网爱好者可以轻松地使用它进行各种项目的温度测量和控制。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值