DEV Community

Cover image for IoT-Based Environmental Monitoring System with kiwisIOT
S. Nishanth
S. Nishanth

Posted on Edited on

IoT-Based Environmental Monitoring System with kiwisIOT

I was sitting at my desk in Erode, wondering how hot and humid the room was, and I had no good way to find out. A wall thermometer shows one spot and no history. So I built an IoT environmental monitor with an ESP8266, a DHT11 sensor, and the KiwisIoT cloud platform.

Every two seconds, the board reads the temperature and humidity and sends both values over Wi-Fi to a live dashboard. I can check the room from any browser or phone. The wiring takes three jumper wires.

The hardest part wasn’t the code. My first connection failed because the ESP8266 only works on 2.4 GHz Wi-Fi. KiwisIoT handled the cloud side, so I didn’t need a server or database.

circuit diagram

Circuit Connection

Connect the DHT11 to the NodeMCU as follows:


1. DHT11 Pin        NodeMCU Pin Purpose
2. VCC (+)          3V3         Power supply
3. GND (−)          GND         Ground
4. DATA (S or OUT)  D5 (GPIO14) Data 
Enter fullscreen mode Exit fullscreen mode

Live Dashboard

project code

const char* ssid = "YOUR_WIFI_NAME";
const char* pass = "YOUR_WIFI_PASSWORD";

const char* topic = "YOUR_DASHBOARD_TOPIC_ID";

#define DHT_PIN D5
#define DHT_TYPE DHT11

DHT dht(DHT_PIN, DHT_TYPE);

KiwisIoT kiwisiot(ssid, pass, topic);

void sendDHTData() {

  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();

  if (isnan(temperature) || isnan(humidity)) {

    Serial.println();
    Serial.println("Failed to read DHT11!");

    return;
  }

  Serial.println();
  Serial.println("---------- DHT11 MONITORING ----------");

  Serial.print("Temperature: ");
  Serial.print(temperature, 1);
  Serial.println(" °C");

  Serial.print("Humidity: ");
  Serial.print(humidity, 1);
  Serial.println(" %");

  String temperatureData = String(temperature, 1);

  kiwisiot.send("0", temperatureData);

  Serial.print("Sent to KiwisIoT Channel 0: ");
  Serial.println(temperatureData);

  String humidityData = String(humidity, 1);

  kiwisiot.send("1", humidityData);

  Serial.print("Sent to KiwisIoT Channel 1: ");
  Serial.println(humidityData);
}

void setup() {

  Serial.begin(115200);

  Serial.println("     DHT11 MONITORING     ");

  dht.begin();

  Serial.println("DHT11 initialized");

  Serial.println("Connecting to KiwisIoT...");

  kiwisiot.begin();

  Serial.println("KiwisIoT initialized");
  Serial.println("Starting temperature and humidity monitoring...");
}

void loop() {

  kiwisiot.run();

  static unsigned long lastSend = 0;

  if (millis() - lastSend >= 2000) {

    lastSend = millis();

    sendDHTData();
  }

  delay(100);
}
Enter fullscreen mode Exit fullscreen mode

Serial Monitor Output

The full project, with the README, wiring guide, and Arduino sketch, is on kiwisiot GitHub link: https://github.com/Kiwistron/KiwisIoTProjects/tree/main/esp8266/004-dht11-kiwisiot

Top comments (0)