Skip to content

Nabloo/A4-LED-Code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

A4-LED: Smart IoT LED Lamp Project

Warning

Written by the gibber

Overview

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.


Project Structure

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

Firmware Details

Hardware Specifications

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)

Temperature Monitoring

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)

Core Features

1. Homie Protocol Integration

  • 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

2. Main Power Control

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)

3. LED Effects System

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 effect
  • color (string, settable): RGB color as "red,green,blue" (0-255 each)
  • speed (float, settable): Effect animation speed multiplier

4. Performance Monitoring

The firmware reports performance metrics every 20 seconds:

  • fps: Actual frames per second
  • load: Frame rendering load percentage (0-100%)

Target FPS: 60 (1000/60 ≈ 16.67ms per frame)

MQTT Properties

Advertised Properties (published):

  • temp (float): Current temperature in °C
  • reset-cause (integer): Reason for last reset
  • sleep-mode (integer): Sleep state
  • effect (string): Current active effect
  • color (string): Current color setting
  • speed (float): Current animation speed
  • main (boolean): Main relay state
  • load (float): CPU load percentage
  • fps (float): Current frames per second

Settable Properties (can be controlled via MQTT):

  • effect: Change LED effect
  • color: Set solid color
  • speed: Adjust animation speed
  • main: Control relay output

Configuration Management

Configuration System

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
    }
}

Configuration Generator

Script: gen_config.py

Automatically generates device-specific configurations:

  • 7 Lamp Devices: config-1.json through config-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.py

Hardware Design (PCB)

PCB Files (KiCad)

Located 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

Key Components

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)

Design Calculations

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

Building and Deploying

Prerequisites

  1. PlatformIO CLI installed
  2. Python 3.x for configuration generation
  3. ESP8266 connected via USB

Build Firmware

cd led_lamp_firmware
platformio run --environment d1_mini

Upload Firmware

cd led_lamp_firmware
platformio run --target upload --environment d1_mini

Generate Configuration Files

cd led_lamp_firmware/src
python gen_config.py

Upload Configuration

cd led_lamp_firmware/src
bash upload_config.sh

Deploy Firmware to Server

cd led_lamp_firmware/src
bash upload_firmware_to_server.sh

Network Configuration

WiFi Details

SSID: 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

Usage Examples

Control via MQTT (mosquitto_pub)

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"

Monitor Device Status

mosquitto_sub -h 192.168.1.1 -t "homie/main-lamp-1/lamp/#"

Dependencies

Firmware Libraries

  • Homie ESP8266: MQTT home automation framework

  • Adafruit NeoPixel: Addressable LED control

    • Version: ^1.10.5
    • Supports WS2812B and compatible protocols

Troubleshooting

Device Not Connecting

  1. Verify WiFi SSID and password in configuration
  2. Check MQTT broker is reachable at configured IP
  3. Inspect serial output (115200 baud) for connection errors
  4. Press reset button for 2+ seconds to factory reset

LED Strip Not Responding

  1. Check GPIO4 connection to LED data line
  2. Verify 85 LED count matches physical strip
  3. Test with "on" effect and white color
  4. Ensure adequate power supply to LED strip

Configuration Not Loading

  1. Verify device ID matches MQTT topic prefix
  2. Check JSON syntax in configuration files
  3. Re-run gen_config.py to regenerate configs
  4. Upload config using provided shell script

Technical Notes

Color Handling

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

Effect Performance

  • 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

Reset Behavior

  • Short press (< 2 seconds): Normal operation
  • Long press (≥ 2 seconds): WiFi configuration reset, device enters pairing mode

License & Attribution

Brand: A4-IOT
Repository: https://github.com/Nabloo/A4-LED-Code
Branch: main


Contact & Support

For issues, questions, or contributions, refer to the GitHub repository.


Last Updated: February 2026
Firmware Version: 1.0.0

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors