Last active
March 10, 2019 12:27
-
-
Save ezhov-da/d76cfa76351d7e0996f41c551dceab3e to your computer and use it in GitHub Desktop.
arduino датчик влажности и температуры dht11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//==> http://edurobots.ru/2015/02/arduino-dlya-nachinayushhix-urok-9-podklyuchenie-datchika-temperatury-i-vlazhnosti-dht11-i-dht22 | |
//==> http://edurobots.ru/wp-content/uploads/2015/02/dht-600x339.jpg | |
#include "DHT.h" | |
#define DHTPIN 2 // номер пина, к которому подсоединен датчик | |
// Раскомментируйте в соответствии с используемым датчиком | |
// Инициируем датчик | |
DHT dht(DHTPIN, DHT22); | |
//DHT dht(DHTPIN, DHT11); | |
void setup() { | |
Serial.begin(9600); | |
dht.begin(); | |
} | |
void loop() { | |
// Задержка 2 секунды между измерениями | |
delay(2000); | |
//Считываем влажность | |
float h = dht.readHumidity(); | |
// Считываем температуру | |
float t = dht.readTemperature(); | |
// Проверка удачно прошло ли считывание. | |
if (isnan(h) || isnan(t)) { | |
Serial.println("Не удается считать показания"); | |
return; | |
} | |
Serial.print("Влажность: "+h+" %\t"+"Температура: "+t+" *C "); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment