Cara Menggunakan Sensor DHT22 dengan Arduino, NodeMCU (ESP8266) dan ESP32

Wiring diagram cara instalasi dan program dht 22 di arduino uno


#include "DHT.h"

#define DHTPIN 2     
#define DHTTYPE DHT22   
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println(F("DHTxx test!"));

  dht.begin();
}

void loop() {
  delay(2000);

  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  float hif = dht.computeHeatIndex(f, h);
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.print(F("°C "));
  Serial.print(f);
  Serial.print(F("°F  Heat index: "));
  Serial.print(hic);
  Serial.print(F("°C "));
  Serial.print(hif);
  Serial.println(F("°F"));
}

Wiring diagram DHT 22 menggnakan lcd

#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#define DHTPIN 11
#define DHTTYPE DHT22
#define OUTPUT 9
#define OUTPUT 10

DHT dht(DHTPIN, DHTTYPE);

const int ledPin = 13;
const int col = 16;
const int row = 2;
LiquidCrystal_I2C lcd(0x27, col, row);

int degree[] = {
  0b01110,
  0b100010,
  0b100010,
  0b100010,
  0b01110,
  0b00000,
  0b00000,
  0b00000,
};

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Temins store");
  delay(3000);
  lcd.clear();
  dht.begin();
  pinMode(13, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
}

void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);

  lcd.setCursor(0, 0);
  lcd.print("T:");
  lcd.print(t);
  //lcd.write(byte(0));
  lcd.print("C");
  lcd.setCursor(8, 0);
  lcd.print("H:");
  lcd.print(h);
  lcd.print("%");

  if (t>32.5){
    lcd.setCursor(0, 1);
    lcd.print("Panas ANJAY");
    digitalWrite(13, HIGH);
  } else {
    lcd.setCursor(0, 1);
    lcd.print("ADEM BENER    ");
    digitalWrite(13, LOW);
  digitalWrite(10, LOW);
  digitalWrite(9, LOW);
  }

if (t>33.00){
  digitalWrite(13, LOW);
  digitalWrite(10, HIGH);
  digitalWrite(9, LOW);
}

if (t>33.20){
  digitalWrite(13, LOW);
  digitalWrite(10, LOW);
  digitalWrite(9, HIGH);
}

  delay(2000);
   }

Wiring diagram DHT 22 menggunakan LCD dan LED

#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#define DHTPIN 11
#define DHTTYPE DHT22
#define OUTPUT 9
#define OUTPUT 10

DHT dht(DHTPIN, DHTTYPE);

const int ledPin = 13;
const int col = 16;
const int row = 2;
LiquidCrystal_I2C lcd(0x27, col, row);

int degree[] = {
  0b01110,
  0b100010,
  0b100010,
  0b100010,
  0b01110,
  0b00000,
  0b00000,
  0b00000,
};

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Temins store");
  delay(3000);
  lcd.clear();
  dht.begin();
  pinMode(13, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
}

void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);

  lcd.setCursor(0, 0);
  lcd.print("T:");
  lcd.print(t);
  //lcd.write(byte(0));
  lcd.print("C");
  lcd.setCursor(8, 0);
  lcd.print("H:");
  lcd.print(h);
  lcd.print("%");

  if (t>32.5){
    lcd.setCursor(0, 1);
    lcd.print("Panas ANJAY");
    digitalWrite(13, HIGH);
  } else {
    lcd.setCursor(0, 1);
    lcd.print("ADEM BENER    ");
    digitalWrite(13, LOW);
  digitalWrite(10, LOW);
  digitalWrite(9, LOW);
  }

if (t>33.00){
  digitalWrite(13, LOW);
  digitalWrite(10, HIGH);
  digitalWrite(9, LOW);
}

if (t>33.20){
  digitalWrite(13, LOW);
  digitalWrite(10, LOW);
  digitalWrite(9, HIGH);
}

  delay(2000);
   }

Wiring diagram DHT 22 menggunakan LCD node mcu

#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#define DHTPIN 3
#define DHTTYPE DHT11
#define OUTPUT 3
//#define OUTPUT 10

