Collecting Environmental Sensor Data with Consentium IoT Cloud and ESP32

In today’s world of connected devices, environmental monitoring is more accessible and powerful than ever. Whether you're measuring air quality indoors or monitoring light levels in a greenhouse, the Internet of Things (IoT) makes it possible to build smart, connected systems quickly.
In this tutorial, you'll learn how to use an ESP32, a BME680 multi-sensor, and a BH1750 light sensor to collect environmental data and send it to the Consentium IoT Cloud. We’ll use the ConsentiumThings SDK to make integration seamless and also support OTA firmware updates remotely.
🧰 What You’ll Need
- ESP32 Dev Board
- BME680 Sensor – for temperature, humidity, pressure, gas, and altitude
- BH1750 Light Sensor – for measuring light intensity in lux
- Jumper wires, breadboard
- Arduino IDE or PlatformIO
- A Consentium IoT Cloud account (get your API keys from the dashboard)
⚡ Wiring the Sensors
Connect both sensors using I2C:
BME680
- VIN → 3.3V
- GND → GND
- SDA → GPIO21
- SCL → GPIO22
BH1750
- VCC → 3.3V
- GND → GND
- SDA → GPIO21
- SCL → GPIO22
🧑💻 About the ConsentiumThings SDK
The ConsentiumThings
SDK handles:
- Connecting to WiFi
- Sending sensor data to the cloud using REST
- Managing firmware versioning
- OTA updates from the Consentium Cloud
Just plug in your API keys and go!
🔁 What the Device Does
Every 7 seconds, the device:
- Reads sensor values (temperature, humidity, pressure, gas resistance, light intensity, and calculated altitude)
- Sends this data to the Consentium IoT Cloud
- Every 10 loops, it checks if a firmware update is available
📦 The Complete Code
#include <ConsentiumThingsExp.h>
#include <BH1750.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME680 bme(&Wire); // I2C
BH1750 lightMeter;
// Define firmware version
#define FIRMWARE_VERSION "0.3"
// Create ConsentiumThings object with firmware version
ConsentiumThingsDalton board(FIRMWARE_VERSION);
// Define WiFi credentials
const char *ssid = "YOUR_WIFI_SSID"; // WiFi SSID
const char *pass = "YOUR_WIFI_PASSWORD"; // WiFi password
// Define API keys
const char *SendApiKey = "YOUR_API_KEY"; // API key for sending data
const char *BoardApiKey = "YOUR_BOARD_API_KEY"; // API key for the board
// Define the interval for data sending
constexpr int interval = 7000; // 7 seconds
const int updateInterval = 10; // Check for OTA updates every 10 cycles
// Loop cycle counter
int loopCounter = 0;
void setup() {
Serial.begin(115200);
Serial.println("Consentium IoT - Edge Board Library");
Serial.println("------------------------------------");
Serial.println("Initializing ConsentiumThings Board...");
// Begin WiFi connection
board.initWiFi(ssid, pass);
// Initialize the board for sending data
board.beginSend(SendApiKey, BoardApiKey);
// Enable OTA updates
board.beginOTA(ReceiveApiKey, BoardApiKey);
Serial.println("ConsentiumThings Board Initialized!");
Serial.println("------------------------------------");
Serial.println();
// Initialize I2C and sensors
Wire.begin();
lightMeter.begin();
bme.begin();
// BME680 configuration
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320°C for 150 ms
}
void loop() {
if (!bme.performReading()) {
Serial.println("Failed to perform BME680 reading :(");
return;
}
// Read sensor values
float lux = lightMeter.readLightLevel();
float temp = bme.temperature;
float press = bme.pressure / 100.0;
float humi = bme.humidity;
float gas = bme.gas_resistance / 1000.0; // in kΩ
float alt = bme.readAltitude(SEALEVELPRESSURE_HPA);
// Pack sensor data
vector<double> sensorValues = {temp, humi, press, lux, alt, gas};
const char* sensorInfo[] = {"Temperature", "Humidity", "Pressure", "Light", "Altitude", "Vooc"};
// Send to Consentium Cloud
board.sendData(sensorValues, sensorInfo, LOW_PRE);
// Increment loop counter
loopCounter++;
// Periodic OTA check
if (loopCounter >= updateInterval) {
Serial.println("[Consentium IoT] Checking for OTA updates...");
board.checkAndPerformUpdate();
loopCounter = 0;
}
// Wait before next reading
delay(interval);
}
🌐 Cloud Dashboard
Once your device is online, the Consentium IoT dashboard allows you to:
- Visualise data trends in real time
- Trigger OTA updates with new firmware
- Export or integrate the data into apps or analytics platforms
📌 Sign up or log in at: consentiumiot.com
📝 Final Thoughts
With just an ESP32 and a couple of I2C sensors, you can build a powerful environmental monitor that:
- Streams real-time data to the cloud
- Receives remote updates
- Runs unattended for months
This is ideal for smart agriculture, indoor air quality monitoring, classroom management, and more.