How to use DC motor with Arduino Nano

Hey everyone

Let me just start off by saying I am very new to Arduino, circuits, and pretty much all of this, but I have to figure this out. That being said, I have a problem, and I'm not sure if I can even solve it with the components I have.

Basically I need to use some sort of an Arduino to power a DC motor, and that needs to be controlled via the program. I'm using an Arduino Nano, a breadboard, a motor controller (L298N), a DC motor, and a battery. I have all the necessary cables and wires.

I have a lot more experience programming, so I came up with this program (it compiles fine).

const int enB = 9;
const int in3 = 7;
const int in4 = 8;
void setup()
{
  // set all the motor control pins to outputs
  
  pinMode(enB, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
}
void loop()
{
  // turn on motor B
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  // set speed to 200 out of possible range 0~255
  analogWrite(enB, 200);
  delay(5000);
  // now change motor directions
 
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH); 
  delay(5000);
  // now turn off motors
 
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
}

Thanks

Go on and find out whether it works. If not, show your circuit diagram, battery type, and motor data sheet.

@aconncep:

L298N is one of the first motor driver I used to control small motors and also stepper motor too.. I love the IC so much... Anyway because its a famous motor driver, there are many tutorial online that teaches how to use the motor and how.

tronixlabs L298N motor driver.

A nano is basically an Arduino Uno with a very small form factor...

BTW, I would suggest to make a library for L298...

or atleast use a function to simplify coding.

What issue you are facing?
What is the voltage specification of the Motor?
How much your battery can supply?
Will the motor run, if you connect directly to battery?

Post a handrawn schematic, might be much better to understand.

OP's setup

It appears I've failed to mention this before but I've tried run the program on my set up and which it compiles correctly and uploads to the Nano there is no movement from the motors. I'm still in the processes of working on a circuit diagram and will post it when I'm done. For batteries I am using 4 AAA and have access to a 9 volt. While I dont have access to a data sheet I'm am currently using a 1.5 to 3VDC motor from radio shack but will be using 6VDC motor.

Yes the motor runs when connected to the battery

In the photo you attached, cant see the battery connection.

Can you please take one more photo, a bit closer? Or can you explain those yellow and black from Nano. I guess yellow is 5v and black is GND. Is the motor driver wired correctly?

Post a link to the driver.

Some Improved pictures of my setup. Everything should be wired correctly.

Motor Driver: http://www.oddwires.com/l298n-dual-h-bridge-dc-stepper-motor-controller-module-for-arduino/?gclid=CNmu9cqd_c0CFUIfhgodOg0BpA

Capture.jpg|0x0

Capture2.jpg|0x0

Capture3.jpg|0x0

Capture4.jpg|0x0

Seems like some issue with the photos, cant open them

Sorry about that, these should work




I assume you need to provide power to +12V in the driver board. +5v is used as operating volt and +12v used to power the DC motor.

Keep in mind, you should not draw power from VIN, it's for supplying raw voltage to Arduino. You can use 5v pin instead.

Serious advice requires a circuit diagram and data sheets. Images are useless for that purpose.

I think there is an error in your code, change enB = 100 then your motor would work

I am also facing the same problem .

aconncep:
Hey everyone

Let me just start off by saying I am very new to Arduino, circuits, and pretty much all of this, but I have to figure this out. That being said, I have a problem, and I'm not sure if I can even solve it with the components I have.

Basically I need to use some sort of an Arduino to power a DC motor, and that needs to be controlled via the program. I'm using an Arduino Nano, a breadboard, a motor controller (L298N), a DC motor, and a battery. I have all the necessary cables and wires.

I have a lot more experience programming, so I came up with this program (it compiles fine).

const int enB = 9;

const int in3 = 7;
const int in4 = 8;
void setup()
{
  // set all the motor control pins to outputs
 
  pinMode(enB, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
}
void loop()
{
  // turn on motor B
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  // set speed to 200 out of possible range 0~255
  analogWrite(enB, 200);
  delay(5000);
  // now change motor directions

digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);
  delay(5000);
  // now turn off motors

digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
}




Thanks

Did you ever get this to work? I'm attempting a similar thing, except with a stepper motor. If I'm not mistaken (and I could be because I'm new to this Arduino thing), the Nano's output pins operate at 3.3V, but the L298N input pins are 5V TTL.

aconncep:
Hey everyone

Let me just start off by saying I am very new to Arduino, circuits, and pretty much all of this, but I have to figure this out. That being said, I have a problem, and I'm not sure if I can even solve it with the components I have.

Basically I need to use some sort of an Arduino to power a DC motor, and that needs to be controlled via the program. I'm using an Arduino Nano, a breadboard, a motor controller (L298N), a DC motor, and a battery. I have all the necessary cables and wires.

I have a lot more experience programming, so I came up with this program (it compiles fine).

const int enB = 9;

const int in3 = 7;
const int in4 = 8;
void setup()
{
 // set all the motor control pins to outputs
 
 pinMode(enB, OUTPUT);
 pinMode(in3, OUTPUT);
 pinMode(in4, OUTPUT);
}
void loop()
{
 // turn on motor B
 digitalWrite(in3, HIGH);
 digitalWrite(in4, LOW);
 // set speed to 200 out of possible range 0~255
 analogWrite(enB, 200);
 delay(5000);
 // now change motor directions

digitalWrite(in3, LOW);
 digitalWrite(in4, HIGH);
 delay(5000);
 // now turn off motors

digitalWrite(in3, LOW);
 digitalWrite(in4, LOW);
}




Thanks

Did you ever get this to work? I'm attempting a similar thing, except with a stepper motor. If I'm not mistaken (and I could be because I'm new to this Arduino thing), the Nano's output pins operate at 3.3V, but the L298N input pins are 5V TTL. Can anyone verify this? The Nano documentation says, "Operating Voltage 3.3V," so I'm assuming that means both input and output voltage, given the extra complexity it would require to step up the voltage.

Los2000:
Did you ever get this to work? I'm attempting a similar thing, except with a stepper motor. If I'm not mistaken (and I could be because I'm new to this Arduino thing), the Nano's output pins operate at 3.3V, but the L298N input pins are 5V TTL.

The L298 is a brushed DC motor driver, NOT a stepper motor driver.
You can get away with that chip if... you have a high impedance stepper (post a link to the stepper).

An L298 is 5volt only, and a Nano (classic Nano) uses 5volt logic.
But the newer Nano series (confusing, because there are many) uses 3.3volt logic.
They can only work with modern drivers (the L298 is an inefficient dinosaur).
Tell us which Nano you have.
Leo..