Determine Relay Status

I'm trying to determine if a relay is opened or closed in order to determine if specific code should be executed.

I am checking to see if the state is HIGH or LOW using the digitalRead command. Is it possible to use a regular arduino relay and if so how do I connect it.

I have also considered using a Bosch style automotive relay.

I'd appreciate any input

Is it possible to use a regular arduino relay

There is no such thing as "a regular Arduino relay". Arduino doesn't make relays.

ok..here are specs

Thanks

27115-Single-Relay-Board-Datasheet-709206.pdf (92.1 KB)

Do you want to know whether a relay controlled by an Arduino output pin is energised or not, or something else ?

If the former then surely you know whether it is energised or not because your code will have commanded it. You can read the state of an output pin if necessary but should not need to if you have a variable holding the current state.

If you want to know the state of a relay that is controlled by an external circuit you have a couple of choices. One is to read the state of the relay input pin but be careful of voltages and polarity. Another is to read the state of the relay output either by using a multi pole relay and using spare contacts to switch an Arduino pin to GND or 5V or possibly to read the state of a changeover relay contact if both ways are not used by the external device. Again, be careful of voltages and polarity.

what I would like to do is use a Bosch style automotive relay. The relay is powered on and off by 12v, not connected to the Arduino.

Then the Arduino would read if the relay is open or close just like it reads if a push button has been depressed.

Does this make sense

what I would like to do is use a Bosch style automotive relay. The relay is powered on and off by 12v, not connected to the Arduino.

That has clarified the situation a lot. What is the relay controlling, how is it wired and does it have spare contacts ?

Is the Bosch relay switched between +12 and relay or between relay and ground?

separate 12v and separate gnd from the arduino

The relay is controlling something. That is, it's controlled side is letting current flow, or it isn't. Tap into that side of the relay. Connect that to a voltage divider, to drop the voltage to 5V or less. From the middle of the voltage divider, run a wire to a digital pin. Connect all the grounds - the relay, the voltage divider, and the Arduino.

Set the pin mode to INPUT_PULLUP.

When the relay is on, the pin will read HIGH. When it is off, the pin will read LOW.

Without knowing if it's low side or high side switched, I would go with an opto isolator.

out.png

read the state of the relay output either by using a multi pole relay and using spare contacts to switch an Arduino pin to GND

If you don't already have the relay, just get a double pole relay, and use one side for the Arduino and the other for the 12v.

Please excuse my lack of knowledge. put a little help o9n the DPDT wiring would be appreciated.

I assume coil gets 12v and ground for non Arduino source. One side gets ground, 5v and signal from Arduino.

Not sure how other 3 legs are connected

double pole single throw (dpst) or double pole double throw(dpdt) would be ok.

The input coil is controlled by the external 12v source. One set of output teminals are used by the device powered by the relay. The other set of output terminals is for the Arduino. The most simple connection is one terminal wired to an arduino pin with pinMode INPUT_PULLUP. The other terminal is connected to ground. When the relay is activated, the Arduino input will be pulled LOW.

thanks I'll give it a try

Yeah, replace what's probably an essential automotive relay that's been approved for automotive use, and replace it with a cheap chinese hobby grade relay because some guy on the internet thinks that's a good idea.

Aka, don't do that.

What is the relay controlling?

Here's my 2 pesos worth :slight_smile:
New-Project.png

Ahhh, so the relay coil is energized by the brake switch and the relay contacts feed the Arduino input pin, correct?
relay-Ard.png

If I were doing that I would use an opto coupler as in reply #9 but if you still want to use a relay, get one like the Bosch thats MADE for automotive use, not a chinese cheapie, here's a simple sketch:

const byte relayPin = 7;

void setup() 
{
   pinMode(relayPin,INPUT_PULLUP);

}
void loop()
{
   if(digitalRead(relayPin == LOW)
   {
     do some stuff;
   }
}