🎉 Black Friday is Here! Enjoy Up to 35% Off ~ Offer Ends November 30th!
In this build, we'll explore how to configure the CodeCell's onboard LED light using the Espalexa library, which allows Alexa to control devices like smart lights. We'll walk you through the process of connecting the CodeCell to your Wi-Fi, setting up the Espalexa library, and enabling voice control for the onboard LED through Alexa.
The Espalexa library simplifies Alexa integration for ESP32 projects. It creates a virtual smart light, which Alexa can control via voice commands, without needing complex setup or cloud services. By using this library, your CodeCell can function as a smart device, like a light bulb, that Alexa can turn on, off, or dim.
In this project, the CodeCell is set up to connect to your Wi-Fi network. Once connected, Alexa can control the onboard LED light using voice commands, whether it's fully on (green) or off (no color).
Below is the example code to get you started. Update the Wi-Fi credentials with your network details, and follow the comments in the code to understand each step.
#include <Espalexa.h>
#include <WiFi.h>
#include <CodeCell.h>
CodeCell myCodeCell;
// WiFi credentials
const char* ssid = "SSID"; //Change to your SSID
const char* password = "PASSWORD"; // Change to your password
// Alexa object
Espalexa espalexa;
// Function to handle Alexa commands
void alexaCallback(uint8_t brightness) {
// Handle brightness (or ON/OFF) commands here
if (brightness == 255) {
myCodeCell.LED(0, 0xFF, 0); // Full brightness, green light
} else if (brightness == 0) {
myCodeCell.LED(0, 0, 0); // Turn off the LED
}
}
void setup() {
// Initialize serial for debugging
Serial.begin(115200);
myCodeCell.Init(LIGHT); /*Initializes Light Sensing*/
// Connect to WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
// Add a device to Alexa
espalexa.addDevice("MyLED", alexaCallback);
// Start Espalexa
espalexa.begin();
}
void loop() {
espalexa.loop(); // Handle Alexa requests
}
After uploading the code and connecting the CodeCell to Wi-Fi, the next step is to add the device to your Alexa app. Follow these steps to pair it with Alexa:
With these steps, your CodeCell's onboard LED is now fully integrated into your smart home setup, and you can control it with Alexa voice commands or the Alexa app!
alexaCallback()
function to use different colors based on Alexa’s brightness level. You can use RGB values to create various effects.This project demonstrates how to integrate the CodeCell with Alexa using the Espalexa library to control the onboard LED light. By following this example, you can easily build voice-activated projects with CodeCell, bringing IoT capabilities into your hands!
Get creative with the customization options and bring more of your projects to life with Alexa integration!
Be the first to know about new projects and get exciting deals!
© 2024 Microbots.