user79782: Hello i want to switch electric door lock (12V, 170mA) with esp32(3.3V). If is it possible I want use tranzistor. I tried to use IRF520, but it only worked with 5V. My sugestion is use 2 tranzistors one would switch 5V to IRF520 which would switch 12V. Can someone pro provide me some schematic, how to solve it? Thanks.

user68595: A single, reasonably tough general purpose BJT is all you need here if you really want a simple solution.  The 2N4401 supports up to 600mA of current and has a 40V Vce max.  As long as the solenoid on the door lock has a snubber it doesn't need to be any more complicated than this unless you need isolation or have other constraints.
Note that below I've drawn a relay because it was easy, but you can just as well put your door lock's solenoid coil where the relay is drawn below (they're effectively the same type of device).

I have exactly this setup on an ESP8266 controlling a 24V relay and it works great.  I'm using an old 2N2222, which are long since obsolete, but the 2N4401 would do just the same.

user14490: 
BC549 provides strong pull-down for IRFR5305, which is provides up to +12V at 16A with less than 0.09 Ohm channel resistance.
This circuit works well with ESP8266, I use it in some of my devices.
Don't forget about placing the flyback diode (EEV Blog, Wiki) in reverse polarity, parallel to the magnet. Place it as close as possible to the magnet!

79782: <p>Hello i want to switch electric door lock (12V, 170mA) with esp32(3.3V). If is it possible I want use tranzistor. I tried to use IRF520, but it only worked with 5V. My sugestion is use 2 tranzistors one would switch 5V to IRF520 which would switch 12V. Can someone pro provide me some schematic, how to solve it? Thanks.</p>
 68595: <p>A single, reasonably tough general purpose BJT is all you need here if you really want a simple solution.  The 2N4401 supports up to 600mA of current and has a 40V Vce max.  As long as the solenoid on the door lock has a snubber it doesn't need to be any more complicated than this unless you need isolation or have other constraints.</p>
<p>Note that below I've drawn a relay because it was easy, but you can just as well put your door lock's solenoid coil where the relay is drawn below (they're effectively the same type of device).</p>
<p><a href="https://i.stack.imgur.com/MDZZn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MDZZn.png" alt="enter image description here" /></a></p>
<p>I have exactly this setup on an ESP8266 controlling a 24V relay and it works great.  I'm using an old 2N2222, which are long since obsolete, but the 2N4401 would do just the same.</p>
 14490: <p><a href="https://i.stack.imgur.com/nLIiv.png" rel="noreferrer"><img src="https://i.stack.imgur.com/nLIiv.png" alt="enter image description here" /></a></p>
<p>BC549 provides strong pull-down for IRFR5305, which is provides up to +12V at 16A with less than 0.09 Ohm channel resistance.</p>
<p>This circuit works well with ESP8266, I use it in some of my devices.</p>
<p>Don't forget about placing the flyback diode (<a href="https://www.youtube.com/watch?v=hReCPMIcLHg" rel="noreferrer">EEV Blog</a>, <a href="https://en.wikipedia.org/wiki/Flyback_diode" rel="noreferrer">Wiki</a>) in reverse polarity, parallel to the magnet. Place it as close as possible to the magnet!</p>
