ESP32/IoT B.Tech/Diploma Beginner

IoT AC Dimmer using TRIAC & ESP32 WebServer

IoT Based AC Dimmer using TRIAC & ESP32 WebServer to control AC Lights & Fan Speed from Web dashboard using the slider button

  • Suitable forB.Tech/Diploma ESP32/IoT students
  • Build time1-2 weeks
  • LevelBeginner
  • Available atAjvika Labs, Kakinada

About this project

Overview
In this tutorial, we will design a circuit using a
TRIAC
and an
optocoupler
to create an
IoT AC Light Dimmer
or AC Fan Speed Controller using an
ESP32 WebServer
AC power
runs most of our home appliances like lights and fans. Sometimes, we want to control these devices—for example, dimming a lamp or
adjusting a fan’s speed
. To control
110/220V AC power
effectively, we use a
TRIAC for phase control
, which means turning it on only during a specific part of the AC wave.
Controlling AC loads
is more complicated than DC because AC power changes direction at a frequency of
50/60Hz
. To build an AC dimmer, we need to detect the
zero-crossing points
where the wave switches direction. We use a zero-crossing detector for this and adjust the phase and cycle of the wave to control the power delivered.
Most electronic components can’t handle direct contact with
high-voltage AC power
. So, we isolate the
control circuit
from the high-voltage side using
optocouplers
. These devices let us control the
power safely
without exposing sensitive parts to dangerous voltages.
In this project, we incorporate an
ESP32 microcontroller
to add IoT capabilities to our AC dimmer. By hosting a
web server
on the ESP32, we can control the dimming of the AC load remotely through a web interface. This allows for convenient and flexible control of appliances over a network, paving the way for smart home applications.
WARNING:
This circuit is connected directly to the mains AC voltage. You must care about all safety precautions before using the device. If you are a beginner and without having the idea of using electronics appliances. Please avoid!
Bill of Materials
For this project, we will need the following components. The component list, footprint, and quantity are given below.
ID
Designator
Footprint
Quantity
Manufacturer Part
1
Capacitor 1uF
C1
C0805
1
2
Capacitor 0.1u
C2,C4
C0805
2
3
Capacitor 10uf
C3, C6, C7
C0805
3
4
Capacitor 1uf
C5
C0805
1
5
Rectifier DB107
D1
DIO-BG-TH_DB107
1
DB107
6
FTDI Connector
PROG
HDR-F-2.54_1X6
1
7
Transistor BC847
Q1,Q3
SOT-23-3
2
2n3904S-RTK/PS
8
TRIAC BTA16
Q2
TO-220-3
1
BTA16-800CW
9
Resistor 330R
R1,R4
R0805
2
10
Resistor 47K
R2,R3
R0805
2
11
DNP (10K Resistor)
R5
R0805
1
12
Resistor 10K
R6,R7,R8
R0805
3
13
Optocoupler PC817C
U1
DIP-4
1
PC817C
14
MOC3052SR2M
U2
SMT-6_6.3MM
1
MOC3052SR2M
15
HLK-10M05
U3
PWRM-TH_HLK-10M05
1
HLK-10M05
16
ESP32-WROOM
U4
WIFIM-SMD_39P
1
ESP32-WROOM-32-N8
17
HT7333-7
U5
SOT-89-3
1
HT7333-7
18
Terminal Block 2 Pin
U6,U7
CONN-TH_2P-P5.00
2
TY500-5.0-02P-14-00AH
ESP32 AC Dimmer Circuit Diagram & Hardware Design
The circuit for the “
IoT AC Dimmer using TRIAC & ESP32
” consists of three main sections: the
power supply
control circuit
, and
AC load contro
l.
Fig: ESP32 IoT AC Dimmer Circuit Diagram & Hardware Design
The power supply section uses an
HLK-10M05 module
to step down the AC mains to a
5V DC supplY
, further regulated to
3.3V
using an
HT7333-7
regulator to power the ESP32 module. Capacitors are used for filtering to ensure a
stable DC output
The ESP32 is the brain of the circuit, hosting a
web server
to control the dimming function. The
zero-crossing detection
is achieved using an
optocoupler
(
PC817C
) connected to the AC mains. The
zero-crossing signal
helps the ESP32 to synchronize with the
AC wave
and control the
TRIAC’s firing angle
via a
MOC3052
opto-isolated TRIAC driver. The ESP32 triggers the MOC3052 through a GPIO pin, which then controls the main
TRIAC (BTA16)
. This TRIAC regulates the power supplied to the load, allowing
precise control
of brightness or speed.
To program the
ESP32 raw chip
, the
FTDI pin
is provided. We can connect an
FTDI Module
(USB-to-TTL Converter) to program the ESP32 Chip directly.
Project PCB Gerber File & PCB Ordering Online
We have designed the
PCB
using the
EasyEDA Software
. It took quite a lot of time fixing all the issues in the PCB but still we managed to design a complete working custom PCB.
Fig: ESP32 IoT AC Dimmer PCB Design
The top part of the PCB design looks like this.
Fig: Top Layer of PCB Board
The bottom part of the PCB board looks like this.
Fig: Top Layer of PCB Board
Here is the
3D View
of the PCB from the front side.
Fig: 3D View of PCB Board
The Gerber File for the PCB is given below. You can simply download the Gerber File and order the PCB from
ALLPCB
at
1$
only.
Download Gerber File:
IoT AC Dimmer Gerber File
You can use this Gerber file to order high-quality PCB for this project. To do that visit the
ALLPCB
official website by clicking here:
https://www.allpcb.com/
You can now upload the Gerber File by choosing the Quote Now option. From these options, you can choose the Material Type, Dimensions, Quantity, Thickness, Solder Mask Color and other required parameters.
After filling all details, select your country and shipping method. Finally you can place the order.
PCB & Hardware Assembly
After ordering the PCB, it took almost 5 days and I got my PCB.
The PCB quality from
ALLPCB
is superb with very premium quality. That is why most people trust
ALLPCB
for PCB/PCBA Services.
Fig: Received PCB of ESP32 IoT AC Dimmer
First solder all the
SMD components
like resistors, capacitors, transistors, voltage regulators & diodes.
Fig: ESP32 IoT AC Dimmer Assembled PCB
After soldering all these, you can solder the
ESP32 raw chip
. The final stage would be soldering all the through-hole components like Optocoupler IC, terminal block, male-female headers, and AC-to-DC Converter Module.
Connect the AC input Cable at the input terminal of AC IN. Also connect any load like Filament Bulb or AC Fan at the output terminal of AC OUT.
Fig: ESP32 IoT AC Dimmer Board Final Hardware
After soldering all the components, the ESP32 IoT AC Dimmer Board is ready for the test. You can upload a blink sketch by connecting a
USB-to-TTL Converter
Module.
Fig: Programming the ESP32 Chip
Now we can move to the main part of the project and write a C/C++ & WebServer Code for ESP32 IoT AC Dimmer project.
Source Code/Program
This code implements an IoT-based AC dimmer using an ESP32, allowing users to control the brightness of an AC load (like a lamp or fan) through a web interface. The ESP32 connects to a WiFi network and hosts a web server that provides a user-friendly control page. On the web page, users can adjust a slider to set the dimming level (0 to 100%), which is sent to the ESP32 via HTTP GET requests.
The circuit detects the AC mains’ zero-crossing points through an interrupt, ensuring synchronized control of the TRIAC. Based on the dimming level received from the web interface, the
set_power
function calculates the TRIAC’s firing angle, and the
zero_cross_int
function controls the TRIAC to adjust the power delivered to the load. This allows for smooth dimming of the connected AC device.
From the following lines in the below code, change the WiFi SSID and Password and replace it with yours.
1
2
const
char
*
WIFI_SSID
=
\"**************\"
;
const
char
*
WIFI_PASS
=
\"**************\"
;
Here is the final code that you can copy, modify and upload to the ESP32 Chip.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include `arduino.h`

Technologies used

ESP32ArduinoWiFiBLEC++

Hardware components

  • ESP32
  • Arduino

Software & tools

  • EasyEDA

What you get

  • Working project / hardware kit, tested before delivery
  • Complete source code with explanation
  • Project demo and guidance for your viva
  • Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed. Payment is in two parts: • 50% advance to start the project • Remaining 50% before delivery Note: • Documentation and PPT are not included by default • If you need documentation/PPT, it can be arranged for extra time and cost We'll confirm the exact timeline and cost with you after reviewing your requirements.