Temperature-Humidity Monitoring & LED Control

  1. Make the circuit as shown below,

  1. Create IoT devices

Login to OpenIoE,

Compoents >> IoT Devices >> Add IoT Device

Names: Temperature, Humidity, and LED

Data Format: Value, Hardware: Generic

  1. Creates plots, and control

Components >> Plots >> Add Plot

Plot Name: Temperature, Humidity, Sampling Time: 2s, Frames:100

Control Name: LED, Type: On/Off

  1. Upload the program to Microcontroller

include "DHT.h"
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>

DHT dht;
ESP8266WiFiMulti WiFiMulti;
uint8_t LED_Pin =D1;
char TEMP_SENSOR[]="http://app.gnanodaya.org/openioe/api/updatedevicevalue/xxxxxx/xxx/xxx/";
char HUMIDITY_SENSOR[]="http://app.gnanodaya.org/openioe/api/updatedevicevalue/xxxxxx/xxx/xxx/";
char DHT_LED[]="http://app.gnanodaya.org/openioe/api/showdevicevalue/xxxxxxx/xxx/xxx/";

void setup() {
  Serial.begin(9600);
  pinMode(LED_Pin, OUTPUT);
  dht.setup(D4);
  WiFi.mode(WIFI_STA);
  WiFiMulti.addAP("xxxxx", "xxxxx");
}

void loop() {
  delay(dht.getMinimumSamplingPeriod());

  if ((WiFiMulti.run() == WL_CONNECTED)) {

    float humidity = dht.getHumidity();
    float temperature = dht.getTemperature();
    WiFiClient client;
    HTTPClient http;

     if (http.begin(client, TEMP_SENSOR+String(temperature))) { 
      int httpCode = http.GET();
      if (httpCode > 0) {
        if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
          String payload = http.getString();
        }
      }
      http.end();
      }

    if (http.begin(client, HUMIDITY_SENSOR+String(humidity))) { 
      int httpCode = http.GET();
      if (httpCode > 0) {
        if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
          String payload = http.getString();
        }
      }
      http.end();
    }


    if (http.begin(client, DHT_LED)) { 
      int httpCode = http.GET();
      if (httpCode > 0) {
        if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
          String payload = http.getString();
          if (payload=="1"){
              digitalWrite(LED_Pin, HIGH);
            }
            else if (payload.equals("0")){
             digitalWrite(LED_Pin, LOW);
            }
            else{
              digitalWrite(LED_Pin, LOW);
            }
        }
      }
      http.end();
    }
  } 
}
  1. Open Temperature and Humidity plots

  2. Turn on/off LED in control gadget

  3. Fetch Temparature and Humidity data Python

pip install openioe
from openioe.openioe_apis import *
oi=openioe_apis()

oi.APIKey='xxxxxxxxxx'
oi.DeviceID=xxx
oi.DevicePin=xxx
SensorData,ResposeCode=oi.ReadValue()
print(SensorData)
print(ResposeCode)
  1. Control LED using Python

oi.APIKey='xxxxxxxxxx'
oi.DeviceID=12
oi.DevicePin=27
oi.Data=0
SensorData,ResposeCode=oi.WriteValue()
print(SensorData)
print(ResposeCode)

Last updated