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 15 posts - 26 through 40 (of 40 total)
  • Author
    Posts
  • #780110
    Robert Atkinson 2
    Participant
      @robertatkinson2

      The noise from a stepper depends on the motor and it’s mounting more than the drive method. For a simple low torque application like a clock there is n need for a H bridge or a specialist driver. Just a bipolar motor and four low side MOSFETs. This gives half steps with simple code.

      Robert.

      Advert
      #780133
      John Haine
      Participant
        @johnhaine32865
        On Robert Atkinson 2 Said:

        The noise from a stepper depends on the motor and it’s mounting more than the drive method. For a simple low torque application like a clock there is n need for a H bridge or a specialist driver. Just a bipolar motor and four low side MOSFETs. This gives half steps with simple code.

        Robert.

        There is if you need to play games with the ratio to avoid mechanical gearing.  On my ‘Nome-based clock the stepper operating the gravity arm needed microstepping to start cleanly and to get low noise.  I would suggest that actually using a “specialist” driver is actually much easier for a beginner than trying to use discretes.  Just set the drive current and microstepping ratio once, then apply power and step pulses.

        #780154
        duncan webster 1
        Participant
          @duncanwebster1

          For driving unipolar stepper motors I’ve used ULN2003 chip. 7 Darlington transistors with built in flyback diodes on one 16 pin chip. Much easier than using separate FET or transistor. Handles 500mA which is plenty for driving a slave clock

          For bipolar (4 wire) motors I’ve used dual H bridge chip. When my PC problem is fixed I’ll be able to look up the number.

          I’m sure there are Arduino libraries for doing t, but I wrote my own using bit twiddling on PortB.

          The 48 step motor I used in my slave clock came with a 15t cog, which looked a bit difficult to get off, so I meshed it with a 75t gear on the minute shaft and advance once per 15 seconds. Then I got ‘clever’ and advanced it 4 steps every minute, why, just because I could.

          As far as using electromagnets and ratchets, that’s what Gents and Synchronome slaves do, the noise isn’t too bad, quite a feature in fact

          #780319
          James Alford
          Participant
            @jamesalford67616

            I have not had a chance to read and assimilate everyone’s replies yet, but I shall.  Thank you.

            John: IIam intrigued by your reference to a gravity arm. Do you have any pictures or drawings of how your clock works as I would be interested in learning more .

            James

            #780335
            Bazyle
            Participant
              @bazyle

              Stepper drive : One of these arrived yesterday https://www.ebay.co.uk/itm/396116799629

              Overkill perhaps for a clock drive but simple screw terminals and easy mount package which I intend for a beginner training exercise. Only minor flaw is that it does have ventilation slots that will need anti swarf netting.

              #780721
              James Alford
              Participant
                @jamesalford67616
                On Stuart Smith 5 Said:

                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

                Can anyone help regarding my understanding of output pins and their states, please? I think that I am being either obtuse or have misunderstood a fundamental aspect of output pins on Unos.

                My understanding is that if an output pin is set to LOW it is effectively off and delivering little or no current. If it is set to HIGH, it is on and current can flow. Looking at the relay module boards in these links, and others that I have found, they all operate when the pin to which they are connected is set to LOW. Presumably, this means that to keep the relay off, the pin needs to be set to HIGH.

                If my understanding is correct, would this not mean that the Uno is drawing more power the whole time that the relay is off? If the relay needs to operate only once a day, this would seem to be wasteful.

                My other thought was that if the conditions that set the code loop running e.g. the time is midnight, are not met, the relevant output pin is set to neither LOW nor HIGH and the relay remains off. Somehow, though, this seems wrong.

                On the other hand, I could have simply completely misunderstood the basic concept and be on the wrong track.

                James.

                #780725
                Robert Atkinson 2
                Participant
                  @robertatkinson2
                  On Bazyle Said:

                  Stepper drive : One of these arrived yesterday https://www.ebay.co.uk/itm/396116799629

                  Overkill perhaps for a clock drive but simple screw terminals and easy mount package which I intend for a beginner training exercise. Only minor flaw is that it does have ventilation slots that will need anti swarf netting.

                  ” anti swarf netting”? Really?

                  Thsi highlights the widespread mis-understanding of how these and similar components are supposed to be used. They must be enclosed in a suitable housing and depending on the type and application suitable overcurrent protection, safety controls and EMC filtering.
                  This particulat unit is lowvoltage which mitigates things a little depending on what power source is used. but as a minimum even home built equipment is required to comply with the relevant standards. That is at least the EMC directive in this case.
                  No I don’t expect homebuilders to get their projects tested and don’t want to stop people building and experimenting.
                  BUT we should as a minium observe good practice:
                  Using suitable enclosures and connectors ideally metallic
                  Over current protection
                  Screened cables and EMC filter were required.

                  Ideally the components should come with suitable instructions and guidance but the majority come with nothing leaving many users to rely on online guides and videos These are often of dubious quality. The ability to produce a slick or engaging video seems to be inversly proprotional to the quality of the information.

                  Robert.

                  #780727
                  Robert Atkinson 2
                  Participant
                    @robertatkinson2
                    On James Alford Said:
                    On Stuart Smith 5 Said:

                    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

                    Can anyone help regarding my understanding of output pins and their states, please? I think that I am being either obtuse or have misunderstood a fundamental aspect of output pins on Unos.

                    My understanding is that if an output pin is set to LOW it is effectively off and delivering little or no current. If it is set to HIGH, it is on and current can flow. Looking at the relay module boards in these links, and others that I have found, they all operate when the pin to which they are connected is set to LOW. Presumably, this means that to keep the relay off, the pin needs to be set to HIGH.

                    If my understanding is correct, would this not mean that the Uno is drawing more power the whole time that the relay is off? If the relay needs to operate only once a day, this would seem to be wasteful.

                    My other thought was that if the conditions that set the code loop running e.g. the time is midnight, are not met, the relevant output pin is set to neither LOW nor HIGH and the relay remains off. Somehow, though, this seems wrong.

                    On the other hand, I could have simply completely misunderstood the basic concept and be on the wrong track.

                    James.

                    Hi James,

                    Your basic understanding of the processor outputs is correct. Subtle difference is when LOW / 0V current can still flow from an external circuit to ground. When HIGH / 5V (3.3V on some) the pin supplies current to the external circuit.
                    So there is no simple rule that says high or low consumes less power.

                    A driver with simple transistors will normally have processor output high = transistor ON. The common (typically emitter or source) of the transistors is connected to 0V / common so ON is 0V . You connect the load (coil) between the suppy positive voltage and the driver output. When the output is ON current flows to ground and load is active. This is called low side switching.

                    For various reasons this is the simplest most efficent circuit. IT is the same as having a mechanical switch in the negative of a circuit.

                    The driver boards that have the output ON for a LOW input typically have more complex circuits such as optical isolation or a integrated circuit driver.
                    Foe an optoisolator the output is ON when the LED at the input has current passing through it. The positive (anode) of the LED is connected to the supply (5V) with a series resistor and the negative (cathode) to the processor output. If the processor pin is LOW (0V) current flows  and the output is ON. With the processor pin HIGH (5V) no current flows (both sides of LED are at the same voltage) and output is OFF.

                    Hope this helps.

                    Robert.

                     

                    #780729
                    John Haine
                    Participant
                      @johnhaine32865

                      James, if you use pinmode(X, OUTPUT) it becomes an output.  If you then set it HIGH by using digitalWrite(X, HIGH) then internally it is connected to the positive supply rail and can source current.  If LOW then it’s connected to the negative rail and can sink current.  If you use pinmode(X, input) then it becomes an input and is very high impedance unless you use pinmode(X, input_pullup) which connects it to the positive rail through a resistor of around 20kohms. You can happily change from input to output and back in a sketch which can be useful.

                      #780743
                      Bazyle
                      Participant
                        @bazyle

                        Here is a neat reference https://www.circuito.io/blog/arduino-uno-pinout/ which may help. The details about output pins is part way down the page. It is always worth checking resources like this even if ‘you think you know’ because different varieties (Uno, Pico, Pi etc) can have a mixture of capabilities on different pins ie some outputs can sink 20 mA and the pin next to it is only allowed 1mA. Ditto for high level, and nowadays also check carefully about whether it is only 3v logic and melts if you apply 5v.

                        #780769
                        SillyOldDuffer
                        Moderator
                          @sillyoldduffer

                          When a microcontroller pin is configured as an output, it fairly obviously provides current when set HIGH.   How much depends on the chip, up to 40mA on an Arduino Nano, but not all pins at the same time!

                          Less obviously, when an output pin is set LOW, the pin sinks current, also up to 40mA on a Nano.

                          In this example circuit, the output pin is held HIGH by a 1k resistor connected to the 5V rail.  The voltmeter reads 5V when the pin is set HIGH.  When the output pin is set LOW, it pulls the resistor down to ground, and the voltmeter reads zero volts.

                          hilo

                          Useful because binary logic can meet switching requirements either way round by inverting the meaning of HIGH and LOW.  Both handy and complicated!  But as an example, James is using an NPN transistor, which works with the logic in my circuit.  If his junk box was full of PNP transistors, which are upside-down compared with NPN,  he could invert the logic in the Arduino to match PNP electronics.

                          Why did I specify a 1k resistor in the example?  At 5V 1000 ohms limits the current sunk by the output pin to 5mA, well within the 40mA maximum, and enough to drive an NPN/PNP transistor fully ON.  It’s “about right”, not carefully calculated.  As FETs are switched by volts, not amps, the resistor could have a much higher value.

                          A good reason for experimenting with basic Arduinos is they use a slow but robust chip that’s more resilient to mistakes.   Faster microcontrollers with more memory and features tend to be delicate.  Get the electronics wrong, and pop!   Many other microcontrollers can’t source or sink much current.  For them, as Bazyle recommends, check the data-sheet and read the small print.

                          Dave

                           

                           

                           

                          #780935
                          James Alford
                          Participant
                            @jamesalford67616

                            Thank you for the clarification of the power used by the Uno in different states of the output pins. This has clarified my understanding a lot.

                            I have decided to buy a couple of the relay boards that have been suggested and to stick with the electromagnets for now. I have only one spare digital pin, so to use a stepper motor, I would have to start again, pretty much, with my code. I am not keen to do that just at the moment.

                            I do have a low speed, high torque electric motor, though, that I might press into use to lift a small weight to drive a seconds hand, rather than pulsing a coil every second. I just need to think out how to make it work.

                            Thank you all for the advice.

                            James.

                            #780942
                            John Haine
                            Participant
                              @johnhaine32865

                              James, just to be clear, if you used a modern bipolar stepper such as a NEMA08 with a modern driver such as the DRV8834, you only need one pin to drive it, the direction and programming pins can all be tied to appropriate logic levels.

                              #781006
                              James Alford
                              Participant
                                @jamesalford67616
                                On John Haine Said:

                                James, just to be clear, if you used a modern bipolar stepper such as a NEMA08 with a modern driver such as the DRV8834, you only need one pin to drive it, the direction and programming pins can all be tied to appropriate logic levels.

                                Thank you, John. I had not realised that.

                                #781011
                                John Haine
                                Participant
                                  @johnhaine32865

                                  Before someone leaps in, I mean of course a stepper in the NEMA08 frame size, just because a clock is unlikely to need any more torque than available in that size.  Motors that size are readily available.

                                  https://www.omc-stepperonline.com/nema-8-bipolar-1-8deg-1-4ncm-1-98oz-in-0-2a-20x20x28mm-4-wires-8hs11-0204s

                                Viewing 15 posts - 26 through 40 (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