Professional Documents
Culture Documents
int in1 = 9;
int in2 = 8;
// motor two
int enB = 5;
int in3 = 7;
int in4 = 6;
void setup()
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
void demoOne()
// this function will run the motors in both directions at a fixed speed
// turn on motor A
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(enA, 200);
// turn on motor B
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
analogWrite(enB, 200);
delay(2000);
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
delay(2000);
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
void demoTwo()
// this function will run the motors across the range of possible speeds
// note that maximum speed is determined by the motor itself and the operating voltage
// the PWM values sent by analogWrite() are fractions of the maximum speed possible
// by your hardware
// turn on motors
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
analogWrite(enA, i);
analogWrite(enB, i);
delay(20);
analogWrite(enA, i);
analogWrite(enB, i);
delay(20);
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
void loop()
demoOne();
delay(1000);
demoTwo();
delay(1000);
SHARE THIS
37 likes
RELATED ARTICLES
Hi Guys This article is about something every electronics enthusiast would want to learn and master. Its
name might...
How to run small brushed motor for mini quadcopter with Arduino+
How to run small brushed motor for mini quadcopter with Arduino
Hi Guys, I have read the question on many forms, How to run small brushed motor for mini
quadcopter....
Arduino and Bluetooth HC-06 to Control the LED with Android Device+
Arduino and Bluetooth HC-06 to Control the LED with Android Device
Hi everyone, In this project i will show you how to control LED light with your Android device along...
Ultrasonic Distance sensor HC-04 with Arduino - DIY Distance Meter project+
Ultrasonic Distance sensor HC-04 with Arduino – DIY Distance Meter project
DIY distance meter with an Arduino and ultrasonic distance sensor Hi Folks, Ones again I am going to
write...
In this article you will get the code and circuit diagram to control the DC Motor CW/CCW using GY-521
gyroscope and...
Hi folks I am back ones again to share with you my simple but useful project and step by...
If you are a beginner and want to enter the world of Robotics and want to build your own...
How to Run Stepper Motor with Arduino using L298N Driver Module
Hi Guys, In this post, I will demonstrate how you can run or control 6 wired unipolar stepper motor...
12 COMMENTS
CrystalRunner
2 years ago
Arduino: 1.8.5 (Windows Store 1.8.10.0) (Windows 10), Board: “Arduino/Genuino Uno”
C:\Users\User\Desktop\SKETCHES\DualHBridgeDCMotor_Sketch\DualHBridgeDCMotor_Sketch.ino: In
function ‘void demoTwo()’:
analogWrite(enA, i);
exit status 1
REPLY
Author
REPLY
REPLY
remove the spaces behind the scope or in other words remove the indentations. to verify the keywords
should be colored, check that
REPLY
Matey Ankit
2 years ago
I want to run 24v dc motor having 10kg torque, 30 rpm with the help of aurdino uno
REPLY
md.intishar ul islam
2 years ago
how to contro??
by joystic???
REPLY
Shashi Kiran
2 years ago
My DC motor spins one direction only when connected thru the L298. I have adapted the code above. I
dont think the problem is with the code or the motor as I tested the motor by connecting + and – to 12V
directly and changed polarities and it spins both directions. But when I connect thru the L298 then only
1 direction works.
How can I debug the L298. At this time I have only 1 DC geared 100 rpm motor. Have not connected
another motor.
The Power is thru a 12V DC wall adapter. The controls to the L298 are thru the Arduino Pins 6 and 7. Pin
9 is set to analogWrite of PWM 255. ( of course the jumper on EN-A Enable A is removed and controlled
thru the Arduino.
REPLY
I also have the same problem if you get the solution please let me know
REPLY
Emon
12 months ago
How can I do the same thing with Arduino & L293D motor shield ?
REPLY
Vinod
11 months ago
I also have the same problem if you get the solution please let me know
REPLY
Harshala
4 months ago
hi
I am not getting any error but the motor is not running please help
REPLY
Abhishek Gupta
3 months ago
REPLY
Leave a reply
Your email address will not be published. Required fields are marked *
Comment
Name *
Email *
Website
Save my name, email, and website in this browser for the next time I comment.
Admin
Follow4
37 likes
Find us on Facebook
Members
Newest | Active
admin
manjunath s
Mandeep Singh
Kristen
beipsychsebi
Recent Posts
Recent Comments
Abhishek Gupta on How to control DC motor with L298N driver and Arduino.
Categories
3d Printer
Arduino
Circuits
Cool Projects
technology
Search
Categories
3d Printer (5)
Arduino (19)
Circuits (1)
technology (1)
Tag Cloud
3d PrinterArduinoCircuitsCool Projectstechnology
notification icon