Question about measuring the State of Relays

I am looking at checking the state of a number of relays(Digital Input Seems to be the way to go to do this).. Most of them are 24VDC..

I am not very well versed in electronics at the moment... Still getting my toes wet.. So I am just making sure I get this right to keep that all important Magic Smoke on the inside of my arduino :slight_smile:

It looks like I should be using a Transistor... but I am a bit confused when it comes to the grounding (negative) side... It seems wrong to have the negative side of various DC circuits of varying voltage all tied together since most transistors are 3 pole ... or do I put resistors in line of the - side to bring voltage potential down to 5V for the digital input.

I looked at 4 pole transistors (was thinking a 4 pole with isolate the - side of the circuit but that didn't seem to be the case from what I understood) don't seem to be what I want to use (from what I can figure out on my own)...

So I guess my question is... to use the digital input of the arduino to see if a 24VDC relay is active I should use a transistor and resistors on the negative side of the circuit to bring voltage potential down to 5VDC for the digital input? or is there a better way to do it?

Ground is defined as 0 volts - that's the reference point (voltage is relative). You need to tie all of the DC grounds together.

Often the reason we use transistors is to allow a low voltage to switch a higher one.

You would tie the 24vdc negative (ground) to arduino ground.

Depending on whether you are using a FET or a BJT, the pins have different names (and are connected slightly differently).

Emitter/Source goes to this ground
Base/Gate goes to Arduino pin (through resistor if transistor is a BJT)
Collector/Drain goes to one side of the relay coil (the negative side, if it's a polarized relay).

You need one resistor: If it's a BJT, this goes between base and arduino pin (consult datasheet to sort out the right value - some darlingtons even have an integrated resistor). If it's a MOSFET, put a resistor (10k-100k, exact value not important) between Gate and Source, and gate goes directly to the arduino pin - this resistor just gently pulls the gate down to source, so if the Arduino isn't connected, or is in reset, the MOSFET will stay off.

Then +24 vdc goes to the other side of the relay coil.

A diode (1N4001 is fine) should be placed across the two sides of the relay coil, with the band towards positive side to clamp the back EMF when you turn it off.

Obviously, make sure your transistors are appropriately rated for the load. If using a MOSFET, make sure it is logic level drive (it should spec "Rds on" at 5v or less), and that the max Vds is 30V or more. I happen to have a product search page for logic level mosfets open, in case you don't have your transistors yet:

DrAzzy - that description certainly describes how to -switch- a relay using a transistor/mosfet - but it does nothing to answer the OP's question, which was how to sense the state (on/off) of a relay.

There are ways of doing this - the easiest being to use a multi-pole relay, and using one of the contacts as a switch to drive a digital input pin on the Arduino LOW.

Otherwise, you could try sensing current flow across the pins of the relay (basically just like you would measure any current - ie, use a hall-effect current sensor, or use a small-value resistor sized properly for the current, and measure the voltage drop).

Another way would be to use the voltage being switched to turn on a transistor or mosfet (or, ideally - the input of an opto-coupler - for isolation), and use that to trigger a pin on the Arduino.

There might be other methods, but those would be the two most common, I think.

No I think he did answer my question if we are thinking along the same lines... I was thinking about using the 24VDC current that is energizing the relay and a digital pin on the arduino to see it was being energized.

Initially I thought of using another relay (which would have been really simple) but other than simple it didn't seem like an elegant way to do it.. From all the reading I did it seemed a transistor was the way to go... I just don't have the knowledge/experience with electronics to fully understand how the negative side of of the circuits work..

Not that I don't appreciate your comments they are helpful

Aaah, ya - I misinterpreted the question as being one about how to drive the relay - sorry about that.

For sensing the state of the relay... if you're controlling it with the Arduino, you know the state of the relay, since you're controlling it, so I guess you're not doing that.

No I think he did answer my question if we are thinking along the same lines... I was thinking about using the 24VDC current that is energizing the relay and a digital pin on the arduino to see it was being energized.

Like DrAzzy says, if your Arduino is controlling the relay your software knows it's state (assuming nothing's failed).

Otherwise, you don't need a transistor or another relay. You just need a [u]Voltage Divider[/u] (two resistors) to knock the voltage down to 5V. The resistance isn't too critical It's the ratio that's important. I'd shoot for a total resistance of around 10K (low enough to minimize noise pickup but high enough that there's not much current). So, that would be resistors somewhere around 2K & 8K.

You'll also need a common ground between the relay coil and the Arduino. If there is no common ground and for some reason you can't connect the grounds, then you could use a relay or an opto-isolator.

If you're not sure the 24VDC is exact, and/or if you're not sure if there is a voltage-kickback diode across the relay coil, add a couple of [u]protection diodes[/u] at the Arduino input. That will protect against voltage spikes above 24V or negative voltage spikes. (You can skip the resistor that's shown, because of the resistors already in your voltage divider.)

Well now, you have two options.

If you want to verify that the relay has actually operated, the only way to really do that is by monitoring its contacts.

If, as is more likely, you want to know if the coil is energised, then the neatest way to do this, and avoiding problems with having a common ground, is to use an optocoupler such as a 4N35 (or a twin opto for even numbers of relays) with its LED side connected across the coil via a 2k2 series resistor and its output side between an Arduino input (set to INPUT_PULLUP) and ground.

Two components per relay - one opto, one resistor.