# Send DHT-22 data to thingspeak using nodemcu esp8266 and arduino uno

**URL:** <https://forum.arduino.cc/t/send-dht-22-data-to-thingspeak-using-nodemcu-esp8266-and-arduino-uno/1147886>\
**Category:** Programming\
**Created:** [July 14, 2023, 3:49am UTC](https://forum.arduino.cc/t/send-dht-22-data-to-thingspeak-using-nodemcu-esp8266-and-arduino-uno/1147886 "2023-07-14T03:49:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hydro23](https://avatars.discourse-cdn.com/v4/letter/h/958977/32.png) [@hydro23](https://forum.arduino.cc/u/hydro23)\
**Post date:** [July 14, 2023, 3:49am UTC](https://forum.arduino.cc/t/send-dht-22-data-to-thingspeak-using-nodemcu-esp8266-and-arduino-uno/1147886/1 "2023-07-14T03:49:26Z")

</div>

I want to send sensor data to thingspeak using nodemcu esp8266 and arduino uno. So, the sensor only connect to arduino uno and i use serial communication between nodemcu esp8266 and arduino so that data from arduino can be read by nodemcu esp8266, and nodemcu esp8266 will send the data to thingspeak. I'm getting data on serial monitor but the data is not visible on thingspeak server. I have entered the credential code correctly. What should i do to make the sensor data visible on Thingspeak?

This is what I've done :

```arduino
Code for Arduino Uno :
#include <DHT.h>
#define dhtPin 3
#define dhtType DHT22
DHT dht(dhtPin, dhtType);

void setup() {
  Serial.begin(115200);
  dht.begin();
}

void loop() {
  float t = dht.readTemperature();
  float h = dht.readHumidity();
  if (isnan(t)|| isnan(h)) {
    Serial.println("No Data");
    delay(2000);
  }

  Serial.print("Temperature : ");
  Serial.print(t);
  Serial.print("Humidity : ");
  Serial.print(h);

  Serial.println();
  delay(5000);
}

Code for NodeMCU ESP8266 :
#include<ESP8266WiFi.h>
#include<WiFiClient.h>
#include<ESP8266HTTPClient.h>
#include <ThingSpeak.h>

String URL = "http://api.thingspeak.com/update?api_key=APIKEY&field1=";
void setup() {
  Serial.begin(115200);
  WiFi.disconnect();
  delay(2000);
  Serial.print("Start connection");
  WiFi.begin("SSID","PASSWORD");
  while((!(WiFi.status()==WL_CONNECTED))){
    delay(500);
    Serial.print("..");
  }
  Serial.println("Connected");

}

void loop() {
  if(Serial.available()>0){
    String data=Serial.readStringUntil('\n');
    Serial.println(data);
    int comma = data.indexOf(',');
    if(comma!=-1){
      float t = data.substring(0,comma).toFloat();
      float h = data.substring(comma+1).toFloat();
      Serial.print(t);
      Serial.println(h);
      sendData(t,h);

    }
  }
}

void sendData(float t, float h){
  WiFiClient client;
  HTTPClient http;
  String newUrl=URL+String(t)+"&field2="+String(h);
  http.begin(client,newUrl);
  int responsecode=http.GET();
  String data = http.getString();
  Serial.println(data);
  http.end();
  delay(5000);
}

```

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [July 14, 2023, 8:39am UTC](https://forum.arduino.cc/t/send-dht-22-data-to-thingspeak-using-nodemcu-esp8266-and-arduino-uno/1147886/2 "2023-07-14T08:39:06Z")

</div>

Why not use a controller that can do both sensor reading and Thingspeak communication?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 10, 2024, 8:39am UTC](https://forum.arduino.cc/t/send-dht-22-data-to-thingspeak-using-nodemcu-esp8266-and-arduino-uno/1147886/3 "2024-01-10T08:39:17Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
