relay to microcontroller input

Thread Starter

bionio

Joined Feb 21, 2011
3
Hi all, I want to connect a SPDT relay to GND, a 5 DC power supply and to my microcontroller. When the relay is energized it latches from gnd to 5v. Is there any issues in connecting it in this way without damaging the microcontroller?
 

ericgibbs

Joined Jan 29, 2010
18,734
hi bi,
Its important to have a clamping diode across the relay coil, the coil winding is inductive and will create a high voltage transient spike when the current is switched OFF.

Your description of the way the relay is connected to the PIC is not clear.?

Is the relay coil connected from +5V at one end and to the PIC pin on the other end of the coil.??
If yes, ensure that the relay coil resistance is not less than 250R, so that it draws 20mA or less.

E
 

MikeML

Joined Oct 2, 2009
5,444
I interpret the OP as wanting to use a formC relay contact to an Input of a ucontroller.

The OP proposes to hook 5V to NO, Gnd to NC, and connect Com to the uC Input.

That is not the way I would do it. As the relay armature is moving from one state to the other, the uC input becomes disconnected.

I would use only the form A relay contact (NC to gnd and Com to uC input; NO open). I would put a pull-up resistor (10K to 100K) from the uC pin to +5V.
 

t06afre

Joined May 11, 2009
5,934
I interpret the OP as wanting to use a formC relay contact to an Input of a ucontroller.

The OP proposes to hook 5V to NO, Gnd to NC, and connect Com to the uC Input.

That is not the way I would do it. As the relay armature is moving from one state to the other, the uC input becomes disconnected.

I would use only the form A relay contact (NC to gnd and Com to uC input; NO open). I would put a pull-up resistor (10K to 100K) from the uC pin to +5V.
Yes you are probably correct. The relay is probably used for input
@bionio!
A relay switch may be considered as any other mechanical switch. They have problems like switch bouncing, and some approach to debouncing should be taken https://www.google.com/search?q=switch+debouncing Another important thing is that a then a MCU input is not connected to anything (floating) it will most probably give high level (+5 volt). But noise may cause it to switch from this level. So a floating input shall be regarded as undetermined.
 

Thread Starter

bionio

Joined Feb 21, 2011
3
Yes you are probably correct. The relay is probably used for input
@bionio!
A relay switch may be considered as any other mechanical switch. They have problems like switch bouncing, and some approach to debouncing should be taken https://www.google.com/search?q=switch+debouncing Another important thing is that a then a MCU input is not connected to anything (floating) it will most probably give high level (+5 volt). But noise may cause it to switch from this level. So a floating input shall be regarded as undetermined.

That was a quick response! Ok great, I remember about debouncing, since this application will not be used for fast switching, I believe I can correct this using a delay in software ~1 second. I also like MikeML's approach of using a pull up resistor.
 

MikeML

Joined Oct 2, 2009
5,444
Alternate way which includes debounce (eliminates software debounce code) and holds the pin voltage either high or low until the contact transitions to the other state.
 

Attachments

Alec_t

Joined Sep 17, 2013
14,263
Will that time constant be big enough, Mike? What is the relay switching time likely to be (recent reading for pcb latching relays gives ~3ms)?
 

MikeML

Joined Oct 2, 2009
5,444
Will that time constant be big enough, Mike? What is the relay switching time likely to be (recent reading for pcb latching relays gives ~3ms)?
The time constant in question the effective CMOS input resistance (leakage) times 100nF after the relay contact breaks and only has to hold until it makes on the other side. The 100Ω is there just to limit the inrush current while charging/discharging the capacitor.
 
Top