3
\$\begingroup\$

Imagine I have a 5v wire connected to a resistor, a button, an LED, and a pin set to ground. When I press the button the LED goes on.

I want to be able to recreate a circuit like this without the button so that the LED can switch between on and off while the code is running. The catch is that I cannot change the 5v pin from 5v and I cannot change the ground pin to 5v. I need to either be able to change the ground pin to and from a high impedance state or use some sort of replacement for the button that the Arduino can control. Unfortunately it seems that digital pins cannot be switched between input and output while the code is running and I can't figure out any other way to solve this.

The reason I ask: I am trying to wire a PCB designed to be controlled by button presses so that I can control it with Arduino. By default the PCB has one 5v, one ground, and four buttons, depending on what button is pressed one of four things happens. I attached a wire to each button, and if I set one of those wires to ground its just like I pressed the button. But I need to be able to control which button is 'pressed,' and I can't figure out how to do that.

\$\endgroup\$

1 Answer 1

5
\$\begingroup\$

You can add a parallel path with a transistor for current to flow from your 5V rail through the LED to ground. Effectively you're building an OR-gate, so the LED will be on if the button is pushed OR your micro-controller decides it wants the LED on.

Here's an example schematic using a N-channel MOSFET. The MOSFET is on when the IO pin is driven high, and it's off when the IO pin is driven low.

example schematic

\$\endgroup\$

Your Answer

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

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