Warning
Written by the gibber
A4-LED is a comprehensive IoT-enabled smart LED lamp system designed for networked environments. The project consists of:
- Firmware: ESP8266-based microcontroller code for controlling RGB LED strips
- PCB Design: Custom hardware design (KiCad schematics and layouts)
- Configuration Management: Multi-device configuration system
This is a distributed lighting system designed for A4-IOT applications with MQTT-based remote control and multiple customizable LED effects.
LED/
├── raspi.html # WiFi and device credentials reference
├── led_lamp_firmware/ # Main firmware directory
│ ├── platformio.ini # PlatformIO build configuration
│ ├── src/
│ │ ├── main.cpp # Main firmware code
│ │ ├── config.json # Base configuration template
│ │ ├── config-1.json to # Device-specific configurations
│ │ │ config-7.json
│ │ ├── gen_config.py # Configuration generator script
│ │ ├── upload_config.sh # Config upload script
│ │ └── upload_firmware_to_server.sh # Firmware deployment script
│ ├── include/ # Header files (if needed)
│ └── lib/ # Library dependencies
└── led_lamp_pcb_2/ # PCB design files
├── led_lamp_pcb.kicad_pro # KiCad project file
├── led_lamp_pcb.kicad_sch # Schematic
├── led_lamp_pcb.kicad_pcb # PCB layout
├── led_lamp_pcb.csv # Component list
├── mains_voltage_sensor_design.py # Mains power analysis
├── Regulator_Linear.kicad_sym # Custom symbol
└── proj_footprints.pretty/ # Custom footprints
Target Platform: ESP8266 (D1 Mini board)
- MCU: ESP8266
- Build Framework: Arduino
- Monitor Speed: 115200 baud
GPIO Pins:
- LED_PIN (GPIO4): Controls addressable RGB LED strip
- RELAY_PIN (GPIO5): Main power control relay
- RESET_BTN_PIN (GPIO13): Reset button (2-second press triggers factory reset)
LED Strip Configuration:
- LED Count: 85 addressable RGB LEDs (NeoPixel compatible)
- Protocol: NEO_RGB, 800 kHz timing
- Color Format: 24-bit RGB (8-bit per channel)
The firmware includes an analog temperature sensor with:
- Voltage Reference: 3.3V
- Resistor Network: R1=10kΩ, R2=220kΩ, R3=100kΩ, Rt=10kΩ (NTC thermistor)
- Sampling Interval: 20ms
- Unit: Celsius (°C)
- MQTT-based home automation protocol
- Automatic WiFi and MQTT configuration
- Over-the-air (OTA) firmware updates
- Brand: A4-IOT
- Firmware: main-lamp-firmware v1.0.0
Property: main (boolean, settable)
- Controls the relay output (active-low logic)
- When true: relay OFF (LED effects active)
- When false: relay ON (main power controlled)
The firmware supports 9 different LED effects:
| ID | Name | Description |
|---|---|---|
| 0 | off | All LEDs off |
| 1 | on | Solid color mode (uses color property) |
| 2 | chill | Smooth color fade (blue→pink→yellow→blue) |
| 3 | pride | Pride flag animation |
| 4 | fire | Random orange/red sparks |
| 5 | alert | Alternating red pattern |
| 6 | matrix | Random green LED on/off pattern |
| 7 | bounce | Charged particle physics simulation |
| 8 | xmas | Christmas pattern (alternating red/green) |
Effect Properties:
effect(string, settable): Set active effectcolor(string, settable): RGB color as "red,green,blue" (0-255 each)speed(float, settable): Effect animation speed multiplier
The firmware reports performance metrics every 20 seconds:
fps: Actual frames per secondload: Frame rendering load percentage (0-100%)
Target FPS: 60 (1000/60 ≈ 16.67ms per frame)
Advertised Properties (published):
temp(float): Current temperature in °Creset-cause(integer): Reason for last resetsleep-mode(integer): Sleep stateeffect(string): Current active effectcolor(string): Current color settingspeed(float): Current animation speedmain(boolean): Main relay stateload(float): CPU load percentagefps(float): Current frames per second
Settable Properties (can be controlled via MQTT):
effect: Change LED effectcolor: Set solid colorspeed: Adjust animation speedmain: Control relay output
The project uses JSON-based device configuration with centralized generation:
Base Configuration (config.json):
{
"name": "",
"device_id": "",
"device_stats_interval": 20,
"wifi": {
"ssid": "WLAN-9G3521",
"password": "nUO6HI0JphjIhff97GQk",
"ip": "",
"mask": "255.255.255.0",
"gw": "192.168.1.1"
},
"mqtt": {
"host": "192.168.1.1"
},
"ota": {
"enabled": true
}
}Script: gen_config.py
Automatically generates device-specific configurations:
-
7 Lamp Devices:
config-1.jsonthroughconfig-7.json- Named: "Lamp 1" - "Lamp 7"
- Device IDs: "main-lamp-1" - "main-lamp-7"
- IPs: 192.168.1.21 - 192.168.1.27
-
Special Device:
config-lemon-light.json- Name: "lemon-light"
- Device ID: "lemon-light"
- IP: 192.168.1.40
Usage:
cd led_lamp_firmware/src
python gen_config.pyLocated in led_lamp_pcb_2/:
- Schematic (
led_lamp_pcb.kicad_sch): Full circuit design - Layout (
led_lamp_pcb.kicad_pcb): PCB routing and placement - Project (
led_lamp_pcb.kicad_pro): KiCad project metadata
Voltage Sensors:
- Mains voltage sensor design (analyzed in
mains_voltage_sensor_design.py) - Uses capacitive coupling with 15nF capacitor and 10kΩ resistor
- Calculates: power consumption, surge current, and filter parameters
Regulator:
- Linear voltage regulator (custom symbol in
Regulator_Linear.kicad_sym) - Designed for stable 3.3V supply to ESP8266
Custom Footprints:
proj_footprints.pretty/contains project-specific component footprints- Includes specialized footprint: CHP5R5L504R-TW (likely a power component)
The mains_voltage_sensor_design.py script analyzes:
- Peak voltage: √2 × 230V ≈ 325V
- Average power: Calculated via complex impedance analysis
- Surge current: Worst-case inrush current protection
- Time constant (τ): RC filter response time
- Fuse rating: Determined from surge current
- PlatformIO CLI installed
- Python 3.x for configuration generation
- ESP8266 connected via USB
cd led_lamp_firmware
platformio run --environment d1_minicd led_lamp_firmware
platformio run --target upload --environment d1_minicd led_lamp_firmware/src
python gen_config.pycd led_lamp_firmware/src
bash upload_config.shcd led_lamp_firmware/src
bash upload_firmware_to_server.shSSID: WLAN-9G3521
Network: 192.168.1.0/24
Device IP Assignments:
| Device | IP Address |
|---|---|
| MQTT Broker | 192.168.1.1 |
| Lamp 1 | 192.168.1.21 |
| Lamp 2 | 192.168.1.22 |
| Lamp 3 | 192.168.1.23 |
| Lamp 4 | 192.168.1.24 |
| Lamp 5 | 192.168.1.25 |
| Lamp 6 | 192.168.1.26 |
| Lamp 7 | 192.168.1.27 |
| Lemon Light | 192.168.1.40 |
Turn On Solid White:
mosquitto_pub -h 192.168.1.1 -t "homie/main-lamp-1/lamp/effect/set" -m "on"
mosquitto_pub -h 192.168.1.1 -t "homie/main-lamp-1/lamp/color/set" -m "255,255,255"Activate Chill Effect:
mosquitto_pub -h 192.168.1.1 -t "homie/main-lamp-1/lamp/effect/set" -m "chill"
mosquitto_pub -h 192.168.1.1 -t "homie/main-lamp-1/lamp/speed/set" -m "0.5"Fire Effect:
mosquitto_pub -h 192.168.1.1 -t "homie/main-lamp-1/lamp/effect/set" -m "fire"Turn Off:
mosquitto_pub -h 192.168.1.1 -t "homie/main-lamp-1/lamp/effect/set" -m "off"Toggle Relay:
mosquitto_pub -h 192.168.1.1 -t "homie/main-lamp-1/lamp/main/set" -m "false"mosquitto_sub -h 192.168.1.1 -t "homie/main-lamp-1/lamp/#"-
Homie ESP8266: MQTT home automation framework
- Repository: https://github.com/42Ar/homie-esp8266.git (stable branch)
- Handles WiFi, MQTT, OTA updates
-
Adafruit NeoPixel: Addressable LED control
- Version: ^1.10.5
- Supports WS2812B and compatible protocols
- Verify WiFi SSID and password in configuration
- Check MQTT broker is reachable at configured IP
- Inspect serial output (115200 baud) for connection errors
- Press reset button for 2+ seconds to factory reset
- Check GPIO4 connection to LED data line
- Verify 85 LED count matches physical strip
- Test with "on" effect and white color
- Ensure adequate power supply to LED strip
- Verify device ID matches MQTT topic prefix
- Check JSON syntax in configuration files
- Re-run
gen_config.pyto regenerate configs - Upload config using provided shell script
Colors are specified as comma-separated RGB values (0-255 range):
string_to_color("255,0,0") // Red
string_to_color("0,255,0") // Green
string_to_color("0,0,255") // Blue
string_to_color("255,255,0") // Yellow
- Target: 60 FPS at full brightness (255)
- Load reporting: Frames/(Frames + Skipped) × 100%
- Speed multiplier: 1.0 = normal, 0.5 = half speed, 2.0 = double speed
- Short press (< 2 seconds): Normal operation
- Long press (≥ 2 seconds): WiFi configuration reset, device enters pairing mode
Brand: A4-IOT
Repository: https://github.com/Nabloo/A4-LED-Code
Branch: main
For issues, questions, or contributions, refer to the GitHub repository.
Last Updated: February 2026
Firmware Version: 1.0.0