flury_sti
Posts: 34
Joined: Thu May 08, 2014 12:51 am

DC Motors and Relay Switches - Forward and Reverse

Thu Mar 03, 2016 5:53 am

I have some large DC motors with a high amperage - too high for any of the motor control chips I have, like the L293D.

I have a few of these Sainsmart 4-channel 5V relay modules (http://www.sainsmart.com/4-channel-5v-r ... logic.html) which I was thinking of using. I've wired up the relay to the Pi and a separate power source with positive to the DC motor and negative to the relay and then to the DC motor. When the Pi switches on the relay, the DC motor spins as expected.

Is there a way to make the DC motor turn in reverse by wiring it in a certain way or using two of the relays?

User avatar
brekee12
Posts: 335
Joined: Wed Feb 03, 2016 3:36 pm
Location: HU

Re: DC Motors and Relay Switches - Forward and Reverse

Thu Mar 03, 2016 6:22 am

Yes and no. It is possible to build a forward reverse system; but four relay needed. You need to build a full bridge from the relays.
Brekee12
on a Raspberry B+ with whezzy, two Zero with Jessie Light

User avatar
rpdom
Posts: 15600
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: DC Motors and Relay Switches - Forward and Reverse

Thu Mar 03, 2016 6:55 am

Yes, quite simple. Connect the +V motor supply to the NC connections of two of the relays. Connect the motor 0V supply to the NO connections of those relays. Connect the motor between the C connections of the two relays.

With just one relay on the motor will run one way.
With just the other relay on the motor will run the other way.
With both relays on, or both relays off, the motor will not run.

User avatar
brekee12
Posts: 335
Joined: Wed Feb 03, 2016 3:36 pm
Location: HU

Re: DC Motors and Relay Switches - Forward and Reverse

Thu Mar 03, 2016 7:46 am

Congratulation! It is a good idea, relays has NO and NC connection, using both contact only two relay is enough.
Brekee12
on a Raspberry B+ with whezzy, two Zero with Jessie Light

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: DC Motors and Relay Switches - Forward and Reverse

Thu Mar 03, 2016 8:02 am

Watch those sparks fly when switching big inductive loads!

Make sure you add flyback clamping diodes across the relay contacts or they'll soon be destroyed.

flury_sti
Posts: 34
Joined: Thu May 08, 2014 12:51 am

Re: DC Motors and Relay Switches - Forward and Reverse

Sat Mar 05, 2016 4:10 am

Thanks for the suggestion. Are you able to provide some more detail on how this works?

Here is a link to what my 4 channel relay looks like. I don't have those specific NO and NC connections labeled.

Image

User avatar
brekee12
Posts: 335
Joined: Wed Feb 03, 2016 3:36 pm
Location: HU

Re: DC Motors and Relay Switches - Forward and Reverse

Sat Mar 05, 2016 4:48 am

I tried to google for that, but I could find just a short description on the datasheet. The drawing also not selfexplanatory.
A relay has: Normally Open, Normally Closed, Common(flying) contacts. From the figures it seems to be only two connectors NO and Common(empty) which is possible, but not usual and makes no sense with the thre contacts per relay.
Please check this with the producer or you can test it yourself:
- select a relay contacts, measure resistance center and closed side of the switch. If it is short, activate the relay and now it is open and other side is closed. If it behaves like this you have all three contacts center Common, first Normally Closed, second Normally Open.
- if you had two contacts only, Normally Open and Common, you would not measure any shortage between center and the two side. In this case the two side is open in inactive mode and short in active mode

No worry, you will be able to build what you want, question is only that how it can be based on the infos. In worst case the four relay are enough for that. If they have all three connection you can drive even two motor.

Please make sure this before you step further. And do not forget later the diodes mentioned!
Brekee12
on a Raspberry B+ with whezzy, two Zero with Jessie Light

User avatar
rpdom
Posts: 15600
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: DC Motors and Relay Switches - Forward and Reverse

Sat Mar 05, 2016 5:57 am

Does this diagram help?
relay.jpg
relay.jpg (28.47 KiB) Viewed 8719 times
I haven't included any diodes.

The C (Common) connector is the middle one of each block of three, the one that is show as "joined" to the middle one is NC (Normally Closed) and the one that isn't joined is NO (Normally Open).

User avatar
brekee12
Posts: 335
Joined: Wed Feb 03, 2016 3:36 pm
Location: HU

Re: DC Motors and Relay Switches - Forward and Reverse

Sat Mar 05, 2016 6:14 am

That's it! The diodes does not need to operate the circuit, it is needed to defend the relay contacts against sparks because of the strong inductive loads.
Brekee12
on a Raspberry B+ with whezzy, two Zero with Jessie Light

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: DC Motors and Relay Switches - Forward and Reverse

Sat Mar 05, 2016 7:59 am

rpdom was wise to omit them from that wiring diagram, as they clutter it & make it less clear, but they are easy to imagine:

You will need four diodes in total, two on each relay - one between NC & C, the other C & NO. The "arrow" symbol on all should point to the left ie cathodes to the left, anodes to the right.

Edited to add: the above does assume you stick to the convention of using red for +ve & black for -ve!

flury_sti
Posts: 34
Joined: Thu May 08, 2014 12:51 am

Re: DC Motors and Relay Switches - Forward and Reverse

Sun Mar 06, 2016 10:24 pm

Cool, thanks. This is making sense now. I've never used diodes before. Are there different sizes?

I just want to test this with a small DC motor - do I need diodes for that or is it more for just the larger DC motors?

Do I just put the diodes directly into the terminals with the wires?

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: DC Motors and Relay Switches - Forward and Reverse

Mon Mar 07, 2016 6:57 am

Use rectifier diodes eg 1N4001, not those flimsy signal diodes eg 1N4148. Yes, inserting them in the terminals is OK - wrap the motor wire around the diode leg otherwise you might find wire or leg coming loose if they are different diameters (not equally clamped when you do the terminal up).

Try it without the diodes & a small motor, just to see the sparks. Short term it will be OK, but long term the contacts would be eaten away, and with a bigger motor can get welded in place in no time at all.

flury_sti
Posts: 34
Joined: Thu May 08, 2014 12:51 am

Re: DC Motors and Relay Switches - Forward and Reverse

Fri Apr 29, 2016 5:35 am

Hi Again. I finally had a chance to get going on this project but I'm still unsure about the diodes. From what I read, you typically put the "silver band" towards the positive. So is the attached diagram the correct location and orientation for the diodes?
Relay with Diodes.jpg
Relay with Diodes.jpg (56.92 KiB) Viewed 8315 times
Adding the diodes doesn't seem to make sense to me in the circuit. If you follow the black wire to NO in the first relay does the diodes in between black and blue not complete the circuit without the relay triggering?

The motors I'm using have a stall current of 3 amps so I'm going to get some diodes that support up to 3A.

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: DC Motors and Relay Switches - Forward and Reverse

Fri Apr 29, 2016 6:57 am

Yes that's the correct orientation & position for all diodes. It's easier to see that is the case if you sketch it out as a circuit diagram - all are oriented such that no current can flow through them from the positive rail to the negative rail. They do their job when the relay contacts open & the motor coils generate that reverse voltage pulse, dumping it back into the power supply.

Diodes have a headline continuous current rating, but can deal with such short-lived currents well in excess of that continuous rating. But yes, the beefier the better as always.

drgeoff
Posts: 9925
Joined: Wed Jan 25, 2012 6:39 pm

Re: DC Motors and Relay Switches - Forward and Reverse

Fri Apr 29, 2016 10:19 am

Except for the diodes the basic wiring is exactly the same as with two light switches giving on-off control from either switch. At top and bottom of stairs in many houses.

flury_sti
Posts: 34
Joined: Thu May 08, 2014 12:51 am

Re: DC Motors and Relay Switches - Forward and Reverse

Sat Apr 30, 2016 5:10 am

Okay, I did a test with some smaller diodes and the DC motor based on the drawing and it works! I couldn't get the diodes into the terminals so I did them on a breadboard. Does this have the same effect?
DC-Motor.jpg
DC-Motor.jpg (51.45 KiB) Viewed 8164 times
Now, I did a test without the diodes and no sparks... That got me thinking. Are the sparks only an issue if I switch from forward to reverse at the same time? For the system I'm building, I'll never have to do that - the motor will be going one way for about 5 seconds then turn off. Then several minutes later, it will go the other direction for a few seconds and then stop. So based on that, do I even need diodes?

drgeoff
Posts: 9925
Joined: Wed Jan 25, 2012 6:39 pm

Re: DC Motors and Relay Switches - Forward and Reverse

Sat Apr 30, 2016 8:23 am

The sparks are between the brushes and commutator, inside the motor where they are not easily visible. They occur when the motor is running, even if you never change direction.

You would be unwise to omit the diodes.

User avatar
davidcoton
Posts: 4259
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: DC Motors and Relay Switches - Forward and Reverse

Sat Apr 30, 2016 9:52 am

Actually, the sparks you are concerned about are between the relay contacts as they open. The motor, when disconnected, becomes a generator which can produce a high voltage "back EMF" (electromotive force), which arcs across the relay contacts. The diodes suppress that, to protect the relay contacts. It shouldn't matter about the physical position of the diodes, but to keep radio interference to a minimum they should be as close as possible (short wires) to the motor.

The sparks occur when the relay opens (stopping the motor). If you were to reverse direction, you would still get sparks while the relay contacts change over.
Signature retired

User avatar
davidcoton
Posts: 4259
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: DC Motors and Relay Switches - Forward and Reverse

Sun May 01, 2016 11:07 am

drgeoff wrote:Except for the diodes the basic wiring is exactly the same as with two light switches giving on-off control from either switch. At top and bottom of stairs in many houses.
In the interests of accuracy -- this is NOT the circuit used for two-way switching of mains lights. The main reason is that one combination means that the light, while off, would still be live. That is undesirable at mains voltages.
Mains two-way circuits have one side of the load permanently connected to neutral, since there is no need to reverse the voltage. There are two versions of the circuit, which I won't detail here. Both of them can also be extended to three (or more) ways by using "intermediate" switches -- something that is also possible (but usually not helpful) with the H bridge circuit.
Signature retired

flury_sti
Posts: 34
Joined: Thu May 08, 2014 12:51 am

Re: DC Motors and Relay Switches - Forward and Reverse

Sun May 01, 2016 7:07 pm

Thanks for all of the responses! I hate to be a pain but I like to understand what I'm doing, not just copy the directions... After some research on diodes and motors (http://playwithrobots.com/dc-motor-driver-circuits/) I realize we have built an H-bridge circuit.

I rebuilt this on a breadboard without the relay to better understand it.
H-Bridge-Breadboard.jpg
H-Bridge-Breadboard.jpg (60.67 KiB) Viewed 7984 times
H-Bridge.jpg
H-Bridge.jpg (13.77 KiB) Viewed 7984 times
As mentioned in that link, with none of the switches connected (In my breadboard example, the wires), there is no motion. With S1/S4 connected and S2/S3 not connected the motor goes one direction. With S2/S3 connected and S1/S4 not connected, the motor goes in the other direction. Then connecting S1/S3 and not connecting S2/S4 while the motor is running essentially applies the brake and stops the motor.

davidcoton, you mentioned the diodes should be close to the motor... What if that isn't possible? I'm planning on soldering this H-Bridge onto a board and then I will run about 3 foot wires from it to the motor. Is that going to be okay?

I still don't fully understand how the diodes prevent the sparks. Let's say S1/S4 are closed and S2/S3 are open - the motor would be doing in one direction. When the relay switches and S3 closes and S4 opens, the motor would stop but then generate the high voltage back EMF. Which diodes (D1, D2, D3, or D4?) protects the switch and what switch needs the protecting? Which direction is that back EMF going in this example?

User avatar
davidcoton
Posts: 4259
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: DC Motors and Relay Switches - Forward and Reverse

Sun May 01, 2016 9:19 pm

flury_sti wrote: davidcoton, you mentioned the diodes should be close to the motor... What if that isn't possible? I'm planning on soldering this H-Bridge onto a board and then I will run about 3 foot wires from it to the motor. Is that going to be okay?
It will work. The currents associated with the back EMF will run through the 3' wires. This MAY cause radio interference with adjacent equipment. Or there MAY be no issues.
flury_sti wrote: I still don't fully understand how the diodes prevent the sparks. Let's say S1/S4 are closed and S2/S3 are open - the motor would be doing in one direction. When the relay switches and S3 closes and S4 opens, the motor would stop but then generate the high voltage back EMF. Which diodes (D1, D2, D3, or D4?) protects the switch and what switch needs the protecting? Which direction is that back EMF going in this example?
S4 opens. EMF appears, from motor acting as generator. Diode D1 protects S4. THEN S3 closes. No more problem.

In an H bridge, the diode protection is needed for the short period between one contact opening and the other closing. Note that (for example) S3 does not and MUST NOT close before S4 opens -- if it did, the supply would be short circuited. This is one of the problems in designing a solid state H bridge (eg using MOSFETs as switches) controlled by GPIO pins. The switching timings must be correct, and designed to be failsafe.

Suggestion: your diagram would be easier to work with if the diode numbering corresponded to the switch numbering -- D1 across S1, and so on. :ugeek: 8-)
Signature retired

flury_sti
Posts: 34
Joined: Thu May 08, 2014 12:51 am

Re: DC Motors and Relay Switches - Forward and Reverse

Sun May 01, 2016 10:11 pm

Great explanation - that makes perfect sense now! Thanks so much! Oh, and good call on the diagram - I'll fix that ;)

Massimo48
Posts: 1
Joined: Wed Oct 26, 2016 6:00 pm

Re: DC Motors and Relay Switches - Forward and Reverse

Wed Oct 26, 2016 6:03 pm

I'm really curious on how this went for you, any updates on your project if you don't mind me asking?

I'm trying to power window regulators on my car using this method & I wanted to know if you ran into any problems other than what you stated.

flury_sti
Posts: 34
Joined: Thu May 08, 2014 12:51 am

Re: DC Motors and Relay Switches - Forward and Reverse

Sat Oct 29, 2016 1:00 am

Hi Massimo48. I didn't end up using the motors in the project because of some mechanical issues with something else but the prototype I built based on this post worked great!

Return to “Advanced users”