Sinking Current with ESP8266 [SOLVED]

gatoruss
Posts: 2
Joined: Mon Jan 15, 2024 2:33 pm

Sinking Current with ESP8266 [SOLVED]

Postby gatoruss » Mon Jan 15, 2024 3:04 pm

Hi.

I am experimenting with an 2n7000 mosfet and a d1 mini pro (esp8266). My code toggles between the LED_BUILTIN and an external LED on pin D5 (alternating the LEDs). I am trying to drive the external LED with the 2N7000 using the circuit below.

Image

(Note "muc" --> "mcu"

My understanding of this circuit is that:

[*] when the D5 is LOW, there will be a voltage across the gate and source which will turn ON the mosfet causing current to flow from the drain to the source -- turning the external LED OFF.
When the DE is HIGH, there will be no voltage across the gate an source which will turn OFF the mosfet causing the current to flow thru the external LED -- turning the external LED ON. [*]

If I set pin D5 to output (using pinMode(D5, OUTPUT)), the LED is continuously ON -- meaning that the mosfet never turns ON. This suggests to me that the D5 pin is not sinking current when LOW as an output.

Alternatively, if I set pinMode(D5, OUTPUT_OPEN_DRAIN), then the circuit behaves as I anticipated -- taggling LED_BUILTIN and the external LED.

My question: Did I misunderstand the behavior of a an output pin when LOW? I had expected D5 to to sink current (behave like an open-drain) when LOW as OUTPUT.
Attachments
2n7000.png
2n7000.png (22.78 KiB) Viewed 11489 times
Last edited by gatoruss on Tue Jan 16, 2024 8:11 pm, edited 1 time in total.

gatoruss
Posts: 2
Joined: Mon Jan 15, 2024 2:33 pm

Re: Sinking Current with ESP8266

Postby gatoruss » Tue Jan 16, 2024 8:09 pm

I have been digging around some more, and have re-examined my circuit several times. Embarrassingly, while my circuit was arranged correctly, I had a loose connection that caused the unexpected behavior.

I seem to have the circuit working correctly now. If D5 is LOW, the mosfet is ON and the external LED is OFF; if DE is HIGH, the mosfet is OFF and the external LED ON.

Who is online

Users browsing this forum: No registered users and 57 guests