Difficulty: Beginner
Time Required: 1 hour
Cost: $10-15
ESP Board: ESP32
What You’ll Need
| Component | Cost | Where to Buy |
|---|---|---|
| ESP32 Dev Board | $5-8 | Amazon |
| WS2812B LED Strip (1m) | $4-6 | Amazon |
| 5V Power Supply (2A+) | $3-5 | Amazon |
| Jumper Wires | $2 | Amazon |
Circuit Diagram
| ESP32 Pin | Component |
|---|---|
| 5V | LED Strip VCC |
| GND | LED Strip GND |
| GPIO 4 | LED Strip DIN |
The Complete Code
/*********************************************************************
* ESP32 WiFi LED Controller
*
* Control RGB LED strip via WiFi and web browser
* Hardware: ESP32, WS2812B LED Strip
*
* Libraries Required:
* - FastLED (install from Library Manager)
*********************************************************************/
#include
#include
#include
// ============== LED CONFIGURATION ==============
#define LED_PIN 4
#define NUM_LEDS 60
CRGB leds[NUM_LEDS];
// ============== WIFI ==============
const char* wifi_ssid = "YOUR_WIFI";
const char* wifi_password = "YOUR_PASSWORD";
WebServer server(80);
// ============== STATE ==============
int currentMode = 0;
int brightness = 100;
CRGB currentColor = CRGB::White;
void setup() {
Serial.begin(115200);
// Initialize LEDs
FastLED.addLeds(leds, NUM_LEDS);
FastLED.setBrightness(brightness);
// Set all LEDs to current color
fill_solid(leds, NUM_LEDS, currentColor);
FastLED.show();
connectToWiFi();
setupWebServer();
Serial.println(F("LED Controller Active!"));
}
void loop() {
server.handleClient();
// Update LEDs based on mode
updateLEDs();
}
// ============== FUNCTIONS ==============
void updateLEDs() {
switch (currentMode) {
case 0: // Static color
fill_solid(leds, NUM_LEDS, currentColor);
break;
case 1: // Rainbow
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV((i * 256 / NUM_LEDS + millis()/10) % 256, 255, 255);
}
break;
case 2: // Breathing
float breath = (sin(millis() / 500.0) + 1) / 2;
fill_solid(leds, NUM_LEDS, currentColor);
FastLED.setBrightness(brightness * breath);
break;
}
FastLED.show();
}
void setupWebServer() {
server.on("/", []() {
String html = ""
"ESP32 LED Controller
"
"Brightness: " + String(brightness) + "
"
""
"
"
""
""
""
"
"
""
""
""
""
""
""
"";
server.send(200, "text/html", html);
});
server.on("/mode", []() {
currentMode = server.arg("m").toInt();
server.send(200, "text/plain", "OK");
});
server.on("/color", []() {
currentColor = CRGB(
server.arg("r").toInt(),
server.arg("g").toInt(),
server.arg("b").toInt()
);
server.send(200, "text/plain", "OK");
});
server.on("/bright", []() {
brightness = server.arg("b").toInt();
FastLED.setBrightness(brightness);
FastLED.show();
server.send(200, "text/plain", "OK");
});
server.begin();
}
void connectToWiFi() {
WiFi.begin(wifi_ssid, wifi_password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(F("."));
}
Serial.println(F(" Connected!"));
Serial.print(F("IP: "));
Serial.println(WiFi.localIP());
}
Official Documentation
- FastLED Library – Official GitHub
- ESP32 Arduino – Official docs
Safety Warning
⚠️ Use a separate 5V/2A+ power supply for LED strips longer than 1 meter. USB power is not sufficient.

