Free delivery on orders above Rs 900 | Single Delivery charges for Multiple Items

Cart

Your Cart is Empty

Back To Shop

Cart

Your Cart is Empty

Back To Shop

ESP32 temperature sensor tutorial: How to Stream real-time data to ThingSpeak

Streaming real-time temperature data from an ESP32 to ThingSpeak involves setting up the ESP32 with a temperature sensor and then using the ThingSpeak API to send the data to your ThingSpeak channel. Below is a step-by-step tutorial on how to achieve this:

Hardware Setup:

 

  1. Materials Needed:
  2. Connections:
    • Connect the temperature sensor to the ESP32 as per the sensor’s datasheet.
    • For example, if you’re using a DHT22 sensor:
    • Connect the VCC pin to 3.3V.
    • Connect the GND pin to GND.
    • Connect the data pin to a GPIO pin on the ESP32 (e.g., GPIO 4).

Software Setup:

 

  1. Arduino IDE:
    • Make sure you have the Arduino IDE installed on your computer.
    • Install the ESP32 board support in the Arduino IDE if you haven’t already. You can find instructions on the official ESP32 GitHub repository.
  2. Libraries:
  3. Coding:
    • Write the code to read temperature data from the sensor and send it to ThingSpeak using the ESP32‘s Wi-Fi capabilities. Below is a sample code snippet using the DHT22 sensor and the ThingSpeak library:

#include <WiFi.h>
#include <DHT.h>
#include <ThingSpeak.h>

#define WIFI_SSID “your_wifi_ssid”
#define WIFI_PASS “your_wifi_password”

#define DHTPIN 4 // DHT22 data pin
#define DHTTYPE DHT22 // DHT sensor type

DHT dht(DHTPIN, DHTTYPE);

unsigned long previousMillis = 0;
const long interval = 60000; // Send data every 60 seconds

const char *thingSpeakApiKey = “your_thingspeak_api_key”;
const unsigned long channelID = your_channel_id;

void setup() {
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println(“Connecting to WiFi…”);
}
Serial.println(“Connected to WiFi”);

ThingSpeak.begin(thingSpeakApiKey);
dht.begin();
}

void loop() {
unsigned long currentMillis = millis();
if (currentMillis – previousMillis >= interval) {
previousMillis = currentMillis;

float temperature = dht.readTemperature();

if (!isnan(temperature)) {
ThingSpeak.writeField(channelID, 1, temperature, thingSpeakApiKey);
Serial.print(“Temperature: “);
Serial.println(temperature);
} else {
Serial.println(“Failed to read temperature from sensor”);
}
}
}

Replace your_wifi_ssid, your_wifi_password, your_thingspeak_api_key, and your_channel_id with your actual values.

  1. ThingSpeak Configuration:
    • Create a ThingSpeak account if you don’t have one.
    • Create a new channel and add a field named “Temperature.”
    • Note down your ThingSpeak channel ID and API key.

Uploading and Testing:

 

  1. Upload the code to your ESP32 using the Arduino IDE.

  2. Monitor the Serial Monitor in the Arduino IDE to see the temperature readings and the status of the data upload.

  1. Visit your ThingSpeak channel to see the real-time temperature data being plotted.

That’s it! You’ve successfully set up an ESP32 to stream real-time temperature data to ThingSpeak. This tutorial provides a basic example; you can enhance it by adding error handling, more sensor types, and additional fields to your ThingSpeak channel for various data readings.

Cart

Your Cart is Empty

Back To Shop
GET DISCOUNT CODE

It will take just few seconds to claim 7% Discount, After Submitting check Email for Coupon code.

    X
    GET DISCOUNT CODE