Now the general plan is to replace the push button by the relay,
but I'm not sure if I got the right relay and I'm not sure how to wire it.
Step by step:
There is an external 12 V battery. Now when the electric circuit (12 V) is closed the relay shall close the electric circuit (5 V) of the Arduino (just like the push button would have done that).
marCenzeichen:
There is an external 12 V battery. Now when the electric circuit (12 V) is closed the relay shall close the electric circuit (5 V) of the Arduino (just like the push button would have done that).
I doubt that It is Even Possible?
Why Don't you use a Potential divider Circuit and take a 5v input from Digital Input Pin ?
Whandall:
How about using an opto-isolator instead of the relay?
That's a good idea....
Remember to put big enough resistor on its input to limit the current to whatever your opto says it can handle through its LED.
And on the output side, switch the logic you currently have with the pull-down resistor to using a pull-up, which is easier to implement with the internal one using pinMode(pinNum, INPUT_PULLUP); .
How about using an opto-isolator instead of the relay?
sounds interesting!
Remember to put big enough resistor on its input to limit the current to whatever your opto says it can handle through its LED.
And on the output side, switch the logic you currently have with the pull-down resistor to using a pull-up, which is easier to implement with the internal one using pinMode(pinNum, INPUT_PULLUP)
An opto like a 4N25 is just an led on the input, so lose all the volts except for the led forward voltage across a series resistor while limiting the current.
So say 12V input, forward voltage about 1.5, lose 10.5V at say 40mA. So R= 10.5/0.04 so about 300 or more. As long as the internal led lights up the transistor.
The link shows how to wire up, and has link to datasheet.
You can leave the grounds separated for total electrical isolation.
Although we don't know what opto the OP would use if that was the solution chosen, I reckon a low current on the input LED will still trigger the transistor. The 4N25 datasheet for example, shows a test circuit with 10mA through the LED.
Let's be generous and say the input voltage goes quite high and we need to lose about 12V and have 10mA.
So that would give R= 12 / 0.01 = 1200 ohms so let's say we used 1K with and had 12mA. (In fact the link I gave above does show 1K but doesn't give an input voltage.) Then the power would be 144/1000 = 0.144W so a 1/4W resistor more than adequate.
I think I have some 4N25s lurking somewhere: if I can find one I'll see what resistor with 12V input still gives a reliable output. But it's not quite 6am Sunday so I might not get up for a while.... (except to make coffee).