relay to microcontroller input

Discussion in 'The Projects Forum' started by bionio, Jan 18, 2014.

  1. bionio

    Thread Starter New Member

    Feb 21, 2011
    3
    0
    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?
     
  2. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,501
    380
    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
     
  3. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    You should post a schematic.
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
  5. MikeML

    AAC Fanatic!

    Oct 2, 2009
    5,450
    1,066
    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.
     
  6. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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.
     
  7. bionio

    Thread Starter New Member

    Feb 21, 2011
    3
    0

    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.
     
  8. MikeML

    AAC Fanatic!

    Oct 2, 2009
    5,450
    1,066
    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.
     
    • rly.jpg
      rly.jpg
      File size:
      69.3 KB
      Views:
      43
  9. Alec_t

    AAC Fanatic!

    Sep 17, 2013
    5,779
    1,103
    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)?
     
  10. MikeML

    AAC Fanatic!

    Oct 2, 2009
    5,450
    1,066
    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.
     
Loading...