Connecting DHT11 Sensor to Thingspeak Cloud Using Particle Photon

Introduction

  • Thingspeak is an analytics platform service which can be used for various purposes like to control things remotely, to visualize and analyse live data stream in cloud, etc.
  • It is mainly designed for IoT based application which needs instant visualization of data for analysis. Thingspeak has ability to execute Matlab code which can help us to perform online analysis and processing of data.

Application

  • Let’s develop an IoT based application in which we will send DHT11 Sensor’s data (temperature and humidity) to the Thingspeak cloud/server. Here, we are sending temperature (in Celsius) and humidity using Particle Photon development board.
  • For developing above application, we have interfaced DHT11 sensor to the Particle Photon shown interfacing below.
  • Particle photon will read humidity and temperature form DHT11 continuously and upload/send it to the Thingspeak cloud.
  • To know about how to interface DHT11 sensor with Particle Photon, you can refer DHT11 sensor Interfacing with Particle Photon.

Interfacing Diagram

DHT11 Interfacing with Particle Photon

DHT11 Interfacing with Particle Photon

To build above application, we have used two library given as follows,

  • Adafruit_DHT
  • Thingspeak

Adafruit_DHT library is developed by Adafruit which can be used to read temperature and humidity data from DHT (DHT11, DHT21, DHT22) sensor. This library is developed for Particle Photon/Core.

Thingspeak library is developed to POST data to the Thingspeak cloud/server and to read data from Thingspeak cloud/server.

Using above two libraries, we can read data from DHT11 sensor and upload it to Thingspeak server.

Just we have to include this library to our Project.

Before starting with program, we should create account on Thingspeak for visualizing data on it.

Just sign up and create channel on Thingspeak cloud. We have below channel and write key on Thingspeak for data send and receive.

  • channel ID is = 84322
  • Write Key is = 5JLCK7ND2D2SNSJF

Note:  Do not forget to tick Make Public field in channel setting option on your Thingspeak channel. It makes channel available to use as public. This allows any user to access channel data without any username & password.

To learn more about Thingspeak refer link https://thingspeak.com/pages/learn_more

Also, create a file to write a program to read data and send it to Thingspeak server. To know about how to create app and add library to it, you can refer create app and add library on Particle Photon.

The code for the Particle Photon device is available in Source Code section at the end of this page.

Program

/*
	Send temperature and Humidity information to the Thingspeak Server 
	by interfacing DHT11 Sensor with Particle Photon.
	http://www.electronicwings.com
*/

#include "ThingSpeak.h"

TCPClient client;

#include "Adafruit_DHT.h"

unsigned long myChannelNumber = 84322;		/*Thingspeak channel id*/
const char * myWriteAPIKey = "5JLCK7ND2D2SNSJF";/*Channel's write API key*/

DHT dht(D2, DHT11);

void setup() {
    ThingSpeak.begin(client);
    dht.begin();
}

void loop() {
    
    delay(500);
    
    /*Read humidity*/
    float humidity = dht.getHumidity();
    /* Read temperature as Celsius */
    float temperature = dht.getTempCelcius();

    /* Check if any reads failed and exit early (to try again)*/
    if (isnan(humidity) || isnan(temperature)) {
        Serial.println("Failed to read from DHT sensor!");
	return;
	}

    /* Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different pieces of information in a channel.  */
    /*Here, we write Humidity to field 1 and temperature to field 2*/
    ThingSpeak.writeField(myChannelNumber, 1, humidity, myWriteAPIKey);
    delay(15000); /* ThingSpeak will only accept updates every 15 seconds*/
  
    ThingSpeak.writeField(myChannelNumber, 2, temperature, myWriteAPIKey);
    delay(15000); /* ThingSpeak will only accept updates every 15 seconds.*/
  
    Serial.print("Humidity= ");
    Serial.println(humidity);
    Serial.print("Temperature= ");
    Serial.println(temperature);
}

 

Output at Thingspeak Server

Humidity at Thingspeak channel send by Particle Photon

Temperature at Thingspeak send by Particle Photon

 


Components Used

Particle Photon
PHNTRAYH
1
DHT11
DHT11 is a single wire digital humidity and temperature sensor, which gives relative humidity in percentage and temperature in degree Celsius.
1

Downloads

Connect DHT11 to Thingspeak Project FIle Download
Ad