带Arduino的温湿度传感器

进入这个项目,您将了解接口温度和湿度。带有Arduino的传感器!

工具和机器

Arduino IDE

项目介绍

朋友们,大家好!欢迎来到我的另一个温度和湿度 (DHT11) 传感器教程,在这个项目中,我将向您展示如何将该传感器与 Arduino UNO R3 连接。

#include <dht.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C  lcd = liquidCrystal_I2C(0x27, 20, 4)

dht DHT;

#define DHT11_PIN 7

void  setup(){
  lcd.init(); // initialise I2C LCD
  lcd.backlight(); // Turn On  the backlight of the I2C LCD
}

void loop(){
  int chk = DHT.read11(DHT11_PIN);
  lcd.setCursor(0,0); 
  lcd.print("Temp: ");
  lcd.print(DHT.temperature);
  lcd.print((char)223);
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Humidity:  ");
  lcd.print(DHT.humidity);
  lcd.print("%");
  delay(1000);
}
#include <dht.h> // You have to download this liibrary. NAME: dht library

dht  DHT; 

#define DHT11_PIN 7 // define DHT pin

void setup(){
  Serial.begin(9600);  // Start serial communication
}

void loop(){
  int chk = DHT.read11(DHT11_PIN);  // check the data coming from the DHT pin
  Serial.print("Temperature = ");  // print temperature on the serial monitor
  Serial.println(DHT.temperature);
  Serial.print("Humidity = ");// Print humidity on the serial monitor
  Serial.println(DHT.humidity);
  delay(1000); // delay of 1 second
}


      /*Here are the connections
      
      Take a DHT11 sensor.
      there, in the DHT11 sensor, there  are 3 or 4 pins.
      There, on the DHT11 sensor, there is writen S, +, -
      connect "S" on the digital pin 7.
      connect "+" on the 5V pin on  Arduino.
      connect "-" on the GND pin on Arduino.
      
      Thank  you
      Meet you in the next project.
      */ 

通过串行监视器将 DHT11 连接到 Arduino。

在此代码中,我们使用串行监视器来打印温度和湿度传感器。

#include <dht.h> // You have to download this liibrary. NAME: dht library

dht
DHT;

#define DHT11_PIN 7 // define DHT pin

void setup(){
Serial.begin(9600);
// Start serial communication
}

void loop(){
int chk = DHT.read11(DHT11_PIN);
// check the data coming from the DHT pin
Serial.print("Temperature = ");
// print temperature on the serial monitor
Serial.println(DHT.temperature);

Serial.print("Humidity = ");// Print humidity on the serial monitor
Serial.println(DHT.humidity);

delay(1000); // delay of 1 second
}


/*Here are the connections


Take a DHT11 sensor.
there, in the DHT11 sensor, there
are 3 or 4 pins.
There, on the DHT11 sensor, there is writen S, +, -

connect "S" on the digital pin 7.
connect "+" on the 5V pin on
Arduino.
connect "-" on the GND pin on Arduino.

Thank
you
Meet you in the next project.
*/

Similar Posts

Leave a Reply