Using one circuit to switch another - (basic!)

Hi. Here's a noob question for you

I have one circuit with a power source (batteries) powering an led, controlled by a switch.

I want this same switch (single pole) to also set an arduino pin HIGH when it is pressed.

Can I use a transistor? From what I've been reading here - Using Transistor as a Switch | ermicroblog I should be able to use something like a 2n3904 transistor to switch the arduino pin high when there is a current in the other circuit, but I cant work it out.

Am I going about this the right way? And do both circuits need to be powered from the same power source for this to work?

Thanks

An Arduino pin set as an INPUT is a high impedance input. So you do not need to "switch" it on. What is the high voltage of the switch that turns on the LED? If it is 5V you can just connect the Arduino INPUT pin to the same point as the high-side of your switch.

And do both circuits need to be powered from the same power source for this to work?

Voltages are based on references, so all components which are connected to each other much share the same reference. In this case, it means the GROUND of each "circuit" should be connected together.

GROUND is another way of saying "reference plane."

You have to share GNDs between the two systems. If the current circuit has a voltage approx 4.5-5v (say 3 AA cells) you could feed the signal that powers the LED directly into an Arduino pin.

If it's a higher voltage (or a lot lower) a transistor would work, using a diagram from that link

you would run a wire from where it says "non-inductive load" to the Arduino input, and "Microcontroller IO port" is your LED circuit. The signal will be inverted so if you read a LOW the button is pressed.

And do both circuits need to be powered from the same power source for this to work?

No, just share GND.


Rob

Thanks, I'll have a play and get back to you

The voltage is 5.9v Will this be too much for the arduino pin?

The voltage is 5.9v

Then another (simpler) option is to step it down with a voltage divider.


Rob

Yes that worked.

Thanks!