2

So, I am new with arduino and am to build a robot using motors, for that I have bought l298n H bridge motor driver. I have watched various site and videos ,to make sure not to make a mistake but, in every video and sites

I have found their connecting the motor direction controller to

Diagram

IN1 -> Arduino Pin 8 (digital) and IN2 -> Arduino Pin 7 (digital)

Till then it was fine ... Now the fishy thing for me is

IN3 -> Arduino Pin 5 (PWM) and IN4 -> Arduino Pin 4 (Digital)

Why connect to a Digital and a PWM?

For E1 and E2 I am sure that the wires should be connected to the PWM (~) pins for arduino, to control speed of the motor..

But, Should not I be able to connect IN3 and IN4 both to rest of the digital pins 12, 13 or 2,4 Just Like IN1 and IN2 is connected to 7 and 8.

But the IN3 and IN4 is connected to a PWM and a Digital pin.

Conclusion,

So can I use all the unused non PWM digital pins to connect the motor direction control?

Thanks for your precious time..!

7
  • PWM is a digital output ... it is pulsed ... the pulse timing is variable
    – jsotola
    Commented Sep 22, 2020 at 17:53
  • I know that but , can we use a non PWM pin for it? Commented Sep 22, 2020 at 17:58
  • 1
    Because , we don't need PWM to just change the polarity of the motor, so , as per my logic, we should be able to use non PWM pins for motor direction changing purpose, So , am I right or wrong? Commented Sep 22, 2020 at 18:00
  • I think that you are missing important information ... the pins on the arduino are PWM only when you use analog out ... they are same as the other pins if you use digital out ... the reason to use PWM on the motor driver is not direction, but speed
    – jsotola
    Commented Sep 22, 2020 at 20:41
  • what are the signal polarities for forward and what are they for reverse?
    – jsotola
    Commented Sep 22, 2020 at 20:44

1 Answer 1

2

Pwm is just a digital out with extra fancy on off controls. You can use any digital out if you do not need those extra features.

To just signal a single H bridge (1 motor of your l289n) for forward, reverse, stop, one only needs two digital outs.

I recommend you get the hang of your h bridge first - signaling it on a bread board with vcc (usually 5v but can be 3.3) and ground rather than the arduino. Then once you understand the motor directions that result from your wiring, write the code accordingly. This tends to result in:

  1. fewer fried arduinos
  2. code with functions and signals named after their intent (rather than having to mix forward and reverse)
5
  • I know, my connection would be , Common Ground for 9v battery and arduino, Then , power the motor driver GND and +12 volt terminals, connect arduino VIN pin to the +5v output of the driver and bingo! It shouldn't burn my board. Commented Sep 22, 2020 at 18:21
  • 1
    If you mean one of those square 9V battery like in a smoke detector then I think you will be disappointed. They’re not much good for motors. Try a handful of AA or AAA would be much better. 9V pp3 batteries can’t produce much current at one time.
    – Delta_G
    Commented Sep 22, 2020 at 18:50
  • 1
    Also don’t connect Vin to 5V. Vin needs at least 7V. If you have regulated 5V then put it on the 5V pin.
    – Delta_G
    Commented Sep 22, 2020 at 18:51
  • Will Duracell 9v batteries work? And also, the 5 volt is going to be regulated from the 9 volt battery by a resistor. Commented Sep 23, 2020 at 2:39
  • yes the 9v will run the arduino over vin. It will produce 5V for you. Both your arduino and l298n have proper regulators for producing 5V so you shouldnt have to do anything but hook the 9V to them (correctly) to produce 5V.
    – Abel
    Commented Sep 23, 2020 at 2:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.