Driving a relay with a micro-controller

Discussion in 'General Electronics Chat' started by minulescu, Apr 15, 2008.

  1. minulescu

    Thread Starter Member

    Apr 15, 2008
    13
    0
    I'm a bit confused about how to easily use a relay to control power flow.

    I have the following relay: 5V coil voltage, and nominal power: 900mW.

    So I assume this means then, that I have to provide 5V, 180mA, for the relay to work properly.

    Since I'm using a microcontroller, I'm pretty sure the 5V signal coming out of the DAC is much less than 180mA.

    I assumed it was pretty common to use a micro-controller to drive a relay, but I can't really find much info on it, and to add to that, the specs for relays are often somewhat confusing.

    Thanks for any help!
     
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    The uC can't supply that much current. But the output pin can drive either a logic level FET or a darlington transistor. We have had numerous threads on this topic with suggestions for the devices to use.
     
  3. Papabravo

    Expert

    Feb 24, 2006
    10,137
    1,786
    I am a bit surprised that you would use a DAC tor drive a relay. Normally a BJT in the common emitter configuration is used as a switch. This would be fed by an ordinary port pin. A microprocessor can easily provide 2 mA of base current to a transistor with a beta on the order of 100 to get you your 180 mA. The relay coil should have a diode to limit the flyback voltage when the transistor turns off.

    A slick alternative is to use a latching relay which requires a pulse in one direction to pull it in and a pulse in the reverse direction to let it go. Now your not wasting that 900 mW to keep current running through the coil. Here a driver like the TC4469 comes in real handy.
     
  4. minulescu

    Thread Starter Member

    Apr 15, 2008
    13
    0
    Thanks for the replies!

    beenthere: Thanks! I will look around the forum for these threads.

    Papabravo: I'm using a DAC mostly because I don't know what I'm doing. I looked at the TC4469 driver and it looks like its peak current is 1.2 A.

    Here's in more detail what I'm trying to do:

    I'm trying to control power to a motor. This is at 24V, up to 20A. I thought I would use a relay to do this (because I have heard of them, not because I have used one before for anything). The problem is, the regular I/O ports of my uC, provide 3.3V control signals, not 5V. But I also have a DAC on the uC, which can provide 5V.

    So I thought, that I would use the DAC to send a 5V control signal to the relay, which in turn would close the 24V circuit, and provide power to the motor.

    What is the difference between a regular I/O port signal, and a DAC signal anyway?

    Thanks in advance!

    Edit: And yes, I wish I could avoid the 900mW power consumption.
     
  5. Papabravo

    Expert

    Feb 24, 2006
    10,137
    1,786
    This is very odd. I have never heard of a uP with an onboard DAC. Can you provide a link to a datasheet? A DAC output is normally used to output an analog voltage over some range. In a typical digital output port there are two ouput values corresponding to ON and OFF or GND and VCC. In a DAC output there are 256 or 1024 or 4096 discrete values between VCC and GND that can be output depending on the width of the data word. No DAC on this planet is capable of driving that motor directly. You need something in between the uP and the motor. While you are at it, a link to the motor datasheet would also be helpful to understand your problem.

    The TC4469 is good for driving relay coils and small motors, and using two of the four functions in a package gets you a bidirectional drive for a single relay coil.

    I forgot to ask about what confuses you about relay specifications.
     
  6. Caveman

    Active Member

    Apr 15, 2008
    471
    0
    minulescu,

    A DAC is a digital to analog controller. Basically, you put in a number (aka. digital)and it puts out a voltage (analog). It is not right for this application. A standard output either drives high(3.3V) or low(0V).

    I think the relay is the right thing to do, but you're just not driving it right. If you look at a relay, it is basically an electromagnet next to some contacts. You put current into a coil, and it magnetically pulls a contact to touch another contact. What you need to do is put a transistor in there. See the attachment.

    The transistor can easily drive this relay, but the diode is needed, because when the relay is turned off, the coil will have an inductive kick which could blow the transistor. This will save the power.

    Also, just so you know, there are things called "latched relays". They are a little more expensive, but you just have to pulse the current for a bit (few ms), and it will stay on or off without current after that.

    Also, if you want to get away from the relay, you can get a high current FET, but you may have to heatsink it. I think the relay is better if you don't have to turn it on and off quickly and very often. The FET is better if you have to pulse it a bit.

    Hope this helps.
     
  7. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    papabravo,
    microchip's pic line of microcontrollers has a great many models with, dacs, adc's, and both.
     
  8. Papabravo

    Expert

    Feb 24, 2006
    10,137
    1,786
    I've seen the ADC and the comparators. Which ones have the DAC, and is it current or voltage output?

    You're not talking about a cheatin' DAC which is a PWM with a low pass filter are you?
     
  9. minulescu

    Thread Starter Member

    Apr 15, 2008
    13
    0
    Thank you all for your replies.

    Papabravo: I suppose I could have been more clear with what I'm using exactly. I suppose calling it a uC is not correct, what I'm using is a SBC, TS-7200, with a PC/104 daughter board TS-9700, that has an optional DAC, using Texas Instruments TLV5818 chips.

    And I am not trying to "drive" the motor with the DAC. I have a 24V battery for the motor, I just want to have remote control over the power to the motor controller / motor.

    Caveman: Thanks for that schematic, it makes good sense. I've seen other similar schematics, but the representation of the relay is usually done in a different way, which got in the way of my understanding.

    With your schematic though, it would seem that I would need an additional 5V source. And where would the 24V line be connected with the relay?

    Thanks all for your help, I feel I'm getting close to grasping this :).
     
  10. Caveman

    Active Member

    Apr 15, 2008
    471
    0
    minulescu,

    The +24V line from the battery would go to one contact. The other contact would go to one side of the motor. The other side of the motor would go to the negative battery contact. So when the contact closes, the circuit closes, and the battery drives the motor.

    If the DAC is driving 5V, it must already exist. I just used it directly.
     
  11. minulescu

    Thread Starter Member

    Apr 15, 2008
    13
    0
    Ok, I understand what you are saying. Thanks a bunch for your help... I think this is a great solution.

    One more newbie question for you.. Is the 500 ohm resistor an arbitrary number? Or how would you choose a value for that resistor?

    Thanks!
     
  12. Caveman

    Active Member

    Apr 15, 2008
    471
    0
    Actually, it was calculated. I apologize for the detail of what I'm about to say, but you asked.

    Since you are using the transistor as a switch, you want to drive it well into saturation (ie, turn it *really* on). If you look at how a bjt works, Ic = B*Ib, where B = beta (basically the same as hfe) is about 100. However, this number is when you are not saturated. What saturation effectively does is drop B down. So I assumed a lower B of about 40 or so (to make sure it is good and saturated). Ib = Ic/B and Ic = 180mA, so I want Ib to be about 4.5mA. The voltage across the resistor when on is 3V - 0.7V = 2.3V. Then, V/I = R = 2.3V/4.5mA = 511Ohms. So 510 is the closest 5% value.
     
  13. Audioguru

    New Member

    Dec 20, 2007
    9,411
    896
    A microcontroller is made with high-speed Cmos, not old TTL. its output goes to the supply voltage or to ground if it has low load current. Its output is about 3.5V when it has its max ouput current of 25mA.

    the transistor needs a base current of 1/10th its collector current to saturate wella sshown on its datasheet.
    So if the load is 50mA then the base current should be 5ma which is provided by a base resistor for the transistor.

    The output voltage of the microcontroller with a 5mA load is about 4.2V. The base-emitter voltage of the transistor is 0.7V. So the base resistor is (4.2V - 0.7V/5mA= 700 ohms. Use 680 ohms.
     
  14. Caveman

    Active Member

    Apr 15, 2008
    471
    0
    Audioguru,
    It was stated that this was a 3.3V driven microcontroller. It goes to rail. It cannot go to 3.5V.
     
Loading...