Air Meter Making #3: Using Thingspeak

Air Meter Making #3: Using Thingspeak © GPL3+

Use ESP-01 and DHT 11 to send temperature and humidity data to the server.

  • 1,496 views
  • 0 comments
  • 3 respects

Components and supplies

Apps and online services

About this project

If you saw what I've posted before, now you know how to use DHT 11 and ESP-01 modules.

Now, using both modules, I will send the temperature and humidity data measured by DHT 11 to the server using ESP-01. To send data to the server, you should use a site called Thingspeak. First, go to the site called "Thingspeak" and sign up for membership.

If you have completed membership, you will see the following screen. Then create a new channel.

Once you have created a new channel, set the name, purpose, etc. of this channel. In this project, the name of the channel is called 'temperature and humidity measurement' because it is aimed to measure temperature and humidity. In addition, two fields have been marked separately for displaying temperature and humidity values.

If you have completed the channel setting, you can view the newly added channel on my channel.

Click on the 'Temperature and Humidity' channel to view the two objects divided into ‘Temperature’ and ‘humidity’. Here, press API Keys to confirm my Write API Key.

Copy my Write API Key and add line 12 of the code:

'String apiKey = "Thingspeak channel write API Key"; 

Paste in the part. (If you do not have the <DHT.h> file, download it here: http://deneb21.tistory.com/attachment/cfile26.uf@21324339574F9E3A184C6F.zip)

When you enter the code in the Arduino IDE and upload it, you will notice that the data was successfully transferred as shown in the screen below.

I have seen how to send data to Thingspeak in this way. Next, we will make an air meter in earnest.

Until then, this is ParkMoonsu! See you next time!

Note: sites and source of the file: http://deneb21.tistory.com/

Code

Code to send data to ThingspeakArduino
Enter your own Thingspeak channel API key! /
Download the <DHT.h> file and add it to the Arduino IDE library
#include <SoftwareSerial.h>
#include <stdlib.h>
#include <DHT.h>
 
#define DHTPIN 2        // Setting the SDA pin
#define DHTTYPE DHT11   // DHT11 (AM2302) Sensor type setting
 
// Upload Notification LED Setting (Adunono On Board LED)
int ledPin = 13;
 
// Enter Write API key for your own thingspeak channel
String apiKey = "Thingspeak channel write API Key";
 
SoftwareSerial ser(10, 11); // RX / TX configuration, serial object creation
DHT dht(DHTPIN, DHTTYPE);
 
void setup() {
  dht.begin();
  // Notification LED output setting
  pinMode(ledPin, OUTPUT);
  // Serial communication speed 9600 baud rate setting    
  Serial.begin(9600);
  // Start the software serial
  ser.begin(9600);
  // ESP8266 Reset
  ser.println("AT+RST");
}
 
void loop() {
  // blink LED on board
  digitalWrite(ledPin, HIGH);   
  delay(200);               
  digitalWrite(ledPin, LOW);
 
  // Read DHT11 value
  float temp = dht.readTemperature();
  float humi = dht.readHumidity();
 
  // String Conversion
  char buf[16];
  String strTemp = dtostrf(temp, 4, 1, buf);
  String strHumi = dtostrf(humi, 4, 1, buf);
  
  Serial.println(strTemp);
  Serial.println(strHumi);
  
  // TCP connection
  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += "184.106.153.149"; // api.thingspeak.com Access IP
  cmd += "\",80";           // api.thingspeak.com access port, 80
  ser.println(cmd);
   
  if(ser.find("Error")){
    Serial.println("AT+CIPSTART error");
    return;
  }
  
  // Set String, Data to send by GET method
  String getStr = "GET /update?api_key=";
  getStr += apiKey;
  getStr +="&field1=";
  getStr += String(strTemp);
  getStr +="&field2=";
  getStr += String(strHumi);
  getStr += "\r\n\r\n";
 
  // Send Data
  cmd = "AT+CIPSEND=";
  cmd += String(getStr.length());
  ser.println(cmd);
 
  if(ser.find(">")){
    ser.print(getStr);
  }
  else{
    ser.println("AT+CIPCLOSE");
    // alert user
    Serial.println("AT+CIPCLOSE");
  }
    
  // Thingspeak delay to meet 15 seconds minimum upload interval
  delay(16000);  
}

Schematics

Schematics to send data to Thingspeak
DHT 22 is used in this circuit diagram. However, DHT11 may be used.
Abc dc9tpnev1q

Comments

Similar projects you might like

Air Meter Making #2: Use the Arduino DHT 11 Module

by 4 developers

  • 3,836 views
  • 4 comments
  • 10 respects

Air Meter Making #1: Use The Arduino Wi-Fi Module ESP-01

by 4 developers

  • 9,110 views
  • 1 comment
  • 12 respects

Air Meter Making #4: Complete

Project tutorial by 4 developers

  • 5,162 views
  • 2 comments
  • 10 respects

Temperature and humidity meter (iot)

Project showcase by 윤원호 and gledel

  • 9,973 views
  • 1 comment
  • 16 respects

IoT Made Easy w/ UNO, ESP-01, ThingSpeak & MIT App Inventor

Project tutorial by MJRoBot

  • 37,061 views
  • 16 comments
  • 66 respects

Weather Station with Thingspeak

Project showcase by Tittiamo

  • 5,372 views
  • 3 comments
  • 8 respects
Add projectSign up / Login