This repository has been archived on 2024-08-19. You can view files and clone it, but cannot push or open issues or pull requests.
Arduino/sketches/sketch_aug10e.ino
2024-05-03 01:10:21 +03:00

26 lines
1.2 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "DHT.h"
#define DHTPIN 2 // Тот самый номер пина, о котором упоминалось выше
// Одна из следующих строк закомментирована. Снимите комментарий, если подключаете датчик DHT11 к arduino
DHT dht(DHTPIN, DHT22); //Инициация датчика
//DHT dht(DHTPIN, DHT11);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
delay(2000); // 2 секунды задержки
float h = dht.readHumidity(); //Измеряем влажность
float t = dht.readTemperature(); //Измеряем температуру
if (isnan(h) || isnan(t)) { // Проверка. Если не удается считать показания, выводится «Ошибка считывания», и программа завершает работу
Serial.println("Ошибка считывания");
return;
}
Serial.print("Влажность: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Температура: ");
Serial.print(t);
Serial.println(" *C "); //Вывод показателей на экран
}