Page 1 of 1

Monitoring A/C redundancy box outputs "dry contacts"

Posted: Tue Jun 23, 2020 11:28 am
by apvi
Hi All,

I am looking into setting up a RaspberryPi for monitoring our A/C redundancy box. The box has 4 outputs, 2 for each A/C unit. One is giving the status of operation and the other is for if the A/C is malfunctioning or not operating. The outputs are described as "dry contacts" (relays).

In the end what I would like is to have the Pi connected to the network and send out emails through our mail server if one of the A/C has failed.

Attached is a picture on how the contacts look and how they are wired. Sadly this is all that is on the documentation I have available.

How would I begin to connect and start monitoring what I get on each relay?

Any input or hints on where to begin is appreciated.

Thanks.

EDIT:
After a bit more reading as I understand what I would need to do is: going from left to right on the picture.. connect the first connector with 3.3V pin on the Pi, the 2nd connector to a GPIO and the 3rd to GRND/0V? I would do the same for the 2nd relay and for the 3rd and 4th relay I would need to use the 5V power pins?
Then I would only need to monitor if I am getting HIGH/LOW on the connector I wire up with the GPIO on the Pi..

Re: Monitoring A/C redundancy box outputs "dry contacts"

Posted: Tue Jun 23, 2020 1:05 pm
by ElEscalador
You need only the pis gnd or 3.3 v, but not both. Err... I suppose it could be done that way but find a tutorial on reading a push-button with the programming language of your choice. Typically, we either connect the gpio pin we will monitor to either 3.3v or ground through a resistor of somewhere from 10k to 50 k ohms. The pi has internal ones we can enable with software - using the PIGPIO library it's as easy a line of code..this is called pulling the pin up or pulling the pin down. I prefer to pull pins up, so any time they are not connected to ground through my switch (AKA dry contact), the "pullup" makes the pin read high. Now simply connect the normally open terminals on your contacts to the monitored pin and the pi's ground. When you know how to read it that way (practice simulating the really closing by just touching the gpio pin to ground momentarily) The next trick is using that to trigger the email. Look into SMTP for that - figure out how to do that separately then connect the two parts.

(I think this can all can be done with shell scripts/callbacks - but I have not done this).

Re: Monitoring A/C redundancy box outputs "dry contacts"

Posted: Tue Jun 23, 2020 1:24 pm
by pcmanbob
Hi.

For the monitoring of the relay contact I would suggest a circuit like this ( one for each relay each using a different gpio input ) this with the relays in the state shown would give you a high as the normal state, go low when the relay changes over ( I assume it does this on problem detected )

Image


You can then use python to run a simple loop checking each input for a low input, you can then sent an email directly from python using smtplib and a gmail account ( I suggest setting one up just for your pi to use ) having different subjects and body test for each error. different.

Here is an example of how to send mail from python

Code: Select all

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders

email_user = "account@gmail.com"
email_password = "password"
email_send = "address to send to"

subject = "Test email from pi"

msg = MIMEMultipart()
msg["From"] = email_user
msg["To"] = email_send
msg["Subject"] = subject

body = "Hi there, sending this email from Python!"
msg.attach(MIMEText(body,"plain"))

text = msg.as_string()
server = smtplib.SMTP("smtp.gmail.com",587)
server.starttls()
server.login(email_user,email_password)


server.sendmail(email_user,email_send,text)
server.quit()
and some basic input reading code

Code: Select all

import RPi.GPIO as GPIO
import time


GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(23, GPIO.IN)
GPIO.setup(24, GPIO.IN)
GPIO.setup(25, GPIO.IN)
GPIO.setup(8, GPIO.IN)


# you need to have the 3 messages on the pi in wav format in the /home/pi dir this example

while True:

    if GPIO.input(723) == 0:
        print("Alarm R1")
        
        
    if GPIO.input(24) == 0:
        print("Alarm R2")
        
        
    if GPIO.input(25) == 0:
        print("Alarm R3")
    

    if GPIO.input(8) == 0:
        print("Alarm R4")   

    time.sleep(5)
    

Re: Monitoring A/C redundancy box outputs "dry contacts"

Posted: Tue Jun 23, 2020 5:40 pm
by davidcoton
apvi wrote:
Tue Jun 23, 2020 11:28 am
connect the first connector with 3.3V pin on the Pi, the 2nd connector to a GPIO and the 3rd to GRND/0V?
No. Not that. That will short out the 3V3 supply, which is something that some Pis really object to. It will crash any Pi, some of them permanently.

As others have said, you only need two contacts. After that there are several possible wiring schemes, depending on whether you switch 3V3 or 0V (my preference), and whether you use the normally open (NO) or normally closed (NC) contact -- that affects what happens when the power to the AC fails.

