Jump to content

MDM331AID/Experiment 8

From cognifront

Experiment: Transmit sensor data between an IoT device and a server

Aim

To develop an IoT application that uses the communication protocol to transmit sensor data between an IoT device and a server

Objectives

  • To understand the concept of IoT-based sensor data communication.
  • To interface an DHT11 temperature sensor with an ESP32 development board.
  • To read temperature data from the DHT11 sensor using the ESP32.
  • To connect the ESP32 to a Wi-Fi network and transmit sensor data to a cloud server.
  • To store and log the transmitted sensor data in CSV format.

Components Required

Sr. No. Component Quantity
1 ESP32 development board 1
2 DHT11 temperature sensor 1
3 USB cable 1
4 Patch cords / jumper wires As required
5 Wi-Fi network / Internet connection 1
6 Computer with Arduino IDE 1
7 Cloud IoT platform / server (Cognifront IoT Cloud) 1 account per user/student

Theory

Internet of Things (IoT) is a technology in which physical devices equipped with sensors, processing units and communication capabilities collect and exchange data over a network. IoT enables sensor data to be transmitted to a remote server or cloud platform for storage and monitoring.

An IoT-based sensor data transmission system generally consists of:

  • Sensor: Measures physical parameters and provides the measured data to the IoT device. In this experiment, the DHT11 is used to measure temperature and humidity.
  • IoT device / Controller: Reads the sensor data, processes it and provides network connectivity. In this experiment, the ESP32 acts as the IoT device.
  • Communication network: Provides connectivity between the IoT device and the server or cloud platform. The ESP32 uses Wi-Fi for communication.
  • Cloud server: Receives and stores the sensor data transmitted by the ESP32. The cloud platform used in this experiment provides facilities for storing the sensor data.
  • Data storage: The collected sensor data can be stored on the server and exported in CSV format for further use.

DHT11 is a digital temperature and humidity sensor that measures temperature and relative humidity. Unlike an analog temperature sensor such as the LM35, the DHT11 provides digital sensor data through its data pin. The sensor contains temperature and humidity sensing elements along with internal signal-processing circuitry.

The ESP32 communicates with the DHT11 through its digital data pin. It reads the temperature and humidity values from the sensor and processes the received data. The ESP32 then connects to a Wi-Fi network and transmits the sensor data to the cloud server using the configured cloud communication mechanism.

The cloud server receives the temperature and humidity readings and stores them as data records. In this experiment, the sensor readings are collected at regular intervals and stored on the server. The stored data can be exported as a CSV (Comma-Separated Values) file, allowing the collected sensor data to be saved in a standard tabular format.

The overall data flow of the system is:

DHT11 Temperature & Humidity Sensor
                ↓
              ESP32
                ↓
              Wi-Fi
                ↓
          Cloud Server
                ↓
        Data Storage / CSV

This type of IoT-based data logging system can be used for applications such as environmental monitoring, indoor temperature and humidity monitoring, weather monitoring and other systems where sensor measurements need to be collected remotely and stored for later use.

Actions:

  1. Write ESP32 code to read temperature data from the DHT11 sensor and send it to a cloud server using Wi-Fi.
  2. Display this reading on a web-based dashboard in real-time.
  3. Download readings data in CSV format.

Setting Up Cloud

   Step 1
   
Step 1
Visit www.cognifront.com and scroll down to the footer section.
   Step 2
   
Step 2
Click on the IoT Cloud option.
   Step 3
   
Step 3
Click on Login or Sign Up / Registration to access your account.
   Step 4
   
Step 4
After logging in, navigate to the Dashboard section.
   Step 5
   
Step 5
Click on Create New App to start a new cloud application.
   Step 6
   
Step 6
Enter your app name — for example, Data Logger.
   Step 7
   
Step 7
Your dashboard will update and display the newly created app.
   Step 8
   
Step 8
Each app shows buttons for Edit, Delete, Launch, and API Key.
   Step 9
   