DHT dht(DHTPIN, DHTTYPE);

const int ledPin = 13;
const int col = 16;
const int row = 2;
LiquidCrystal_I2C lcd(0x27, col, row);

int degree[] = {
  0b01110,
  0b100010,
  0b100010,
  0b100010,
  0b01110,
  0b00000,
  0b00000,
  0b00000,
};

void setup() {
  pinMode(3, OUTPUT);
  //lcd.init();
  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Temins store");
  delay(3000);
  lcd.clear();
  dht.begin();
 // pinMode(13, OUTPUT);
 // pinMode(10, OUTPUT);
  //pinMode(9, OUTPUT);
}

void loop() {
  lcd.begin();
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);

  lcd.setCursor(0, 0);
  lcd.print("T:");
  lcd.print(t);
  //lcd.write(byte(0));
  lcd.print("C");
  lcd.setCursor(8, 0);
  lcd.print("H:");
  lcd.print(h);
  lcd.print("%");

  if (t>32.5){
    lcd.setCursor(0, 1);
    lcd.print("Panas ANJAY");
    digitalWrite(D3, HIGH);
  } else {
    lcd.setCursor(0, 1);
    lcd.print("ADEM BENER    ");
    digitalWrite(13, LOW);
  digitalWrite(10, LOW);
  digitalWrite(9, LOW);
  }
     delay(2000);
   }

  Wiring diagram DHT22 menggunakan node mcu

#include "DHT.h"

#define DHTPIN 3   
#define DHTTYPE DHT22
#define OUTPUT 3  
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println(F("DHTxx test!"));

  dht.begin();
}

void loop() {
  delay(2000);

  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  float hif = dht.computeHeatIndex(f, h);
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.print(F("°C "));
  Serial.print(f);
  Serial.print(F("°F  Heat index: "));
  Serial.print(hic);
  Serial.print(F("°C "));
  Serial.print(hif);
  Serial.println(F("°F"));
}

Wiring diagram dht 22 menggunakan esp32 dan lcd

#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#define DHTPIN 18
#define DHTTYPE DHT22
#define OUTPUT 18
//#define OUTPUT 10

DHT dht(DHTPIN, DHTTYPE);

const int ledPin = 13;
const int col = 16;
const int row = 2;
LiquidCrystal_I2C lcd(0x27, col, row);

int degree[] = {
  0b01110,
  0b100010,
  0b100010,
  0b100010,
  0b01110,
  0b00000,
  0b00000,
  0b00000,
};

void setup() {
  pinMode(18, OUTPUT);
  //lcd.init();
  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Temins store");
  delay(3000);
  lcd.clear();
  dht.begin();
 // pinMode(13, OUTPUT);
 // pinMode(10, OUTPUT);
  //pinMode(9, OUTPUT);
}

void loop() {
  lcd.begin();
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);

  lcd.setCursor(0, 0);
  lcd.print("T:");
  lcd.print(t);
  //lcd.write(byte(0));
  lcd.print("C");
  lcd.setCursor(8, 0);
  lcd.print("H:");
  lcd.print(h);
  lcd.print("%");

  if (t>32.5){
    lcd.setCursor(0, 1);
    lcd.print("Panas ANJAY");
    digitalWrite(18, HIGH);
  } else {
    lcd.setCursor(0, 1);
    lcd.print("ADEM BENER    ");
    digitalWrite(13, LOW);
  digitalWrite(10, LOW);
  digitalWrite(9, LOW);
  }
     delay(2000);
   }

Wiring diagram dht 22 menggunakan esp32

#include "DHT.h"

#define DHTPIN 18   
#define DHTTYPE DHT22
#define OUTPUT 18  
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println(F("DHTxx test!"));

  dht.begin();
}

void loop() {
  delay(2000);

  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  float hif = dht.computeHeatIndex(f, h);
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.print(F("°C "));
  Serial.print(f);
  Serial.print(F("°F  Heat index: "));
  Serial.print(hic);
  Serial.print(F("°C "));
  Serial.print(hif);
  Serial.println(F("°F"));
}

Leave a Reply

Your email address will not be published. Required fields are marked *