In this project, we’ll create a smart light controller using StackyFi to control lights remotely via a web interface or smartphone.
What's StackyFi?Meet StackyFi—a revolutionary microcontroller board designed to empower your projects easily and flexibly. Housed in a compact Raspberry Pi Zero form factor, StackyFi packs a powerful ESP32-S3 WROOM 1 microcontroller, featuring a dual-core 32-bit LX7 processor running up to 240 MHz.
StackyFi stands out with its seamless support for Raspberry Pi HATs, allowing you to directly stack and integrate various HATs without needing a separate Raspberry Pi board. With built-in 2.4 GHz Wi-Fi, Bluetooth® 5 (LE), and an onboard accelerometer, StackyFi offers dynamic connectivity and sensor integration options for a wide range of IoT and automation applications.
Fully open-source and highly customizable, StackyFi is perfect for developers and hobbyists looking to create innovative and versatile projects with ease.
1. Setting Up the Hardware:- Connect the Relay HAT to StackyFi.
- Connect the light bulb to the relay, ensuring proper power connections.
- Set up the Arduino IDE and install the required libraries as before.
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
// Replace with your network credentials
const char* ssid = "Your_SSID";
const char* password = "Your_PASSWORD";
// Define relay pin for light control
const int relayPin = 27; // GPIO pin for relay
// Create an instance of the web server
AsyncWebServer server(80);
void setup() {
Serial.begin(115200);
// Initialize relay pin
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW); // Start with light off
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Connected to Wi-Fi");
// Define the web server routes
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
String html = "<html><body>";
html += "<h1>Smart Light Controller</h1>";
if (request->hasParam("action")) {
String action = request->getParam("action")->value();
if (action == "on") {
digitalWrite(relayPin, HIGH); // Turn on light
} else if (action == "off") {
digitalWrite(relayPin, LOW); // Turn off light
}
}
html += "<p><a href=\"/?action=on\">Turn On</a></p>";
html += "<p><a href=\"/?action=off\">Turn Off</a></p>";
html += "</body></html>";
request->send(200, "text/html", html);
});
// Start the server
server.begin();
}
void loop() {
// Nothing to do here
}
4. Uploading the Code:- Follow the same upload steps as in previous projects.
- Open the Serial Monitor to get the IP address.
- Enter the IP address in a web browser and use the provided links to control the light.
Comments
Please log in or sign up to comment.