element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Spring Clean!
  • Challenges & Projects
  • Project14
  • Spring Clean!
  • More
  • Cancel
Spring Clean!
Spring Clean Projects 2026 Building a Secure, Decentralized Smart Home from Scratch (Part 2)
  • News and Projects
  • Forum
  • Members
  • More
  • Cancel
  • New
Join Spring Clean! to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: abtAmit
  • Date Created: 31 May 2026 11:03 PM Date Created
  • Views 53 views
  • Likes 3 likes
  • Comments 0 comments
Related
Recommended

Building a Secure, Decentralized Smart Home from Scratch (Part 2)

abtAmit
abtAmit
31 May 2026
Building a Secure, Decentralized Smart Home from Scratch (Part 2)

In Part 1, we built and tested a functional physical prototype. The ESP-NOW mesh network, secured by cryptographic hashing and wired to mechanical relays. But while the prototype functioned, it was still just a bulky bench setup wired on a breadboard. To make it compact, integrate better power management, and add AC dimming capabilities, the next logical step was designing a custom PCB.

Phase 6: Custom PCB Design — The 5-Channel AC Dimmer Module

While the mechanical relays worked for basic on/off switching, they take up too much space and can't dim a light.

To fix this, I decided to design a custom 5-Channel AC Dimmer and Switch Module using TRIACs. Controlling AC mains with TRIACs across multiple channels requires microsecond-level timing precision to fire relative to the AC zero-crossing point. The ESP chip managing the wireless connection couldn't handle the ESP-NOW mesh network and execute strict hardware timer interrupts at the same time without dropping packets or flickering the lights.

To solve this processing bottleneck, I used a dual-chip architecture: the ESP handles the network, while a dedicated microcontroller acts as the hardware manager.

Here is the practical hardware architecture and schematic breakdown for the custom PCB:

1. Microcontroller 

At the core is the STM32F103C8T6. Managing five simultaneous dimming channels requires precise timing. The STM32's advanced hardware timers calculate the exact firing delay for each TRIAC independently after every AC zero-cross event, allowing for smooth fading without tying up the main processing loop. While the ESP will manage the wireless connectivity

2. Zero-Cross Detection (ZCD) Circuit

 

image

To dim an AC load, the microcontroller must know exactly when the AC sine wave crosses zero volts.

The mains AC is converted to pulsating DC using an MB6S bridge rectifier.

The pulsating DC passes through high-wattage current-limiting resistors (47kΩ) into an EL817 optocoupler.

Every time the AC voltage drops to zero, the optocoupler briefly turns off, sending a precise pulse to the STM32's ZCD pin. This pulse acts as the metronome for the entire dimming operation.

 3. High-voltage Control and Isolation

image

Optoisolation: The MCU is isolated from the mains voltage using MOC3053 random-phase optocouplers. These are triggered by a low 5mA current, safely driven directly from the STM32's PB12, PB13, PB14, PB15, and PA8 pins.

Power Switching:  It has high-power (16-Amp) T1635 snubberless triacs that handle the physical switching of the AC load, driven by the optocouplers through 470Ω gate resistors and A1 connects directly to live and A2 connects to the channel terminal for connecting appliances.

4. Power Supply and Noise Filtering 

image

An HLK-5M03 step-down module is used to convert 220V AC directly to the 3.3V DC needed for the MCU and logic components.

Input Protection: The AC input line has a fuse (0.5A) and a mov 10D471 to protect the board against short circuits or catastrophic load failures.

Noise Filter: The 3.3v side it uses Pi Filter that has 100uF, 100nF capacitor and 150mΩ 1A 60Ω@100MHz Ferrite Bead and 10uF,100nF capacitor after Ferrite Bead to suppress the noise.

 

5. Interface & Connectivity 

 image

Analog/Digital Inputs: Pins A1 to A5 are for controlling the channels, you can use Switches to turn ON/OFF or rotary switches can be used for dimming purpose.

UART and I2C: PA9 (TX), PA10 (RX) and PB6 (SCL) and PB7 (SDA) are exposed for debugging, serial firmware flashing or to receive digital dimming commands.

 image

How It Works

1. Syncing: The ZCD circuit detects the AC zero-crossing point (100 times a second for 50Hz mains) and triggers an interrupt on the STM32.

2. Calculating Delay: Depending on the desired brightness level (0-100%), the STM32 calculates a delay. For maximum brightness, the delay is nearly 0ms. For 50% brightness, the delay is exactly half of the AC half-cycle (e.g., 5ms for a 50Hz system).

3. Polling: The STM32 uses Timer ISR to check if it is the time to turn on any of five channels.

4. Firing: Once the calculated delay for a specific channel has elapsed, the STM32 sends a brief HIGH signal to the corresponding MOC3053 optoisolator. The optoisolator triggers the gate of the T1635 TRIAC, allowing AC current to flow to the connected load for the remainder of that half-cycle. This process repeats continuously, resulting in a smoothly dimmed output.

for source code and Gerber file visit https://github.com/abtAmit/


Video demonstration

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

the video demonstrate smooth, flicker-free AC dimming and a fully synchronized dual-control system. Flip a physical switch on the wall, and the app updates instantly—letting you turn it on manually and off from your phone!

Conclusion

By building this system from scratch, I made a solution that fixes the specific annoyances I had with off-the-shelf smart home gear. It runs locally without cloud dependence, routes its own mesh network, and the custom dual-chip PCB handles five channels of AC dimming in a compact footprint. It’s still a DIY project, but it’s a highly capable, secure framework built exactly the way I wanted it.

 

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube