ElectronParade

← Back to Academy

Welcome back, makers! Over the last few lessons, we’ve successfully wired up sensors and collected a treasure trove of data. But what good is all that environmental data if it’s trapped inside your microcontroller’s serial monitor?

Today, we’re taking our projects to the cloud. We’ll learn how to send our temperature, humidity, or light readings to the internet and visualize them using beautiful, interactive dashboards. Let’s get that data on a screen!

IoT Dashboards

Why Use a Cloud Dashboard?

Instead of building a web server from scratch on your ESP32 or Arduino, using an IoT platform saves time and provides slick mobile and web interfaces out of the box. Here are the tools we’ll be looking at:

Code Example: Sending Data to Adafruit IO

Here is a basic snippet demonstrating how to publish a simulated temperature reading to an Adafruit IO feed using an ESP32 and the MQTT protocol.

#include <WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"

// WiFi credentials
#define WLAN_SSID       "YOUR_SSID"
#define WLAN_PASS       "YOUR_PASSWORD"

// Adafruit IO setup
#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883
#define AIO_USERNAME    "YOUR_AIO_USERNAME"
#define AIO_KEY         "YOUR_AIO_KEY"

WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);

// Define a feed called 'temperature'
Adafruit_MQTT_Publish temperature = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/temperature");

void setup() {
  Serial.begin(115200);
  WiFi.begin(WLAN_SSID, WLAN_PASS);
  
  Serial.print("Connecting to WiFi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println(" Connected!");
}

void loop() {
  // Ensure MQTT connection is alive (reconnection code omitted for brevity)
  
  // Read your sensor (simulated here)
  float tempValue = 24.5;

  // Publish data to the cloud
  Serial.print(F("\nSending temperature val: "));
  Serial.print(tempValue);
  Serial.print("...");
  
  if (! temperature.publish(tempValue)) {
    Serial.println(F("Failed"));
  } else {
    Serial.println(F("OK!"));
  }

  // Wait 10 seconds before the next update to respect rate limits
  delay(10000); 
}

Once this code is running, your microcontroller will quietly stream data to the internet, and your Adafruit IO dashboard will light up with real-time graphs and dials! Next week, we’ll look at sending commands back from the dashboard to control physical hardware.

Hardware You’ll Need

To follow along with this lesson, you’ll need the following components: