Hi everyone, I am a newbie in developing with Arduino. I have a project that using two Motors DC 12V to control car with Arduino, two Motors will be input same Voltage, same direction. I have one idea that is wiring motor 1 (ENA, IN1, IN2) and motor 2 (ENB, IN3, IN4) into same PIN in Arduino UNO R3 (PIN 2, 3, 4). When I turn on supply, two motors work correctly but when I stop, just one Motor stopped, the other motor does not stop and voltage increase about 7V (it is so large). Can someone help me to fix it or my idea is incorrect?
Code project:
Wiring here is the power cord connecting the motor circuit to Arduino (sorry for my English a bit poor) and I use XY-160D to control two motors DC 775.
But if you electrically connect ENA with ENB, IN1 with IN3 and IN2 with IN4 it does not make sense to use the library L298NX2. This is only required for a standard wiring.
[Edit:] I have replicated your setup with an Arduino Nano, a L298N board, two motors and a separate power supply for the motor driver. It worked (as expected). If the second motor does not stop, you might doublecheck your wiring....
Using the standard lib L298N.h for this "hardwired" solution shows the same behaviour. (However I had to change the speed to something above 100 to get both motors running.),
Because I saw that this library has the same function to run DC motors, and when I used it with my motors (without sharing the same pins), it worked very well. That’s why I decided to use it.
Did you test your application with the code from my post 10? To get the same results you should change the speed in setSpeed() from 15 to 30.
As @jim-p also posted there's nothing wrong with using the library L298N.h. It internally applies the same functions that you are using in your sketch.
Usually you'll find examples, (not always) further explanations but most interestingly: The source code of the library!
Well written libraries consist of
A header file (.h) that includes all information relevant for a use of the library in a sketch.
The main .cpp file that includes the source code for each of the classes, their methods and functions.
Of course it is of advantage to understand the principles of C++ classes but studying the code and structure of libraries can lead to a great step forward.
Just as an example see how the methods forward() and backward() are implemented in L298N.cpp: