Building a Smart Power Switch: Controlling Sensors with an ESP32 and P-Channel MOSFET

Published at : 18 Dec 2025

Altium Develop Free Trial - https://www.altium.com/yt/taste_the_code

Support my work on Patreon so I can continue producing free content and tutorials!
https://www.patreon.com/taste_the_code

In this video, I build and test a smart power switch that allows an ESP32 to control when external sensors are powered on and off using a P-channel MOSFET. This approach is ideal for low-power projects, where sensors only need to be active for short periods while the main board spends most of its time in sleep mode.

I walk through the circuit design, explain how the P-channel MOSFET (IRF9540) is triggered using a simple transistor stage, and show how everything works together to automatically cut power when the system goes back to sleep. The project starts on a perfboard prototype to validate the design before moving on to a proper PCB layout.

For the schematic design and PCB planning, I used Altium Develop, which makes collaboration and design iteration much easier when working on more complex electronics projects. The file is available to my Patrons: https://www.patreon.com/posts/p-channel-mosfet-145814051?utm_medium=clipboard_copy&utm_source=copyLink&utm_campaign=postshare_creator&utm_content=join_link

By the end of the video, you’ll see:
- How to switch higher voltages using an ESP32 safely
- How a P-channel MOSFET can be used as a high-side power switch
- Why prototyping can save you from costly PCB mistakes
- How this setup helps significantly reduce power consumption

This power switch will later be used to control multiple sensors, powering them only when needed and extending battery life in real-world applications.

If you found this useful, make sure to like, subscribe, and check out the links below for tools and resources used in this build.

🛠️ Components Used
ESP32 - https://s.click.aliexpress.com/e/_c3XN2fuV
P-Channel MOSFET (IRF9540) - https://s.click.aliexpress.com/e/_c40Y3KBn
2N2222 NPN Transistor - https://s.click.aliexpress.com/e/_c3iHmF0d
Resistors Pack - https://s.click.aliexpress.com/e/_c4kZyIKz
Perfboard / Prototype PCB - https://s.click.aliexpress.com/e/_c4UiqrVn
Screw Terminals - https://s.click.aliexpress.com/e/_c3uIsqhx
Transistor Pack - https://s.click.aliexpress.com/e/_c4WkG9gN
Soldering Station - https://s.click.aliexpress.com/e/_c3LqPN89
Digital Multimeter - https://s.click.aliexpress.com/e/_c3xbCsHF
Bench Power Supply - https://s.click.aliexpress.com/e/_c4cXSPP3
Fumes Extractor - https://s.click.aliexpress.com/e/_c4qBeRQh

Support my work on Patreon so I can continue producing free content and tutorials!
https://www.patreon.com/taste_the_code



My recording gear:
Canon M50 Mark ii - https://s.click.aliexpress.com/e/_msvmkJ0
GT10 Pro 5G Android Phone - https://s.click.aliexpress.com/e/_oDnXmQm
Dragon Touch 4K Action Camera - https://s.click.aliexpress.com/e/_mrcbfIa
USB Condenser Microphone - https://s.click.aliexpress.com/e/_mq9STfG
Tripod - https://s.click.aliexpress.com/e/_Eynn5TP
Phone tripod mount - https://s.click.aliexpress.com/e/_oDTOzCe

Written article for the video:
https://www.tastethecode.com/sensor-power-switch-using-an-esp32-and-p-channel-mosfet

Building a Smart Power Switch: Controlling Sensors with an ESP32 and P-Channel MOSFET
#MOSFET #esp32 #powerSwitch #pChannel #tastethecode


Main Site and blog: https://www.tastethecode.com
Facebook: https://www.facebook.com/tastethecode/
Instagram: https://www.instagram.com/taste_the_code/
Twitter: http://twitter.com/taste_the_code

00:00 - Introduction
01:28 - Altium Develop
02:29 - Circuit Components
03:43 - Schematic
05:19 - Soldering the prototype
13:10 - Device Test
14:44 - Conclusion and next steps

PCBWay Services - https://pcbway.com/g/7Mb2rj
Altium Develop Free Trial - https://www.altium.com/yt/taste_the_code