How to detect when normally closed circuit is opened

Would you mind drawing your circuit? Do you control all of the voltages in your circuit.

The normal way to detect a open circuit is with a pull up or pull down resistor.

1 Like

The two terminal posts belong to another (black box) device so I can’t draw that. I am free to do whatever with the Core circuit, but it has to read those two terminals.

Should I test the terminals for voltage? I had thought I would only need to use the Core to find when the resistance goes from (nearly) zero to infinite.

What kind of voltage is at the two terminals? AC? DC? 5v? 12? 120?

@ssstraub, if the contacts are indeed “dry” meaning they are probably relay contacts with no voltage then the solution is simple. Connect one terminal to ground in your circuit and the other to a digital pin, say D2. Configure the digital pin to be an input with pullup. Now, simply read the state of the input. If it is high then the contacts are open. If low the contacts are closed.

3 Likes

@ssstraub, if the dry contacts are dedicated to the Core and not used to switch any voltage then:

  1. Use a digital or analog pin configured as a digital input and set it to use a pull-up resistor
  2. Connect the pin to one side of the dry contacts. Connect the other side of the contacts to GND.
  3. When the contacts are open, the Core will see a HIGH. With the contacts closed the Core will see a LOW. This is inverse logic but the Core’s 3.3V does not have to be connected to the contacts. This, IMO, safeguards the Core’s power supply.

The code is very straight forward:

pinMode(D2, INPUT_PULLUP);  //any digital or analog input pin can be specified

int contacts = digitalRead(D2);
if (contacts == LOW) 
   //contacts are closed
else
  //contacts are open

The other way to do it is to connect on of the contacts to the Core’s 3.3V and the other to a pin on the Core. The pin is set as a digital input but configured with a pull-down resistor. So with the contact open, the Core will see a LOW and when closed, the Core will see a HIGH.

pinMode(D2, INPUT_PULLDOWN);  //any digital or analog input pin can be specified

int contacts = digitalRead(D2);
if (contacts == HIGH) 
   //contacts are closed
else
  //contacts are open

:smile:

4 Likes

Ok, I’m starting to understand better now. Thanks. :smile:

Yes, it should be a relay with no voltage according to the instructions for the controller (it’s for a sump pump). I checked it with my DMM and didn’t see voltage. Found very low, almost unmeasurable resistance, which I guess is what I should expect for a short.

I think my code is close to what @peekay123 posted:

int alarmPin = D4;          // Alarm circuit pin
bool alarmState = false;    // Tracks current alarm state
int redLED = D3;

void setup() {
    pinMode(alarmPin, INPUT_PULLDOWN);
}

void loop() {
    // Check for alarm condition. 
    if (!alarmState and digitalRead(alarmPin) == HIGH) {
       setAlarm(true, "Alarm has been tripped!");
    }
}

// Sets alarm state. This will do more in the future
void setAlarm(bool alarm, String desc) {
    alarmState = alarm;
    if (alarmState) {
        digitalWrite(redLED, HIGH);   
    }
}

I have now changed it to INPUT_PULLUP.

I am working on this in a different location than the controller I want to connect to, and I don’t want to constantly trip that circuit anyway for testing. So can I simulate the behavior of the relay on those terminals by connecting a jumper from D4 to GND for the closed state and then pull the jumper off to trigger the open state?

Side note: I have found it’s handy to paste the Tinker code in my project for testing purposes. That way I can get the live value seen at any pin at anytime on the fly without needing to add more serial debug code or reflash. Pretty cool!

@ssstraub, yes that simulation would work just fine :smile:

1 Like

But and is not a boolean operation in C. You'd rather write &&.

2 Likes

Nice catch. Fixed! :smiley:

1 Like

Now all you need to do is use Spark Publish so you can access it via the web super easily :smile:

With the new IFTTT just published today, it looks like receiving notifications on my phone is now going to be stupidly easy.

I still plan on logging other data to graphs, so…

1 Like

Edit: Yeah I was thinking wrong product :smile:

Hi all

I have the same kinds of issue on how to detect open/close circuits.
did (A)one side 10k, 3.3V pull-up and (B)another side 10k, pull-down to GND.
when I do connect as close circuit, I can see only (B) side has the status as High, and (A) side is still stay as high , due to pull-up high.

How to make (A) side also get an state change to know the close circuit?
need both side controller get a connection info. with this simple pull-up/down concept… help me…

Regards
Vraifluss

I know this thread is old, but I have a similar question, but with the case where the ciruit will have 24VAC running through it. Believe it or not, I’ve googled and can’t quite find what I need in a way that I understand. I was wondering if someone could give me the “easy answer” that I can’t find anywhere else :). Maybe just a big enough resistor?

If by that you mean that:

When switch is “Closed” it has a voltage of 24VAC, and when it is “Open” it has a voltage of 0VAC or is floating.

Then this is more challenging and non-trivial. Unfortunately there isn’t a super simple solution for detecting AC voltage like there is for the case above. I would say that in fact this is a very different situation that would warrant a different thread.

Regardless, please refer to this forum post below. You will need to either use a resistive voltage divider network to step down voltages to 3.3VDC instead of 5VDC or pick different components (or configure them differently) to properly create a 3.3VDC signal at the max case.

https://rayshobby.net/wordpress/24vac-to-5vdc-conversion/

You could use an optocoupler, which would also isolate the 24Vac.

1 Like

i’m going to open a new thread… thx.

Fyi, here is the new thread. I created my first circuit diagram to make sure I'm clear :).

I need to do this, but i also want to protect the arduino in case someone puts 12 or 24v on the contacts. How would i do that where the contacts coukd be wet or dry?

If this is for an arduino, I would suggest searching through their forums. This forum is dedicated to Particle devices.