Random Nerd Tutorials

Power ESP8266 with Mains Voltage using Hi-Link HLK-PM03 Converter


In this post you’ll learn how to power the ESP8266 (or ESP32) with mains voltage using the Hi-Link HLK-PM03 converter. As an example, we’ll use the ESP8266-01 to control a relay with a web server.

The ESP32 and ESP8266 are cheap Wi-Fi modules perfectly suited for DIY projects in the Internet of Things (IoT) and Home Automation fields. Using an ESP32 or ESP8266 with a relay allows you to control any AC electronics appliances over Wi-Fi (using a web-server, for example).

One of the biggest issues with these projects is to find a suitable power supply for the ESP32/ESP8266 with a small form factor at the same time (in a final application you don’t want to power the relay and the ESP32/ESP8266 using two different power supplies). One solution is to power the ESP8266 or ESP32 from mains voltage using the AC/DC converter Hi-Link HLK-PM03 (or HLK-PM01 model).

Introducing the Hi-Link HLK-PM03/01 Converter Modules

The Hi-Link HLK-PM03  is a small AC/DC converter module as shown in the figure below.

The HLK-PM03 AC/DC converter can supply 3.3V from either 110VAC or 220VAC. This makes it perfect for small projects that need a 3.3V supply from mains voltage. You can also get 5V output using the HLK-PM01 instead.

You can read more information about these modules’ specifications: HLK-PM03 and HLK-PM01. There’s also a really good article about the performance test of the HLK-PM01.

To power the ESP8266-01 from mains voltage, we’ll be using the HLK-PM03 to provide 3.3V to the VCC pin. If you need 5V to power other ESP8266 models or an ESP32 through the VIN pin, you can use the HLK-PM01 model that provides 5V output and works similarly.

Where to Buy?

You can check the HLK-PM03 or HLK-PM01 modules on Maker Advisor and find the best price.

Safety Warning

This project deals with mains voltage. Make sure you understand what you are doing. Please read the safety warning below carefully.

Powering the ESP8266 with AC using the Hi-Link HLK-PM03 module

You can use the HLK-PM03 without any circuitry and attach it directly to the ESP8266 VCC pin. However, I don’t recommend doing that. It is advisable to add a protection circuit with a thermal fuse and quick-blow fuses.


Adding capacitors to the HLK-PM03 output is also a good idea to smooth voltage peaks and prevent unexpected resets or unstable behavior powering the ESP8266. We’ve also added a varistor across the mains input to protect the circuit from voltage peaks.

Parts Required

Here’s a list of all the parts required to build the circuit for the project we’ll build:

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Circuit Diagram

The following figure shows the circuit diagram.

The J1 terminal block is where you should connect mains voltage.

The 3.3V and GND after the capacitors will power the ESP8266-01.

We’ve also added a three terminal block connected to the ESP8266 to get access to 3.3V, GND and GPIO 2 to control an output (relay module). Because we’re dealing with 3.3V you should use a 3.3V relay module like this, for example.

For testing purposes, we’ve soldered the circuit on a prototype board. We plant to build a PCB with this circuit in a future project.

Soldering Thermal Fuses

The thermal fuse used in the circuit is a 73ºC fuse. This means you need to be very careful when soldering it as the heat from the soldering iron can cause it to blow. To learn more about how to solder thermal fuses, we recommend taking a look at the following resources:


In this example we’ve programmed the ESP8266 with Arduino IDE. To program the ESP8266 using Arduino IDE, you need to have the ESP8266 add-on installed. Follow the next tutorial to install the ESP8266 add-on, if you haven’t already.

The following code creates a web server that you can access to control the relay connected to the ESP8266 (GPIO 2) via Wi-Fi in your local network.

Setting Your Network Credentials

You need to modify the following lines with your network credentials: SSID and password before uploading the code. The code is well commented on where you should make the changes.

// Replace with your network credentials
const char* ssid     = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

For an explanation of the code, you can read the following tutorial: ESP8266 Web Server with Arduino IDE.

Note: if you’re using an ESP32 with the HLK-PM01 module, you can use the code in this tutorial.

Uploading the Code

Upload the code provided to the ESP8266-01 board using an FTDI programmer or a ESP8266-01 serial adapter.

If you’re using an FTDI programmer like this, you need to make a connection as shown in the following schematic diagram:

After uploading the code, open the Serial Monitor to get the ESP8266-01 IP address. You’ll need it to access the web server.


After uploading the code to your ESP8266 and getting the IP address, place it in the circuit and apply power to the circuit.

Warning: don’t touch the circuit while it is connected to mains voltage!

Open your browser, type the ESP IP address and the following page should load.

You should be able to control the relay remotely on your local network.

Note: we’re using the circuit on a prototype board for demonstration purposes. If you want to use the circuit in a final application, we recommend building a PCB and place it inside a proper project box enclosure.

We plan to build this circuit on a PCB in the upcoming weeks if there’s enough interest, and we’ll share all the files and resources you need to build your own PCB with the HLK-PM03 or HLK-PM01 modules.

Wrapping Up

The HLK-PM01 and HLK-PM03 are converter modules that provide 5V and 3.3V respectively, from mains voltage. This provides an easy way to power your ESP8266 or ESP32 in your IoT and Home Automation projects.

We hope you’ve found this project helpful! If you like these subjects, you may also like:

MicroPython Programming with ESP32/ESP8266 eBook

Learn how to program the ESP boards with MicroPython, including projects, tips, and tricks! The registrations are open for a limited time, so SIGN UP NOW »

Recommended Resources

Home Automation using ESP8266 »
Build IoT projects and home automation gadgets with the ESP8266 Wi-Fi module.

Build a Home Automation System »
Learn how to build a automation system using open-source hardware and software from scratch.

Arduino Step-by-Step Projects »
Build 25 cool Arduino projects with our course even with no prior experience!

Leave a Comment:

Add Your Reply

⏰ Registrations are open for "MicroPython Programming with ESP32 and ESP8266" eBook