Step 9
Click Edit App to open your app and create variables.
   Step 10
   
Step 10
Click on Create Variable to define a new data variable.
   Step 11
   
Step 11
Enter a variable name and select its type (defines input/output behavior).
   Step 12
   
Step 12
For example: Name – LM35, Type – Continuous.
   Step 13
   
Step 13
Return to the home page and click View App to launch your application. Congratulations! Your cloud app is now ready.
   Step 14
   
Step 14
Open the program folder — you will find two files: eecit-exp-06-data-logger.ino (main program) and cogcloudesp.h (library header file). Open the .ino file in Arduino IDE.
   Step 15
   
Step 15
Ensure the cogcloudesp.h header file is included properly in your project.
   Step 16
   
Step 16
Update your code with your Wi-Fi SSID, password, and API key. A stable internet connection is required.
   Step 17
   
Step 17
Change the variable name in your code to match the one you created in the cloud app.
   Step 18
   
Step 18
Connect your ESP32 to your computer and upload the code.
   Step 19
   
Step 19
Open or launch your cloud app to visualize real-time sensor data from the LM35.
   Step 20
   
Step 20
In the app settings, click the Download .CSV button to export data.
   Step 21
   
Step 21
Set the desired time range for data export, or leave it blank to download all records.
   Step 22
   
Step 22
Open the downloaded .CSV file in Microsoft Excel to view the logged data.

Circuit & Board Connections

   Circuit Diagram
   
Circuit Diagram
The complete connection diagram of ESP32-based setup.
   Board Connections
   
Board Connections
Actual board wiring layout showing sensor and module connections.

Pin Connections

The following connections are based on the ESP32 and DHT11 configuration used in the program.

DHT11 Pin ESP32 Pin Description
GND GND Ground connection
VCC VIN (5V supply) Power supply
DATA / VOUT GPIO4 Analog temperature output

The USB cable connects the ESP32 to the computer. The computer runs the Arduino IDE and uploads your code to ESP32. ⚠️ Disconnect your ESP32 from the computer while making or removing component connections.

ESP32 Code

// © 2026, Cognifront. Member of The IoT Kits Family.
// DHT11 Temperature Data Logging Using ESP32 and Cognifront Cloud

#include "cogcloudesp.h"
#include <DHT.h>

#define DHT_PIN 4
#define DHT_TYPE DHT11

DHT dht(DHT_PIN, DHT_TYPE);

String ssid = "********";                 // Wi-Fi / hotspot name
String pass = "********";                 // Wi-Fi / hotspot password

String apikey = "YOUR_API_KEY_HERE";      // API key from Cognifront Cloud

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

    dht.begin();

    // Initialize Cognifront Cloud
    cogInitCloud(ssid, pass, apikey);

    Serial.println("DHT11 Temperature Monitoring Started");
}

void loop()
{
    // Handle cloud communication
    cogAppLoop();

    // Read temperature in Celsius
    float temperature = dht.readTemperature();

    // Check for sensor reading failure
    if (isnan(temperature))
    {
        Serial.println("Failed to read temperature from DHT11");
        delay(2000);
        return;
    }

    // Display temperature on Serial Monitor
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" °C");

    // Send temperature to Cognifront Cloud
    cogStoreCloudVariable("DHT11", String(temperature, 2));

    delay(2000);
}


 ⬇ Click Here to Download Code File
 
(Contains ESP32 source code)
Board Connections
Connect your ESP32 to your computer and upload the code make sure right port selected.

Observation

  • The ESP32 successfully reads temperature data from the DHT11 sensor.
  • Data is properly being logged in CSV file, and file is downloaded successfully.

Conclusion

This experiment demonstrates how to log real-time sensor data from ESP32 to a computer using cloud communication.


Real Life Example

Condition Monitoring in Machines and Data Logging: Sensors collect data such as vibration, temperature, or pressure from mechanical systems, which is logged and analysed for predictive maintenance and fault diagnosis. Also this data can be fed for training a machine learning model.