1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Starter question: Trying to understand transistors

Discussion in 'Circuit Simulation & PCB Design' started by rafvervink, Nov 29, 2016.

  1. rafvervink

    rafvervink New Member

    Joined:
    Nov 29, 2016
    Messages:
    8
    Likes:
    0
    Greetings,
    I'm trying to get some basic grasp of how transistors work.
    Made the following setup:
    https://circuits.io/circuits/3371174-transistor-test
    For the led it seems to work, but the engine doesn't get any power...
    The purpose of this setup is to be able to switch on the engine (5V circuit) with a signal from the arduino (3.3V circuit). I'm also aware i might be looking at this completely wrong :/

    Any help would be very much appreciated!
     
  2. Les Jones

    Les Jones Well-Known Member

    Joined:
    May 15, 2015
    Messages:
    1,474
    Likes:
    191
    Location:
    Lancashire UK
    I do not think you will find a relay that can be driven from the output of an atmel microcontroller running on 3.3 volts. You will need a transistor to amplify the signal. Connect the emitter of an NPN transistor to the ground (Negative voltage rail.) of the Arduino. Connect the base of the transistor to the output pin that you are using on the arduino via a 1K resistor. Connect one end of the relay coil (I will assume that you are using a relay with a 5 volt coil.) Also connect a diode in parallel with the relay coil with the negative end to the end of the coil that the transistor is connected to. Connect the negative of your 5 volt power supply to the emitter of the trabsistor and the positive output to the end of the relay coil connected to the positive end of the diode. Almost any common small NPN transistor will do. (BC337, 2N3704 etc.) One of the 1N400x series of diodes will be suitable. (If it is a very small relay even a 1N4148 diode will be OK.

    Les.
     
  3. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,718
    Likes:
    37
    .... yah , even though arduino is 5v you are on 3.3v pin
    also your relay is hooked completely wrong... you do not wire it like a transistor, you are completely missing 2 wires !
    the arduino should be attached to the coil in the middle and should lead to ground to close the circuit, and actually, that 5v power pin will want to be moved to your output pin so the relay isnt always "ON" , the device being switched should be on the outer contacts of the relay and should use the "switch " diagram as shown for the corner pins

    so your arduino ground is hooked up ok, but even if you were using the 5v pin on arduino it goes nowhere, you need to hook it to the other side of your switching coil

    on the switch side of things, you need to move either ONE of those wires to the other side of device
    here is a diagram that shows how the relay works better... which is again different from a transistor
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. rafvervink

    rafvervink New Member

    Joined:
    Nov 29, 2016
    Messages:
    8
    Likes:
    0

    First of, thank you both for taking the time to reply... I realise this is very basic stuff :) It's been 10 years since i've done any electricity.
    A little clarification maybe on what the overall goal is. I send out a (3.3v) signal over one of the pins and the engine starts turning.
    I've updated the diagram as best as I could from both replies, but i'm pretty sure both components are still hooked up wrong.
    Mostly the emittor of the transitor seems to be wrong to me, shouldn't it go to the relay? And i'm probably still missing two wires on the relay, but I didn't find the diagram you referred to.
    Anyway, if you gentlemen could have a quick look... would save me alot of time and most likely a few burned down arduino's!


    upload_2016-11-29_14-47-42.png
     
    Last edited: Nov 29, 2016
  6. MikeMl

    MikeMl Well-Known Member Most Helpful Member

    Joined:
    Mar 17, 2009
    Messages:
    11,139
    Likes:
    566
    Location:
    AZ 86334
    Here is what you need to know:
    1.What is the motor voltage?
    2.What is the motor starting current?
    3.What is the motor running current?

    Knowing that, we could pick a suitable relay. Is the one you show up to the task?

    The relay you have chosen http://datasheet.octopart.com/LU-5-R-Rayex-datasheet-10584258.pdf has a max contact current rating of 2A. Is that enough to switch the motor?

    Presumably, you intend to write code to switch a port pin high/low to start and stop the motor? The UNO runs on 5V when powered with the USB, meaning that its port pin will be close to 0V when low, and close to 5V when high. The port pin can only deliver <40mA to an external load, per the limitations of the port pin circuitry inside the ATMEL chip. Is that enough to drive the relay coil?

    According to the relay data sheet, the coil voltage requirement is nominally 5Vdc @ 40mA, so connecting the relay coil directly (without a transistor) to the port pin might just barely work. However, it would be marginal, because the ATMEL port pin will not simultaneously deliver 5.0V and 40mA. It will deliver 5.0V @ zero current, but might only deliver 3.5V @ 40ma, so putting a switching transistor between the port pin and the relay coil is a good idea.

    Another thing to check: How much extra power can you expect to steal from either the 5Vout or the 3.3Vout pins on the UNO? You would have to read the UNO specs to find out. It may turn out that the relay coil should be powered from the external power supply that runs the motor; not from either the 3.3Vout or 5Vout pins on the UNO.

    After you answer some of these basic questions, we can show how to hook up a transistor to switch the relay coil.

    Note that you do not have the motor side of the relay wired correctly. Look at the pin out, below:
     

    Attached Files:

    Last edited: Nov 29, 2016
    • Informative Informative x 1
  7. rafvervink

    rafvervink New Member

    Joined:
    Nov 29, 2016
    Messages:
    8
    Likes:
    0
    Hey Mike, thanks for the reply. In an attempt to make it easier to reply i might have oversimplified some things.
    First, I'm actually using a raspberry Pi 3, not an UNO, but that should change little to the power output if i'm correct.
    Second, i'm not starting the engine directly. I want to hook it up to my garage engine, so all i need to do is simulate the button pressed and the engine's powersource should start it up.
    The garage engine part i'm hooking up to is running on 5V.
    You are correct, i've written code to switch the pin to high/low. But my attempt is to send a pulse, which should emulate the button pressed.

    Components i'm currently using (but i can get others if needed):
    https://www.kiwi-electronics.nl/downloads/BC547B.pdf
    https://www.kiwi-electronics.nl/relais-5v-3a-spdt-latching

    If you need any more information, just let me know! I'm already very happy I got a place to turn to after a few nights of fruitlessly roaming google!

    kind regards
     
  8. rafvervink

    rafvervink New Member

    Joined:
    Nov 29, 2016
    Messages:
    8
    Likes:
    0
    I have redone the relay wiring to start narrowing down my mistakes. So far i've gotten this to work according to the circuit.io simulation.
    https://circuits.io/circuits/3374128-relay-test
    (yellow wire connected to the power for test, should be connected to a gpio pin)

    So I'm trying to list my questions as clear as possible:
    1. Will this work irlf?
    2. I'm not sure I understand the need to add a transistor. Is it just to ensure the current on the yellow wire is large enough to activate the relay?
    3. Do I need a diode in this setup?
    4. Is there any danger of damaging the arduino/pi in this setup, or does the relay effectively keep both circuits seperate?

    kind regards
     
  9. Les Jones

    Les Jones Well-Known Member

    Joined:
    May 15, 2015
    Messages:
    1,474
    Likes:
    191
    Location:
    Lancashire UK
    Looking at the relay that you have chosen an arduino would be right on the limit of it's current ratings (40 mA) if you connected it directly to an I/O pin without the transistor. If it was used this way without a diode across the coil it would still probably destroy the I/O pin driver on the arduino. The raspberry Pi I/O pins are only rated at 16 mA and 3.3 volts so they would not drive the relay directly. This is how I suggest connecting it up.
    Relay driver.jpg

    Les.
     
  10. MikeMl

    MikeMl Well-Known Member Most Helpful Member

    Joined:
    Mar 17, 2009
    Messages:
    11,139
    Likes:
    566
    Location:
    AZ 86334
    Please tell us what is a "garage engine"???

    Why did you change from a momentary relay to a latching relay???
     
  11. Les Jones

    Les Jones Well-Known Member

    Joined:
    May 15, 2015
    Messages:
    1,474
    Likes:
    191
    Location:
    Lancashire UK
    Well spotted Mike. I had not noticed that rafvervink has now changed over to a latching relay. rafvervink, What is the reason for choosing the latching relay ? The schematic I posted will not work with a latching relay. The simplest circuit I can think of to drive a latching relay from one I.O pin would require 3 transistors and a fairly large value capacitor. (Non polarized capacitor)
    Mike,
    I think rafvervink probably means a garage door opener when he says "garage engine".
    Les.
     
  12. rafvervink

    rafvervink New Member

    Joined:
    Nov 29, 2016
    Messages:
    8
    Likes:
    0
    Hm, garage engine might not be the correct word in english... something like http://www.allaccessgaragedoor.com/image/garage-door-motor.jpg
    I wasn't aware i switched relay types. I'm using circuit.io to draw up the schematics, but they have a limited amount of components to use.
    So apparently I have the wrong type of relay. I'll get a momentary relay.
    Apologies for the confusion.
    Besides this, the drawing Les Jones made seems to be the type of setup I need.
     
  13. MikeMl

    MikeMl Well-Known Member Most Helpful Member

    Joined:
    Mar 17, 2009
    Messages:
    11,139
    Likes:
    566
    Location:
    AZ 86334
    Have you ever seen a garage door operator (1/4hp AC motor) that could be switched directly with such a small relay?

    I think that rafvervink means to parallel his small relay contacts with the garage door push button???

    If so, he shouldn't be using a latching relay, but a momentary relay... The software can simulate the button push, including the dwell time of how long the simulated button is held down.
     
  14. spec

    spec Well-Known Member Most Helpful Member

    Joined:
    Oct 27, 2015
    Messages:
    5,828
    Likes:
    710
    Location:
    Somerset UK GMT
    Hi rafvervink,

    Below is a circuit for you to consider.

    spec

    2016_11_29_Iss1_ETO_SBC_MOTOR_CONTROLLER_VER1.jpg
     
  15. rafvervink

    rafvervink New Member

    Joined:
    Nov 29, 2016
    Messages:
    8
    Likes:
    0
    Yes Mike, you are correct. I'm not attempting to start the engine with this relay. There is a system in place that will do this for me. I simple need to emulate the button push. I'll look for the correct type of relais (https://www.kiwi-electronics.nl/relais-5v-3a-spdt-monostable) and build the circuit Les Jones proposed. Thank you very much for all the help thus far... and the patience.
    I'll come back once i've made some progress! Hopefully just to tell you it worked ;)
     
  16. MikeMl

    MikeMl Well-Known Member Most Helpful Member

    Joined:
    Mar 17, 2009
    Messages:
    11,139
    Likes:
    566
    Location:
    AZ 86334
    rafvervink,

    can you obtain any of the relays in this link in your locality?

    If yes, then you can dispense with the transistor, and switch the relay coil directly from the port pin on the uprocessor.
     
  17. rafvervink

    rafvervink New Member

    Joined:
    Nov 29, 2016
    Messages:
    8
    Likes:
    0
    Yes, I can get this one. It'll be in tomorrow
     
  18. MikeMl

    MikeMl Well-Known Member Most Helpful Member

    Joined:
    Mar 17, 2009
    Messages:
    11,139
    Likes:
    566
    Location:
    AZ 86334
    Ok, now one more confirmation: The Rasberry Pi port pin, does it put out 0V(low) and 3.3V(high) , or does it put out 0V(low) and 5V(high)?

    Postscript: I answered my own question by reading this.

    In that case, here is what I would recommend:
    D20.png

    Note that the "button" is pushed while the port pin is "high".

    When I finally realized that the Pi's port-pin only puts out 3.3V, then driving the relay directly is not possible, and the switching transistor is required. Note how the snubber diode clamps the collector voltage just 0.6V above the 5V supply voltage as the transistor turns off. The snubber must be used... The actual coil current of the relay becomes less important; the original 40mA relay you showed would have worked...

    Now I can almost anticipate your next question: How do I tell my Pi if the garage door is open or closed? I have some ideas on how to do that.
     
    Last edited: Nov 29, 2016
    • Thanks Thanks x 1
    • Agree Agree x 1
  19. rafvervink

    rafvervink New Member

    Joined:
    Nov 29, 2016
    Messages:
    8
    Likes:
    0
    Super, thanks! As you found yourself, they indeed output 3.3v. Can I still use the relay you proposed (even if i need to add a transistor)?
    I'm gonna read up a little on the diode, but i understand your circuit.
    As for the open/closed, i already got this working with some magnetic sensors! Only downside is that i need rather long cables running over the ceiling of my garage.

    I can't wait for the stuff to arrive and start testing this out
     
  20. MikeMl

    MikeMl Well-Known Member Most Helpful Member

    Joined:
    Mar 17, 2009
    Messages:
    11,139
    Likes:
    566
    Location:
    AZ 86334
    Yes
     

Share This Page