I've been trying to get the L298N motor controller to work with the Arduino Mega 2560 rev3 but I've had no luck..
Does the L298N work with the Arduino Mega 2560 rev3?
I've tried following different examples online to simply connect the L298N to the Arduino and just run the motor in the forward direction but didn't get any response:
connected the enable to a PWM pin (speed control)
connected the in1 and in2 to standard digital pins (send high or low signal to the L298N using Arduino)
powered the L298N with 12v and the Arduino with 9v via DC Jack
Used truth table to assign forward direction
I did the above and didn't get a response, if I missed a step could you please let me know or if you've had a similiar issue and found a way to fix it I'd really appreciate you're advice.
Please provide a list of the specific pins you have the L298N connected to on your Mega.
Please post your full sketch. If possible, you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help. If the sketch is longer than the forum will allow then it's OK to add it as an attachment. After clicking the "Reply" button, you will see an "Attachments and other settings" link.
Please always do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.
When your code requires a library that's not included with the Arduino IDE please post a link (using the chain links icon on the toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.
//Motor test
int enA = 2;
int in1 = 22;
int in2 = 23;
void setup() {
// put your setup code here, to run once:
// Define inputs and outputs
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode (in2, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(enA, 100);
}
Are you using just the L298N IC or do you have breakout board with it on? Either way please draw a simple diagram showing ALL the connections. E.g. the IC has two power connections, one for the motor Vs and the other for the internal logic Vss. Are both connected?
I'm not using just the IC, I'm using the L298N motor controller board. I found an old 12v DC motor that I'm using for it but I don't have any additional details on the motor itself though. I just did a quick sketch to show how i have it connected it up. My understanding is though that the enable ENA is for when you want to apply a particular speed via PWM and just need to send either a high or low signal to set the direction of the motor using the the L298N's IN1 and IN2.
You don't seem to have a ground connection between the L298N board and the Arduino. That will stop it working.
And unfortunately when you say "the L298N motor controller board" there are actually dozens of them, all different. I notice yours has a 5V connector with nothing connected to it. Some controller boards have an onboard regulator to supply that 5V for the logic. Some don't and need an external supply.
Just wanted to say thank you and let everyone know the L298N problem has been fixed. Turns out connecting ground from the L298N to the Arduino Mega 2560 rev3 got it working
Travers:
I had no idea you need to connect the ground to the Arduino as well.
Think of it this way. Let's say you were of a mind to put 5V on that EN pin from a battery. You would have wired that battery's 5V +ve "pip" to EN, intuitively. But then you would have said Hmmmm, where does the other end of the battery go? You would probably have realised that just like you would have if the battery was powering a bulb, the other end goes to the -ve side of board where the EN connection is, the other side of the bulb as it were.
In case any one refers to this thread to help with a L298N problem the previous response may confuse, of course the positive and negative wires need to be connected. For example if you're powering the motor controller board with 12v the positive wire is fed into the 12v+ header and the negative in to the ground header but please be aware that an additional wire must be inserted into the L298N board ground header (alongside the negative wire inserted for the 12v power supply)and connected to the Arduino ground pin, otherwise it won't work.