# 3.3V Microcontroller pin protection circuit.

#### Dusan123

Joined Aug 7, 2023
5
Hey all!

I was looking for a solution to protect the analog pins of the ESP32 microcontroller. My circuit can produce voltages up to 5V and the analog pins of the ESP32 can only withstand 3.3V max.

I found a solution online (picture attached) but I don't understand how the circuit works. I tested the circuit in LTspice and I don't get expected results.

Can you guys check if the circuit even works and if it does can you explain to me how and why?

Thank you!

#### Attachments

• 19.8 KB Views: 17

#### AlbertHall

Joined Jun 4, 2014
12,293
Providing the opamp can sink at least as much current as your circuit can provide it should work.

If the analog input goes more than 3.3V positive then there is negative feedback via the diode which will limit the output to that value.

If your circuit is able to produce a lot of current then you could put a resistor between the analog input and your circuit.

#### BobTPH

Joined Jun 5, 2013
8,092
What is wrong with a voltage divider?

#### Dusan123

Joined Aug 7, 2023
5
Providing the opamp can sink at least as much current as your circuit can provide it should work.

If the analog input goes more than 3.3V positive then there is negative feedback via the diode which will limit the output to that value.

If your circuit is able to produce a lot of current then you could put a resistor between the analog input and your circuit.
Aaaah I see, now I understand. Thanks man!

#### Ian0

Joined Aug 7, 2020
8,943
It would be really useful to know how the ESP32's GPIO protection circuits are arranged. For a proper microcontroller, that information would be in the datasheet.
In the absence of that information, place a schottky diode between the pin and Vdd, and a current limiting resistor about 1k.

#### Jerry-Hat-Trick

Joined Aug 31, 2022
447
What is wrong with a voltage divider?
You mention analog pins, so presumably you are using the pins the covert signals up to 5V into digital? The ESP32 is surprisingly non-linear near to 3.3V input, so I'd use a potential divider to drop the maximum of 5V to around 3.0V. In case you are not familiar with the concept, try connecting your sensor output to a 10K resistor, in series with a 15K resistor to ground. The maximum voltage at the point between the two resistors will be 3.0V. The processor itself has an input resistance, so you may get slightly less than 3V but you probably won't notice and it's best to calibrate (and scale) sensor values anyway..

#### MisterBill2

Joined Jan 23, 2018
16,534
I suggest using a series resistor to limit current and then a diode clamp circuit with the top voltage set to limit the input to the actual acceptable maximum.. The opamp scheme is likely to be rather non-linear, and that would limit the accuracy.