Hi
I am writing a simple code to test a L9110 motor driver that I have.
The component I am using are:
L9110 2 channel motor driver
2 toy motors
And also the Arduino Uno R3 that I purchase from this official Arduino store (less than a month ago)
I wrote a simple test sketch. The aim is to repeatedly spin and stop the motors with intervals:
const int PINAIN1 =7;
const int PINAIN2 = 12;
const int PINBIN1 = 13;
const int PINBIN2 = 8;
void setup()
{
pinMode(PINAIN1,OUTPUT);
pinMode(PINAIN2,OUTPUT);
pinMode(PINBIN1,OUTPUT);
pinMode(PINBIN2,OUTPUT);
}
void loop() {
forward();
delay(1000);
halt();
delay(5000);
}
void halt()
{
digitalWrite(PINAIN1, LOW);
digitalWrite(PINAIN2, LOW);
digitalWrite(PINBIN1, LOW);
digitalWrite(PINBIN2, LOW);
}
void forward()
{
digitalWrite(PINAIN1, HIGH);
digitalWrite(PINAIN2, HIGH);
digitalWrite(PINBIN1, HIGH);
digitalWrite(PINBIN2, HIGH);
}
When I upload the program, both motors turned for about 5 seconds and stopped completely. Meaning the motors would spin for about 3-5 seconds immediately after the upload is completed, and nothing else would happen after that.
I tried changing the sketch here and there to figure out what was wrong but each time the outcome was the same- the motors turned for a few second and stopped completely after that.
Lastly, I tried uploading the program below, which the motors should not spin at all, but the same thing happened- the motors was on for a few seconds after upload and stopped.
const int PINAIN1 =7;
const int PINAIN2 = 12;
const int PINBIN1 = 13;
const int PINBIN2 = 8;
void setup()
{
pinMode(PINAIN1,OUTPUT);
pinMode(PINAIN2,OUTPUT);
pinMode(PINBIN1,OUTPUT);
pinMode(PINBIN2,OUTPUT);
}
void loop() {
halt();
delay(5000);
}
void halt()
{
digitalWrite(PINAIN1, LOW);
digitalWrite(PINAIN2, LOW);
digitalWrite(PINBIN1, LOW);
digitalWrite(PINBIN2, LOW);
}
void forward()
{
digitalWrite(PINAIN1, HIGH);
digitalWrite(PINAIN2, HIGH);
digitalWrite(PINBIN1, HIGH);
digitalWrite(PINBIN2, HIGH);
}
I also tried setting the values of pins to low in the setup loop, but the same thing happened
void setup()
{
pinMode(PINAIN1,OUTPUT);
pinMode(PINAIN2,OUTPUT);
pinMode(PINBIN1,OUTPUT);
pinMode(PINBIN2,OUTPUT);
digitalWrite(PINAIN1, LOW);
digitalWrite(PINAIN2, LOW);
digitalWrite(PINBIN1, LOW);
digitalWrite(PINBIN2, LOW);
}
I can't figure out why this is happening. Please help.
I have some questions:
-
Do I need to include any library if I were to use L9110?
I read this link http://me.web2.ncut.edu.tw/ezfiles/39/1039/img/617/L9110_2_CHANNEL_MOTOR_DRIVER.pdf before writing the sketch above, and seems that they did not use any library. -
Would it be advisable to connect the driver pins (eg: PINAIN1 etc) to PWM output (using anologWrite ) if I am using L9110? I am using digital i/o pins (digitalWrite()) at the moment
Thank you for your time