Re: Monitoring A/C redundancy box outputs "dry contacts"

Posted: Wed Jun 24, 2020 7:19 am
by apvi
Many thanks for all the replies. I believe I got the gist of where to start and what to do. But also a few more questions..
pcmanbob wrote:
Tue Jun 23, 2020 1:24 pm
For the monitoring of the relay contact I would suggest a circuit like this ( one for each relay each using a different gpio input ) this with the relays in the state shown would give you a high as the normal state, go low when the relay changes over ( I assume it does this on problem detected )
In your schema, what does the black dot that leads to GPIO pins 24 and GND indicate? How are the two cables connected at that point?

As this is a dry contact, wouldn't I need to connect it to a power source somewhere to get a current through it? So the only options are 3V3 and 5V I thought. If I connect to ground there will not be any current and I would not notice if the switch closes/opens, or?
Do I need the resistors if this is the case?

Thanks!

Re: Monitoring A/C redundancy box outputs "dry contacts"

Posted: Wed Jun 24, 2020 8:09 am
by pcmanbob
So yes the black dot indicates that all wires at that point are connected , its up to you how you do this for testing a would suggest you use a breadboard , then you can set up all 4 circuits and once it working move it to a prototyping pcb for a soldered solution.

So you should never connect 5v or any voltage greater than 4V to a gpio pin or you will kill your pi.

So if you look at the diagram we have a connection to the 3.3V pin which is connected to the com terminal on the relay output, so in the normal state current flows from the 3.3v pin through the rely com & N/C via the 1K resistor to the gpio input giving us a high ,
there is some current flow via the 10K resistor to ground but its very small.

Image

when the relay operates this circuit is broken by the relay contact changing over so now the gpio pin is only connected to ground via the 1K resistor and the 10K resistor and so giving us a low

Image

I suggested using external resistor for 2 reasons

1. they give better pull up/down on unknown relay contacts as in your case.
2. they give a better pull up/down in a noisy electrical environment like you might find in your equipment.

if you want to understand pull up/down try looking at this web site.
https://github.com/raspberrypilearning/ ... up_down.md

Re: Monitoring A/C redundancy box outputs "dry contacts"

Posted: Wed Jun 24, 2020 9:21 am
by drgeoff
pcmanbob wrote:
Wed Jun 24, 2020 8:09 am
So if you look at the diagram we have a connection to the 3.3V pin which is connected to the com terminal on the relay output, so in the normal state current flows from the 3.3v pin through the rely com & N/C via the 1K resistor to the gpio input giving us a high ,
there is some current flow via the 10K resistor to ground but its very small.
The current flowing through the 10k resistor is actually larger than the current into the GPIO pin.

Re: Monitoring A/C redundancy box outputs "dry contacts"

Posted: Wed Jun 24, 2020 11:32 am
by boyoh
Is this project possible using OPTO ISOLATORS You can use the Relays N/C or N/O, You will have the option to do as you want

Pi 5v to relay common

Relay N/C--------------------( R )--------------( a opto k )--------------grd
pi 3.3v Rail------------------------------------------( c T e )-------------------------------GPIO I / P--------------( 10k )----------OV_

Have just illustrated how it might be don.

You have the option of using N/C or N/O Your choice

Calculate R to give 10ma for opto led
T = Opto Transistor

Regards BoyOh

Re: Monitoring A/C redundancy box outputs "dry contacts"

Posted: Wed Jun 24, 2020 11:36 am
by pcmanbob
boyoh wrote:
Wed Jun 24, 2020 11:32 am
Is this project possible using OPTO ISOLATORS You can use the Relays N/C or N/O, You will have the option to do as you want

Pi 5v to relay common

Relay N/C--------------------( R )--------------( a opto k )--------------grd
pi 3.3v Rail------------------------------------------( c T e )-------------------------------GPIO I / P--------------( 10k )----------OV_

Have just illustrated how it might be don.

You have the option of using N/C or N/O Your choice

Calculate R to give 10ma for opto led
T = Opto Transistor

Regards BoyOh
As the existing relay contacts are voltage free I don't see any advantage of adding the opto isolator, the existing contact should work just fine with the resistors giving you a pull up and down at 3.3v.

Re: Monitoring A/C redundancy box outputs "dry contacts"

Posted: Wed Jun 24, 2020 4:01 pm
by davidcoton
pcmanbob wrote:
Wed Jun 24, 2020 11:36 am
As the existing relay contacts are voltage free I don't see any advantage of adding the opto isolator, the existing contact should work just fine with the resistors giving you a pull up and down at 3.3v.
Agreed, except that you don't want a "pull up and down" -- you pull (external or internal) one way, and let the relay contact take it the other way.