replace push button by relay

Hey guys,

I got a push button for my arduino like this...

and i got a relay shield...

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).

  1. Can I use this relay or do I need another one?

  2. How do I have to wire it?

Thanks and regards

Marc

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 ?

I think that will do the Job for you..

Let me understand

You want the the 12v supply to close the relay ,and let the Arduino know its time to do some thing.

Yes you do have the wrong shield.

Your relay operates on 5v not 12..

The potential divider is your best bet. Its solid state..

How about using an opto-isolator instead of the relay?

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); .

Thx for your replies!

You want the the 12v supply to close the relay ,and let the Arduino know its time to do some thing.

Yes...
as long as the 12 V circuit is closed -> the Arduino does something.
When the 12 V circuit is open -> the Arduino doesn't do anything.

Like...
pushing a button -> do something (LED on)
stop pushing the button -> stop doing things (LED off)

Why Don't you use a Potential divider Circuit and take a 5v input from Digital Input Pin ?

The potential divider is your best bet. Its solid state..

Does it work even when the 12 V are not constant. I mean when the battery is charged / discharged, the voltage can be like (12 +/- 0.8) V.

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)

Thanks for your advice!

Does it work with 12 +/- 0.8 V ?

Thanks for your replies!

Regards

Marc

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.

Once again, good idea was Whandall's not mine....

Also, is it correct that the resistor in JimboZA's post would need to be rated for 1/2 watt?

P = V2/R = 102/300 = 1/3W so yep 1/2 I guess.

But if you use a bigger resistor, which may well still allow the opto's led to trigger its transistor, the power rating will drop.

If it worked at 1k, then the power would be 1/10W.

Then a person should ask ,if its a situation like a battery charger.. voltage's may increase to 14.4v to charge a 12v battery

then it would be something like a 330ohm 1w resistor.. there abouts.

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).

1k will do it.

Chris1448:
1k will do it.

Yep just tested 4N25 with 12V on the input even with 2K which gives 5mA measured, it switches the collector properly.

(edit... even with 10K and 1mA the collector switches. Got bored and didn't try any others.)