The Adafruit.io

Adafruit.io is a cloud-based IoT platform that enables real-time data visualization and device control through web dashboards. It provides free service with an intuitive interface for connecting IoT devices via WiFi, using authentication keys and feeds to manage data flow between devices and dashboards.

In this article, we demonstrate how to connect an ESP32 microcontroller with a BMP180 sensor to an Adafruit.io dashboard for monitoring environmental data and controlling an LED remotely.

Required Components

  • ESP32 development board
  • BMP180 sensor (temperature, pressure, altitude)
  • Blue LED
  • Breadboard and jumper wires
  • Adafruit.io account

Circuit Connections

Connect the components as follows

  • BMP180 to ESP32: SCL ? D22, SDA ? D21, VCC ? 3.3V, GND ? GND
  • LED to ESP32: Positive ? D18 (through resistor), Negative ? GND
ESP32 with BMP180 and LED Circuit ESP32 Development Board BMP180 Sensor LED SCL?D22 SDA?D21 D18?LED VCC?3.3V, GND?GND

Adafruit.io Setup

Follow these steps to configure your Adafruit.io account

  1. Visit https://io.adafruit.com/ and create an account
  2. Navigate to "Feeds" and create four feeds: temperature, pressure, altitude, and bluelight
  3. Create a dashboard and add blocks for each feed
  4. Note your AIO Key from the account settings
Installation Required: Install the following libraries in Arduino IDE:
  • Adafruit BMP085 Library
  • Adafruit MQTT Library
  • WiFi Library (included with ESP32)
Go to Tools ? Manage Libraries and search for these libraries to install.

Complete Arduino Code

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

/************************* WiFi Configuration *********************************/
#define WLAN_SSID    "Your_WiFi_SSID"
#define WLAN_PASS    "Your_WiFi_Password"

/************************* Adafruit.io Setup *********************************/
#define AIO_SERVER    "io.adafruit.com"
#define AIO_SERVERPORT 1883
#define AIO_USERNAME "Your_Adafruit_Username"
#define AIO_KEY "Your_Adafruit_AIO_Key"

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

// Feed definitions
Adafruit_MQTT_Publish temperature = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/temperature");
Adafruit_MQTT_Publish pressure = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/pressure");
Adafruit_MQTT_Publish altitude = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/altitude");
Adafruit_MQTT_Subscribe bluelight = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/bluelight");

const int BLUE_LED = 18;
Adafruit_BMP085 bmp;

void setup() {
    Serial.begin(9600);
    pinMode(BLUE_LED, OUTPUT);
    digitalWrite(BLUE_LED, LOW);
    
    // Initialize BMP180 sensor
    if (!bmp.begin()) {
        Serial.println("BMP180 sensor not found!");
        while (1);
    }
    
    // Connect to WiFi
    WiFi.begin(WLAN_SSID, WLAN_PASS);
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println("\nWiFi connected!");
    Serial.println(WiFi.localIP());
    
    mqtt.subscribe(&bluelight);
}

void loop() {
    MQTT_connect();
    
    // Read sensor data
    float temp = bmp.readTemperature();
    float press = bmp.readPressure();
    float alt = bmp.readAltitude();
    
    // Publish sensor data
    temperature.publish(temp);
    pressure.publish(press);
    altitude.publish(alt);
    
    // Check for LED control commands
    Adafruit_MQTT_Subscribe *subscription;
    while ((subscription = mqtt.readSubscription(1000))) {
        if (subscription == &bluelight) {
            String command = (char*)bluelight.lastread;
            if (command == "ON") {
                digitalWrite(BLUE_LED, HIGH);
            } else if (command == "OFF") {
                digitalWrite(BLUE_LED, LOW);
            }
        }
    }
    
    delay(5000); // Send data every 5 seconds
}

void MQTT_connect() {
    if (mqtt.connected()) return;
    
    Serial.print("Connecting to MQTT...");
    while (mqtt.connect() != 0) {
        Serial.println("MQTT connection failed, retrying...");
        mqtt.disconnect();
        delay(5000);
    }
    Serial.println("MQTT connected!");
}

Dashboard Configuration

Create blocks in your Adafruit.io dashboard

Feed Block Type Purpose
temperature Gauge Display temperature in °C
pressure Line Chart Show pressure trends
altitude Text Block Show current altitude
bluelight Button/Toggle Control LED (ON/OFF)

Expected Results

After uploading the code and running the system, you should observe

  • Real-time sensor data (temperature, pressure, altitude) displayed on the dashboard
  • LED control functionality through the dashboard button
  • Serial monitor showing connection status and sensor readings
  • Data updates every 5 seconds on the Adafruit.io dashboard

Conclusion

Adafruit.io provides an excellent platform for IoT projects, offering easy device connectivity and intuitive dashboard creation. This example demonstrates basic sensor monitoring and remote device control, which can be extended for more complex IoT applications.

Updated on: 2026-03-15T14:29:32+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements