How to control a 9v DC motor to run in both directions with arduino

Hi
i want to know how can'i control a 9v DC motor to run in both directions with arduino

in the picture i was able to run it in one direction

thank you

You will need two relays instead of one, setup like in the attached pix.

reversemotor.jpg

@Abdelyo: just one copy of the question was all that was needed.
I deleted the other two.

@zoomkat Thanks you So much !! it's working . even if i really don't know how you did it
@AWOL ok sorry

Hi Abdelyo, and welcome.

The diagram by zoomkat was made for another application but is has all information you need.
The part with the diodes and the limit switches probably doesn't apply to your application.

Take a good look at the diagram, and see that he has put the relay contacts "upside down" with respect to yours.
That way there's always a connection between the motor and GND if a relay isn't active.
So in case both are inactive, both wires are connected to GND.
The relay that gets activated will decide the direction the motor will run.
If by any chance both will be activated, there will be no difference in potential, just like the both inactive state.
So the motor will not run then (in fact it will stop faster).

@MAS3 Thank you :slight_smile:

I believe this would be a job for an H-bridge, would it not?

Why would that be the case ?

I did forget to warn Abdelyo.
You shouldn't use relays connected directly to the Arduino output pin, but with help of a transistor because most relays will need a too large current to switch on.
Then you should use a diode to get rid of the back EMF when releasing the relay coil, to protect the transistor and the Arduino as well.

Optically isolated relay modules like below keep the relay coils isolated from the arduino itself.

185477cd6af315fa2d1fd114661e478a84f1db7c.jpg

The diodes with the limit switches are just a convenience if the motor and limit switches are distant from the controller. Otherwise the switches go in series with the supply to the normally open contacts and the diodes are not required.

rytcd:
I believe this would be a job for an H-bridge, would it not?

That is what the relays do. In many cases, the relays are more practical; you do not have to be concerned about the specification of transistors - or preferably, FETs - to minimise voltage drop, or prevent simultaneous operation of both upper and lower device.

to minimise voltage drop, or prevent simultaneous operation of both upper and lower device.

This sounds like a reference to "shoot-through" prevention in an H-Bridge, which I am pretty sure the OP has no knowledge of or experience with. The intention was good though...

@OP,
If you want to learn about H-Bridges and DIY H-Bridges, see Reply#6 of THIS post.

The comment about "ignore the PWM labels etc. would not apply to you because you are not building a stepper driver. Thus the PWM labels WOULD be applicable to YOUR application of a DC motor. (hope that isn't too confusing)

raschemmel:
This sounds like a reference to "shoot-through" prevention in an H-Bridge, which I am pretty sure the OP has no knowledge of or experience with. The intention was good though...

Well, I was fishing for the correct term, didn't readily come to mind.

I'm not sure that "shoot-through" is the best or universal term either, but if you say so, I'll take your word for it. :grin:

Which intention?

If that's what International Rectifier calls it then , then who am I to question it ?

Shoot-Through Protection
The Shoot-Through Protection of each leg takes advantage of the switching time difference between the Low Side
MOSFET and the High Side Switch. Due to the charge pump circuitry, the HS switch has slow turn-on / turn-off
times compared to the direct drive of the LS MOSFET.
Therefore, when IN 1 (2) is set high, the complemented signal immediately turns-off the LS MOSFET while the
charge pump circuitry hasn’t switched ON the HS part yet. On the other hand, when IN 1 (2) is set low, the HS
switch turns-off slowly and the LS MOSFET isn’t turned-on again until its Vds voltage has gone down to two volts
(back to its quiescent ON state).
By this way, a self-adaptive deadtime circuitry is achieved without any temporization.

SHOOT THROUGH

Which intention?

The intention to explain why relays are simpler to use.
(ie: "idiot proof")
(below)

In many cases, the relays are more practical; you do not have to be concerned about the specification of transistors - or preferably, FETs - to minimise voltage drop, or prevent simultaneous operation of both upper and lower device.