

- #How to set up the l298n motor driver how to#
- #How to set up the l298n motor driver full#
- #How to set up the l298n motor driver code#
#How to set up the l298n motor driver code#
If you were to keep the jumper connecting 5v to ENA, you have all the code you need to start work. Nothing says that if your motor is the other way around that you are doing it wrong, it is just my choice of words. Note: Clockwise and counter clockwise is dependant on your wiring. in1 = HIGH, in2 = HIGH -> Motor is plaid, just kidding, it is OFF again.in1 = LOW, in2 = HIGH -> Motor is moving COUNTER.in1 = HIGH, in2 = LOW -> Motor is moving CLOCKWISE.Let's take a look at the 4 possible states. As I said, in1 and in2 control if the motor is on or the direction of spin. The digitalWrite lines are interesting though. I just defined which pins I am using to keep it clean then declared them as output pins in setup. Making sure I don't get my beard tangled

Let's start with just the definitions and setup. There may be some libraries to do fancy schmancy stuff, but I didn't even bother looking. If you remove that jumper and connect it to an arduino pin, you will be able to vary the speed.
#How to set up the l298n motor driver full#
If you do not remove that jumper, the motor when told to move, will move at full speed. The L298N ships with a jumper connecting it to the 5v pin directly north of it.

The ENA pin that you will find to the left of the IN1 and IN2 pins is connected with a green wire to pin 8 of the arduino. However, if you want to change the speed of the motor, as I did/do, then you need one more. Technically, we have discussed all the connections you need to get a motor moving.
#How to set up the l298n motor driver how to#
More on how to use these pins later in the code. The same applies for IN3 and IN4 but for the motor to the right, which we are not using in this example. These pins will control whether the left motor is stopped, moving clockwise, or moving counter clockwise. In my diagram I have an orange and blue wire connecting the IN1 and IN2 pins to pins 9 and 10 of the arduino. Look to the 4 pins in the middle as these are the INs. To the right of the power screw terminals you will find these IN pins and others. Each of these OUT connections have corresponding IN connections that you will connect to the arduino. These are where you attach the DC motors. The left and right sides of the L298N each have a pair of screw terminals. I can not confirm this personally but I believe if you are using over 12v, then you should remove the 5VEN jumper and input 5v from another source to the 5v screw terminal that you see me stealing power from. DO NOT use this regulator if you are using more than 12v, but I really can't speak to if the L298N should be used with over 12v either way. To use the 5v output, as I have done to power the arduino, you need to use a jumper connecting the two pins just north of the power screw terminals labelled 5VEN.

One of the handy features I was alluding to earlier is that the L298N has a voltage regulator that we can utilize as a 5v source. This will provide the power for the DC motors. The positive and negative from this go directly to the 12V and GND screw terminals on the L298N. Starting with the far right, you will find my usual barrel jack which I use to connect a 12v 4a power supply. Second, I am only using the L298N to drive one DC motor at the moment but you can independently drive a second motor with just one driver. I won't into the technical intricacies of the L298N, but it has some really useful features for not much money that is great for TipsyBrew.įirst off, if you haven't been keeping tabs on the project, I am using the arduino MEGA 2560 full time now because the OLED requires too much memory for the UNO to be reasonable. All we need here is an arduino, 12v power, 12v DC motor, and of course an L298N driver.
