Zhang Yuexin

C# programmer. Know a bit of hardware knowledge. 3D model design novice.

张高兴 - 土味儿编程

高兴不高兴

张高兴的 Windows 10 IoT 开发笔记:DHT11 温湿度传感器

本文约 201 字,包含 0 张图片,5 个代码段,阅读时间约 1 分钟
QR Code

在手机上查看此页面


This is a Windows 10 IoT Core project on the Raspberry Pi 2/3, coded by C#.

GitHub:https://github.com/ZhangGaoxing/windows-iot-demo/tree/master/DHT11

Connect

  • OUT - Pin 3
  • VCC - 5V
  • GND - GND

Reference

https://github.com/ZhangGaoxing/windows-iot-demo/blob/master/DHT11/Reference

What Contains

In DHT11.cs file

One Struct

// DHT11 data struct
struct DHT11Data
{
  // Temperature - ℃
  public short Temperature;
  // Humidity - %
  public short Humidity;
  // Check the data is true or false
  public bool IsTrue;
}

One Constructor

You need to pass sensor pin value to create a new object.

Three Methods

// Initialize DHT11
public void Initialize();
// Read data from DHT11
public DHT11Data Read();
// Cleanup
public void Dispose();

How to Use

  • First, you need to create a DHT11 object. After that you should call Initialize() to initialize.
DHT11 sensor = new DHT11(3);
sensor.Initialize();
  • Second, Read().
DHT11Data data = sensor.Read();
  • If you want to close the sensor, call Dispose().
sensor.Dispose();
最后更新时间 : 2019/06/16 17:18 张高兴 阅读(255) 评论(0)
文章标签: C# IoT UWP Raspberry Pi
  发表评论
Click to Refresh