Transistor Circuit to Operate Relay from Arduino Uno

Advert

Transistor Circuit to Operate Relay from Arduino Uno

Home Forums Electronics in the Workshop Transistor Circuit to Operate Relay from Arduino Uno

Viewing 25 posts - 1 through 25 (of 40 total)
  • Author
    Posts
  • #779499
    James Alford
    Participant
      @jamesalford67616

      Having successfully got my code working and my LEDs flashing as required, I tested the circuit that I built to operate solenoids with the Uno. The idea is that each second, each minute, each hour and so forth, solenoids will operate to advance the time on a clock.

      I built a circuit using BC547b transistors to do this, on transistor circuit per solenoid. I also incorporated a LED so that I know when the solenoid should trigger.

      Testing this circuit, the LEDs all flash as expected, but the solenoids do not. Testing the output voltage on the circuit that flashes each second with a meter, I get a maximum of about 4.5 volts which drops with each flash and then goes back up to about 4.5 volts.

      I have clearly built the circuit wrongly, but I am not sure what is wrong. I was wondering whether the LED, which is across the load, is sapping the voltage or whether I have wired up the transistor incorrectly.

      Again, I should be grateful for advice. This is my circuit.

      20250124_080322

       

       

       

       

      Advert
      #779506
      John Haine
      Participant
        @johnhaine32865

        Trying to drive a relay or solenoid from a 9v battery, if it’s the usual pp3 type, is a hiding to nothing. 250mA needs a proper power supply.

        The maximum collector current rating of the bc547 is 100mA and base current 5mA.  If the base resistor is really 220R then you will be driving 25mA into the base.  I wouldn’t rely on it to switch 250mA. I would suggest that it would be much better to use a logic-level mosfet to switch the relay, lots of guidance on the Arduino forum.  Basically they take zero current from the logic level output.

        Please could you take a few minutes to learn to draw schematics correctly? There is a standard way to do this which makes it easy to see what you are trying to do, and comment. There’s also a free CAD tool, Fritzing, which allows you to draw a schematic and convert between that,  a breadboard, and pcb views.

        #779509
        Joseph Noci 1
        Participant
          @josephnoci1

          Relay should work , but the LED, not so much… The LED in that cct is the wrong way around.

          Transistor is wired OK – it is an NPN, so diagram is correct.

          Also, the resistor from the I/O pin ( 13) to the base is very low in ohm – The poor arduino has to provide around 10mA to drive the base( if the arduino is a 3.3v job, else 20mA if its 5v)  – 2k2 ohm is quite adequate.

          So, I am dismayed that the led flashes in this circuit – it cannot when reverse biased…

          Likewise dismayed that the relay does not activate, it should..unless the relay needs a higher voltage. What voltage does the relay coil require? Does it activate when you apply your 9v across the coil? If so..

          Correct the LED connection direction

          Remove the resistor from the arduino pin 13 and momentarily connect it to the arduino 3.3v or 5v supply.

          The relay should activate. If it does not, did the LED come on?

          If not, the voltage on the collector should be 9v with the base resistor unconnected. When connected to 3.3v/5v the collector voltage should be close to 0v. if not, transistor is dud..

          #779531
          Bazyle
          Participant
            @bazyle

            Find an IC chip called an ULN2003. There are little boards with them already on, also you can get boards with 2 or 4 relays on and the drivers.
            https://uk.rs-online.com/web/p/power-motor-robotics-development-tools/2651121?cm_mmc=UK-PLA-DS3A-_-google-_-CSS_UK_EN_PMAX_Catch+All-_–_-2651121&matchtype=&&gad_source=1&gclid=CjwKCAiAkc28BhB0EiwAM001TRxc0QjsCdmxCVzP822uwGgbNYJ2OKdtxrrja8A9NyJLbW93gup43xoCt-EQAvD_BwE&gclsrc=aw.ds

            It is incredibly hard to understand a non-standard circuit drawing. This is so much easier (though the transistor is inadequate.)
            https://www.electronics-tutorials.ws/blog/relay-switch-circuit.html

             

            #779544
            SillyOldDuffer
            Moderator
              @sillyoldduffer

              I re-drew the circuit to make sure it’s OK, and got this:

              relayDriver

              This is correct except:

              • make sure the LED is the right way round.  If it flashes, it probably is!
              • check the transistor connections.  James shows EBC, I think a BC545 is CBE

              Transistor is a bit small.  Max rating of the BC545 is 100mA.   Wasn’t able to find a blue miniature relay of the Arduino sort and measure it , but found a web source saying the 12V version has a 54ohm coil, which is 160mA at 9V.   Probably OK if the relay doesn’t stay on for long.

              Test the circuit without the relay and make sure the LED flashes correctly.   Then connect the relay.   If the relay doesn’t stir, it may be there isn’t enough energy in the time it takes to flash the LED to power the magnet.   Try a longer flash!  A few things may combine to reduce the energy put into the relay’s electromagnet:

              • Running a 12V relay at 9V is probably OK, but marginal
              • A 9V battery may not be able to provide enough current. A PP9 has more beef than a PP3.  Also, the battery technology matters – a cheap Zinc Carbon PP3 produces much less current than a pricey Alkaline PP9.     If necessary, put two or more batteries in parallel.
              • Pulse length too short    (I’d start with this one!)

              Never forget Sod’s Law: if it can go wrong it will, and in the worst possible way.   The relay could be faulty…

              Dave

               

              #779578
              John Haine
              Participant
                @johnhaine32865
                #779609
                duncan webster 1
                Participant
                  @duncanwebster1

                  If you can find some 12v,you can get little boards with 4 relays each with it’s own drive circuitry and freewheel diodes designed to be driven off Arduino or similar

                  #779634
                  Robert Atkinson 2
                  Participant
                    @robertatkinson2

                    James has the transistor pinout incorrect.

                    Viewed as drawn (looking at leads with flat uppermost) the left lead is Collector and right is Emitter.
                    SOD has the pinout correct but his schematic corrects James’ sketch.

                    Two other issues are that the BC547’s collector current rating is only 100mA so well below the intended load of 250mA plus the LED.
                    Second the sketch does not show any connection between the 0V of the transistor circuit and the 0V of the Arduino.
                    Looks like both design issues and an incorrect sketch.

                    https://www.farnell.com/datasheets/410427.pdf

                    Robert.

                    #779637
                    Stuart Smith 5
                    Participant
                      @stuartsmith5

                      You could buy a ready made relay board. This is one I have used from CPC.

                      https://cpc.farnell.com/whadda/wpm400/4-channel-relay-module-for-arduino/dp/SC17702?st=relay%20board

                      It also shows the circuit diagram on the website.

                      or these 2 from Hobby Components:

                      https://hobbycomponents.com/relays/75-4-channel-5v-relay-module

                      https://hobbycomponents.com/our-brand-exclusives/1090-mlink-4-channel-i2c-parallel-relay-module

                      They don’t charge much for delivery and usually arrive next day.

                      Stuart

                      #779640
                      Bazyle
                      Participant
                        @bazyle

                        Currently teh 2N2222 is considered the ‘do everything’ transistor.

                        #779648
                        duncan webster 1
                        Participant
                          @duncanwebster1

                          Having read on the other thread that the object is to drive an electromechanical clock I’d echo someone else’s suggestion to ditch the relays and use logic level fets to drive the clock coils direct.

                          Just to be pedantic (who me) a relay is not a solenoid. Solenoid has a hollow coil and the iron bit is pulled down the hole.

                          #779658
                          John Haine
                          Participant
                            @johnhaine32865
                            On Bazyle Said:

                            Currently teh 2N2222 is considered the ‘do everything’ transistor.

                            Since 1962…

                             

                            #779669
                            Michael Gilligan
                            Participant
                              @michaelgilligan61133

                              Given that the opening post included Solenoids … This is worth a look:

                              https://youtu.be/nwVRMU9grSI?feature=shared

                              MichaelG.

                              .

                              Edit: __ The pace is a bit laboured, but none the worse for that … his third circuit is the good one.

                              .

                              #779724
                              James Alford
                              Participant
                                @jamesalford67616

                                Thank you for all of the responses: I shall have a good read of them all and have another go.

                                Just to clarify a few points or comments:

                                • the 9v battery is only for the testing stage. The aim is to use a more substantial 12v power supply
                                • the relay works well on the battery if connected directly
                                • the type of relay I have been testing with is the like the relay in the first picture below
                                • the type of solenoid I plan to use is in the second picture below

                                Picture1Picture2

                                #779729
                                John Haine
                                Participant
                                  @johnhaine32865

                                  The problem with testing with a 9V battery is that it will likely run down quickly and start to cause other problems, possibly resetting the Arduino for example, which can be difficult to find unless you have a ‘scope.  This happens because the supply voltage dips when the current switches on, and the regulator on the Arduino board can’t handle it.

                                  Much better to use a proper PSU from the get-go.  It’s amazing how many people ask about problems using motors, relays etc on Arduino support who are using such a battery.

                                  That first picture is what Duncan calls a solenoid.  The second picture might be an electromagnet, but neither is a relay.  See https://en.wikipedia.org/wiki/Relay#:~:text=A%20relay%20allows%20circuits%20to,of%20controlling%20industrial%20electronic%20systems. for lots of pictures of different types of relays.

                                  #779744
                                  Grizzly bear
                                  Participant
                                    @grizzlybear

                                    Hi,

                                    If you are ordering components, I can recommend a few “N type” logic FETs.

                                    Good luck………..

                                     

                                    #779746
                                    Michael Gilligan
                                    Participant
                                      @michaelgilligan61133

                                      DataSheet for the MOSFET mentioned in the video:

                                      https://protostack.com.au/download/FQP30N06L.pdf

                                       

                                      Possibly overkill … but they are cheap enough.

                                      MichaelG.

                                      #779937
                                      Michael Gilligan
                                      Participant
                                        @michaelgilligan61133

                                        Grateful if wiser men than me could comment on these two links:

                                        https://www.utmel.com/compare/FQP30N06L–6383549-vs-FQP30N06–6383422

                                        https://electronics.stackexchange.com/questions/331381/nearly-identical-mosfets-yet-only-1-works-fqp30n06l-vs-rfp30n06le

                                        MichaelG.

                                        .

                                        Edit: __ Having just purchased Qty.5 via ebay at what seemed a reasonable price … I then spotted this:

                                        .

                                        IMG_0549

                                        #779943
                                        Robert Atkinson 2
                                        Participant
                                          @robertatkinson2

                                          I can’t see any image. The FQP30N06L is a logic level device. The FQP30N06 isn’t.
                                          The problem dscussed on stackexchange sounds like bogus devices. I don’t buy any cheap semiconductors on ebay etc.

                                          Robert.

                                          #779971
                                          Michael Gilligan
                                          Participant
                                            @michaelgilligan61133

                                            Thanks, Robert … if I need more, I will probably buy from R.S.

                                            MichaelG.

                                            .

                                            In theory at least, I bought the correct version:

                                            IMG_0550

                                            #779973
                                            peter1972
                                            Participant
                                              @peter1972

                                              The photo of a solenoid looks like it is probably one rated at 5V and draws 1.1A at 5V.

                                              The photo of an electromagnet looks like it is probably one rated at 12V and draws 0.25A at 12V.

                                              If you use an electromagnet you will need to provide an armature.

                                              An electromagnet or solenoid is going to be very noisy. Do you really want one snapping away every second?

                                              Consider using a small stepper motor, at least for the seconds hands. They are available from eBay for under £5 including a ULN2003 driver integrated circuit on a small PCB. They are not totally silent, depending on how they are mounted, but will be very much quieter than electromagnet or solenoid.

                                               

                                              #780042
                                              James Alford
                                              Participant
                                                @jamesalford67616

                                                I have had a bit more of a look at the linked products and quite like this one that John suggested Breakout Board If I understand it correctly, I just need to feed a wire from a pin of the Aruduino into the board, along with the power, and connect the load to the output connector.

                                                Peter: I had initially planned to use the push-pull type relay like the one in my post, but changed my mind because, as you say, it is noisy. It reminded me of my time in telephone exchanges.

                                                I started looking at the pull-type electromagnet in the other picture because of the noise. My rough design arranges an armature to operate the hands in such a way that it has a small air gap to prevent noise. However, I am not sure whether the magnet has the strength to cope with this. I am also apprehensive about the armature becoming magnetised over time if I use the wrong type of metal for the armature.

                                                I can see the advantages of stepper motors and shall do a bit of reading on them as I know nothing about them or operating them with the Uno.

                                                James.

                                                #780064
                                                John Haine
                                                Participant
                                                  @johnhaine32865
                                                  On James Alford Said:

                                                  I have had a bit more of a look at the linked products and quite like this one that John suggested Breakout Board If I understand it correctly, I just need to feed a wire from a pin of the Aruduino into the board, along with the power, and connect the load to the output connector.

                                                  Peter: I had initially planned to use the push-pull type relay like the one in my post, but changed my mind because, as you say, it is noisy. It reminded me of my time in telephone exchanges.

                                                  I started looking at the pull-type electromagnet in the other picture because of the noise. My rough design arranges an armature to operate the hands in such a way that it has a small air gap to prevent noise. However, I am not sure whether the magnet has the strength to cope with this. I am also apprehensive about the armature becoming magnetised over time if I use the wrong type of metal for the armature.

                                                  I can see the advantages of stepper motors and shall do a bit of reading on them as I know nothing about them or operating them with the Uno.

                                                  James.

                                                  Stepper motors have a lot to commend them.  In my “Arduinome” clock I use 2 – one to lift/lower the gravity arm and the other to drive the dial, which is akin to what you are trying to do.  I started with a standard Synchronome dial which uses an electromagnet that is impulsed every 30s – I demo’d this to the domestic authority and it was instantly vetoed!  So I modified the movement so it uses a NEMA08 size stepper with a small pinion on its shaft engaging with the pinion on the minute hand.  The stepper is driven using a DRV8834 IC on a breakout board from Pololu, using a 9V supply (though it will operate happily on 5V).  The stepper does 400 steps per rev and steps every 9s so 3600 steps.  The Arduino programming for this is trivial, you would not need all the complexity of the stepper libraries.

                                                  Another approach is to butcher a quartz clock movement by cutting the PCB tracks where the connections to its stepper motor are made and soldering on some thin twisted pair.  Drive this from an Arduino using 2 pins and a single 220R resistor for 5V.  Drive with a 5V 20ms pulse every second on alternate pins.  I’ve done this on a clock in my office and currently working on another for a joint project.

                                                  #780076
                                                  Robert Atkinson 2
                                                  Participant
                                                    @robertatkinson2

                                                    Hi James,

                                                    The board you linked to should work OK but keep the wiring between it and the Ardunio short or it may oscillate. Ideally a circuit like this should have a small resistance in series with the gate and physically close to the MOSFET. A value of 100 Ohms is typical, see circuit:

                                                    Mosfet1

                                                    The 10k resistor ensures the MOSFET is off with nothing connected and gives a bit of protection from electrostatic discharge.
                                                    Putting a soft stop or air gap on a electromagnet to reduce noise is a valid approach. A stop in the energised position does not reduce the inital closing force. Putting a soft stop at the de-energised position actually increases the inital force as it reduces the gap. Both reduce the total travel but that can be accomodated in the mechanical design.
                                                    Stepper motors can be noisy too. Driving them from a microcontroller can be as simple as 4 MOSFETs or a integrated circuit designed for the task. The typical 1.8 degrees / 200 steps per revolution can require some thoughtover gear ratios and pulse rates for a clock.

                                                    Robert.

                                                    #780099
                                                    John Haine
                                                    Participant
                                                      @johnhaine32865

                                                      On the topic of steppers in clocks.  One half-step every 9 seconds is inaudible.  The gravity arm drive runs for about 250ms every minute but the actual stepper noise is hardly noticeable.  For the very low speeds needed in clocks  you can also use improved stepper drivers such as the Trinamic types which have modes which are effectively silent, and they are as easy to use as standard drives. IMHO these days using an H bridge driven straight from the micro is a waste of effort as proper drivers such as the DRV8834 are so cheap and do everything for you.

                                                      Regarding gear ratios the usual 200 steps per rev at first sight is a problem for clocks which count in 60s.  I have made a clock dial where the seconds hand is driven directly by a NEMA08 200 steps per rev. motor.  How do you get  1 second increments from that?  Well for example if you use 4x microstepping to get 800 steps per rev.  800/60=13.3333….  Oops!  But if you do 13 / 13 /14 steps and repeat, that’s 40 steps in 3 seconds and 20 x 40 = 800.  It does mean that the hand is only “accurate” once every 3 seconds but the maximum error is imperceptible.  The stepper makes a little more noise but still very quiet.  Programming this is slightly tricky but really not difficult.  Of course the other hands are mechanically geared down from the seconds hand so there is no problem with them.

                                                    Viewing 25 posts - 1 through 25 (of 40 total)
                                                    • Please log in to reply to this topic. Registering is free and easy using the links on the menu at the top of this page.

                                                    Advert

                                                    Latest Replies

                                                    Viewing 25 topics - 1 through 25 (of 25 total)
                                                    Viewing 25 topics - 1 through 25 (of 25 total)

                                                    View full reply list.

                                                    Advert

                                                    Newsletter Sign-up