Greetings, wizarding developers and tech enthusiasts! ✨
At Team PowerPotters, we’re always looking to bring the magic of innovation to life through clever use of hardware and software. For our submission to the Embedding Numbnut badge, we present the heart of our IoT-powered solution: an ultrasonic sensor connected to an ESP32 microcontroller, bringing physical interactions to our potion production platform.
Here’s how our code, coupled with an end-to-end setup, transforms real-world sensor readings into actionable data for our modern workflows.
🪄 The Ultrasonic Detector: Turning Hardware into Magic
Our ultrasonic detector is more than a simple sensor—it’s the spark that initiates our potion brewing process. Connected to an ESP32 microcontroller, it captures data in the physical world (like liquid levels or proximity) and seamlessly integrates it with our cloud-based systems using Power Automate.
Key Features of the Sensor Setup
- Real-Time Data Capture: The ultrasonic sensor measures distances (or liquid levels) using sound waves, triggering actions when specific thresholds are reached.
- ESP32 Integration: The ESP32 runs the control code, processes sensor readings, and communicates with cloud endpoints via Wi-Fi.
- Cloud Connectivity: Using HTTP POST requests, the ESP32 sends data to Azure Logic Apps, triggering automated workflows for further processing.
🧙♂️ The Code That Makes It Work
Below is the magical incantation—our C++ code—that powers the ultrasonic detector. Let’s break it down:
#include <WiFi.h>
#include <HTTPClient.h>
#include <ESPAsyncWebServer.h>
// Define GPIO pins
#define LED_PIN 18
#define ULTRA_SENSOR_E 4
#define ULTRA_SENSOR_T 2
#define TRIGGER_pulse 1
int DURATION;
long DISTANCE;
// Wi-Fi credentials
const char* ssid = "Simen's Galaxy S20+ 5G";
const char* password = "#######";
// Server endpoint URL
const char* serverUrl = "https://<YOUR-ENDPOINT>";
AsyncWebServer server(80);
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
pinMode(ULTRA_SENSOR_E, INPUT);
pinMode(ULTRA_SENSOR_T, OUTPUT);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected to Wi-Fi");
server.on("/trigger", HTTP_POST, [](AsyncWebServerRequest *request){
digitalWrite(LED_PIN, HIGH);
sendDuration();
digitalWrite(LED_PIN, LOW);
request->send(200, "text/plain", "Request received, duration sent");
});
server.begin();
}
void sendDuration() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(serverUrl);
http.addHeader("Content-Type", "application/json");
sense();
String payload = "{\"duration\":" + String(DURATION) + "}";
int httpResponseCode = http.POST(payload);
if (httpResponseCode > 0) {
Serial.println(http.getString());
} else {
Serial.println("Error sending POST request");
}
http.end();
}
}
void sense() {
digitalWrite(ULTRA_SENSOR_T, HIGH);
delay(TRIGGER_pulse);
digitalWrite(ULTRA_SENSOR_T, LOW);
DURATION = pulseIn(ULTRA_SENSOR_E, HIGH);
DISTANCE = (DURATION * 0.034 / 2) + 1;
Serial.println(DURATION);
Serial.println(DISTANCE);
}
✨ How It All Comes Together
- Sensing the Magic:
- The ultrasonic sensor emits sound waves, measuring the time it takes for the echo to return and calculating the distance.
- Data Processing and Transmission:
- The ESP32 processes the sensor data and sends it as a JSON payload to an Azure Logic Apps endpoint using HTTP POST requests.
- Triggering the Workflow:
- The payload is received by Power Automate, initiating a series of actions, such as potion brewing approval or status updates.
- Automation and Insight:
- The sensor data is logged, analyzed, and acted upon without any manual intervention, showcasing true IoT integration.
🐍 Why This Deserves the Embedding Numbnut Badge
Our setup is the perfect embodiment of Embedding Numbnut:
- Hardware Integration: The ultrasonic sensor and ESP32 work in harmony to capture and transmit real-world data.
- IoT Innovation: We’ve demonstrated how to bridge the gap between physical hardware and cloud-based workflows.
- Seamless Automation: By connecting sensors to Power Automate, we’ve eliminated manual tasks, ensuring precision and efficiency.
- Slytherin Ambition: True to our house, we’ve taken a simple sensor and turned it into a powerful enabler of potion production magic.
🪄 A Picture Is Worth a Thousand Spells
Below is a snapshot of our code being loaded onto the ESP32, where the magic begins:
🔮 The Future of Embedded Magic
With our ultrasonic detector at the heart of our IoT setup, we’ve showcased how embedded hardware can power real-world automation. We humbly submit our case for the Embedding Numbnut badge, proving that even the smallest components can create the most magical outcomes.
Follow our journey as we continue to innovate and enchant the world of ACDC 2025: acdc.blog/category/cepheo25.
#ACDC2025 #EmbeddingNumbnut #PowerPotters #IoTMagic #SlytherinInnovation