I'm trying to find a way I can toggle the 5V pin to turn on/off. I want the voltage to pass to another wire at a certain point. It should be off and then when something happens, the 5V should turn on.
How can I do this?
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It only takes a minute to sign up.
Sign up to join this communityI'm trying to find a way I can toggle the 5V pin to turn on/off. I want the voltage to pass to another wire at a certain point. It should be off and then when something happens, the 5V should turn on.
How can I do this?
For energy-efficient switching (along with relatively high-current capability), I recommend using a Darlington transistor connected to one of the output pins (digital for on/off, analogue for variable). Then you would just call pinMode(A0, OUTPUT); followed by digitalWrite(A0, HIGH); Here is a sketch I made demonstrating what I mean:
Note that a normal transistor would draw more current from the Arduino's pin, which could be bad for the Arduino, and which would waste energy.
There isn't programmatic control of the 5V pin, it is hard wired to the USB or the output of the Vin Voltage regulator.
You might try something from How can higher current devices (motors, solenoids, lights, etc.) be controlled by an Arduino? to control the low side of the external device. If you need high-side control, maybe an opto-isolator would be a good solution.
If I'm understanding you correctly, you want a 5 V output that is under programatic control. Do you know how much power you want to pull from the pin?
If the demand is fairly low, you could use one of the digital pins directly – they will supply about 40 mA on an "official" Arduino.
If you need more power, then you could use the pin to switch an external device such as a transistor or a relay.
You don't really want to do that. The 5V pin is on the power bus of your Arduino board. If it were possible to turn it off, the entire Arduino would shut down.