0
\$\begingroup\$

The more I think about it the more I confuse myself... In the attached circuit if I want to simulate the effect of SW1 (or SW2) closing to ground how do I set the MCU-pin? Connect to Terminal 2 of the SW to one MCU-pin, and via Pinmode-set to INPUT for high impedance when the SW is OPEN? And then DigitalWrite-LOW while in INPUT (for low impedance) to CLOSE the SW? Or I need to change Pinmode to OUTPUT and then LOW (for low impedance) to close the SW?

I think I got the NPN transistor "switch": connect Base to a pin and set Pinmode-OUTPUT-HIGH if I want the transistor to conduct to E from C. And then set to Pinmode INPUT (no pullup) for high impedance to stop it from conducting.

enter image description here

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Yes for simulating a button you must have a low output to ground it or high-impedance input (no pull-up or pull-down) to let the pin float.

For driving the transistor, you can just have an output that is set low or high. No need to change it to a floating input.

However the VIN must never exceed the MCU supply voltage, if SW is connected to MCU IO pin.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.