Negar Rafieedolatabadi
Published

Smart Coffee Mug with Sensirion STS40 Temperature

With SensiMug and its STS40 sensor, your coffee stays at the perfect temperature from the first sip to the last.

IntermediateProtipOver 2 days246
Smart Coffee Mug with Sensirion STS40 Temperature

Things used in this project

Hardware components

ESP32
Espressif ESP32
×1
youngneer 5v relay
×1
Sensirion sts40 temperature sensor
×1
warmer coaster
×1
coffee mug
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Android Studio
Android Studio

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Custom parts and enclosures

Enclosure

LeMotech Junction Box, Electrical Box IP55 Water Resistant Dustproof ABS Plastic Project Enclosure for Electronics White 3.1 x 3.1 x 1.9 inch

Schematics

Mobile and Tablet application

Inside Enclosure

Circuit diagram

Code

Sensimug app HTML code

HTML
No preview (download only).

ESP32 Relay control and Wi-fi and app communication

C#
#include <SensirionI2CSts4x.h>
#include <Wire.h>
#include <WiFi.h>
#include <WebServer.h>

// 🔹 REPLACE WITH YOUR WIFI CREDENTIALS 🔹
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";

// 🔹 SETUP WEB SERVER ON PORT 80 🔹
WebServer server(80);

// 🔹 STS40 TEMPERATURE SENSOR SETUP 🔹
#define SDA_PIN 21
#define SCL_PIN 22
SensirionI2CSts4x Sts40;
float currentTemperature = 0.0;
float setTemperature = 50.0; // Default user-set temperature

// 🔹 RELAY PIN 🔹
#define RELAY_PIN 25  // Change to your actual GPIO pin

void setup() {
    Serial.begin(115200);
    pinMode(RELAY_PIN, OUTPUT);
    digitalWrite(RELAY_PIN, LOW); // Ensure relay is off at start

    // 🔹 START I2C COMMUNICATION 🔹
    Wire.begin(SDA_PIN, SCL_PIN);
    Sts40.begin(Wire);

    // 🔹 CONNECT TO WIFI 🔹
    WiFi.begin(ssid, password);
    Serial.print("Connecting to Wi-Fi...");
    while (WiFi.status() != WL_CONNECTED) {
        delay(1000);
        Serial.print(".");
    }
    Serial.println("\nConnected!");
    Serial.print("ESP32 IP Address: ");
    Serial.println(WiFi.localIP());

    // 🔹 HANDLE WEB REQUESTS 🔹
    server.on("/setTemp", []() {
        if (server.hasArg("temp")) {
            setTemperature = server.arg("temp").toFloat();
            Serial.print("Set Temperature Updated: ");
            Serial.println(setTemperature);
            server.send(200, "application/json", "{\"status\":\"success\"}");
        } else {
            server.send(400, "application/json", "{\"status\":\"error\",\"message\":\"No temp parameter\"}");
        }
    });

    server.on("/getTemp", []() {
        String tempJson = "{\"temperature\": " + String(currentTemperature) + "}";
        server.send(200, "application/json", tempJson);
    });

    server.begin();
    Serial.println("HTTP Server Started");
}

void loop() {
    server.handleClient();

    // 🔹 READ STS40 TEMPERATURE 🔹
    float temperature;
    uint16_t error = Sts40.measureHighPrecision(temperature);
    if (!error) {
        currentTemperature = temperature;
        Serial.print("Current Temperature: ");
        Serial.println(currentTemperature);
    } else {
        Serial.println("STS40 Sensor Error!");
    }

    // 🔹 CONTROL RELAY 🔹
    if (currentTemperature < setTemperature) {
        digitalWrite(RELAY_PIN, HIGH); // Turn ON warming pad
        Serial.println("Warming pad ON");
    } else {
        digitalWrite(RELAY_PIN, LOW);  // Turn OFF warming pad
        Serial.println("Warming pad OFF");
    }

    delay(2000);
}

Credits

Negar Rafieedolatabadi
4 projects • 4 followers
Contact

Comments

Please log in or sign up to comment.