# Reading fan speed by ESP32

I have a case type 12 V 3-pin fan and I would like to connect its tach signal wire to an ESP32 input pin. Power supplies to ESP32 and the fan are separate, but the ground wire is common.

Based on some posts in google, internally the tach wire gets connected to ground wire twice during each fan rotation cycle. If it is that simple, should I just connect this wire to an ESP32 input pin and have a pull up resistor connected to 3.3 V? If so, what is the minimal reliable current or range the resistor should be calculated for - is it 12 mA or less? Or can the ESP32 pin be configured to use an internal pull-up resistor so the external resistor is not required?

• yeah, setting the gpio to INPUT_PULLUP should work to read open collector outputs. I would make sure that there's not ever 12v on the signal before connecting it to an esp, just in case the fan isn't like what you read or described. If it is 12v pulses, use a voltage divider to chip that to 3v, and set the GPIO as a normal INPUT Jan 22 at 8:56
• Read the answers to electronics.stackexchange.com/questions/69613/…; the easiest solution is a resistor and a diode to ensure you don't get 12V on your ESP32.
– Paul
Jan 24 at 15:32
• @dandavis. Kind of same question with regards to the voltage divider - should there be some current consideration? For example, to get 3 / 12 division, I can use 3K + 9K resistors, but I can also use 3M + 9M resistors? Jan 29 at 3:18
• targeting 1ma should suffice. Use INPUT instead of INPUT_PULLUP in that case. Jan 29 at 6:18
• @Paul. Being a person with some theoretical knowledge and virtually no practice, I found that solution elegant. But it helped me realize that, while I have some idea how to calculate resistors to connect MCU output pin to a transistor using load current, transistor current gain and Ohm's law, I have no idea how to calculate resistors for MCU input pin. That schematic shows 10K pullup resistor connected to the MCU's input pin, which should mean about: (5V - 0.6V) / 10K = 0.00044mA. Jan 30 at 1:13