# Temperature-Humidity Monitoring & LED Control

{% embed url="<https://youtu.be/guov3_6X9Vs>" %}

1. **Make the circuit as shown below,**

<figure><img src="/files/b3IHPX8uvnSphKU0oM9w" alt="" width="375"><figcaption></figcaption></figure>

2. **Create IoT devices**

Login to OpenIoE,&#x20;

Compoents >> IoT Devices >> Add IoT Device

Names: Temperature, Humidity, and LED&#x20;

Data Format: Value, Hardware: Generic

3. **Creates plots, and control**

Components >> Plots >> Add Plot

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

Control Name: LED, Type: On/Off

4. **Upload the program to Microcontroller**

```arduino
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();
    }
  } 
}
```

5. **Open Temperature and Humidity plots**
6. **Turn on/off LED in control gadget**
7. **Fetch Temparature and Humidity data Python**

```python
pip install openioe
```

```python
from openioe.openioe_apis import *
oi=openioe_apis()
```

```python

oi.APIKey='xxxxxxxxxx'
oi.DeviceID=xxx
oi.DevicePin=xxx
SensorData,ResposeCode=oi.ReadValue()
print(SensorData)
print(ResposeCode)
```

8. **Control LED using Python**

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.openioe.in/open-ioe-app/examples/temperature-humidity-monitoring-and-led-control.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
