L9110 motor driver sketch not working as expected

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:

  1. 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.

  2. 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

Hello,

Did you read the component datasheet?

The operation is of the Exclusive-Or (XOR) type, so when the inputs are in the same logical state the output will always be in a low logic state.

Datasheet L9110

Try this:

void forward()
{
 digitalWrite(PINAIN1, HIGH);
 digitalWrite(PINAIN2, LOW);
 digitalWrite(PINBIN1, HIGH);
 digitalWrite(PINBIN2, LOW);
}

Or:

void forward()
{
 digitalWrite(PINAIN1, LOW);
 digitalWrite(PINAIN2, HIGH);
 digitalWrite(PINBIN1, LOW);
 digitalWrite(PINBIN2, HIGH);
}

Thank you for your reply rTek1000!

I will shall try the codes that you have provided. May I know why the motors are always on for a few seconds after each upload ( my previous sketches)? They should not be turning at all because i set the pins with same values.

Thank you!

Hello,

Please let us know if everything went well, and when this happens, please add [Solved] at the beginning of the title,

Thank you,

Have fun!

Hell rTek1000,

I tried the XOR logic as you have suggested, and it worked but not quite expected. I have some questions:

Below is the code:

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,HIGH);
 digitalWrite(PINAIN2,HIGH);
 digitalWrite(PINBIN1,HIGH);
 digitalWrite(PINBIN2,HIGH);
}
void forward()
{
 digitalWrite(PINAIN1, LOW);
 digitalWrite(PINAIN2, HIGH);
 digitalWrite(PINBIN1, LOW);
 digitalWrite(PINBIN2, HIGH);
}

The motors would only spin and stop if I use HIGH for the halt() function. It would not work if I set all pins to LOW. Why is that so? Both pins HIGH and Both pins LOW should give 0, am I right?

After upload, the motors would spin/ stop for 2 times, and then the 3rd or 4th time, one of the motor would stop spinning ( while the other one is spinning very slowly (they usually spin fast during the first 2 or 3 cylces). The L9110 LED and the arduino LED seems to dim when that happen. Do you have any idea what is causing this? i tried uploading several times and the result is consistent. The spin/ stop only last about 3-4 cycles, sometimes only 2, and then one of the motor would stop working and the other 1 spin significantly slower than before.

Thank you for your help!

Hello,

It can be a problem with power,

What is the configuration of your hardware?

Which motor?

What power supply?

Hi rtek1000,

The arduino is connected to my laptop (which is always plugged in and fully charged ), and the L9110 is connected to the arduino pins as below:

PINAIN1 to pin 7;
PINAIN2 to pin 12;
PINBIN1 to pin13;
PINBIN2 to pin 8;

The VCC pin of L9110 is connected to the 5V pin of arduino.

The 2 motors I am using are just small toy motors that runs on 5 volt.

The motor that stop spinning is the connected to Output 2 of L9110.

Thank you!

snow_leopard:
arduino is connected to my laptop... and the L9110 is connected to the arduino... L9110 is connected to... arduino

Look, the USB port can provide up to 500mA, and it seems to me that the consumption of your motor, although it is small physically, may be draining a lot of current, so a protection may be being actuated.

The motor has a very high power consumption when it starts spinning, so it is recommended to use a different power source than the USB port.

You could even use the USB port to supply power to some motor, but you would have to use some current limiting circuit.

Thank you rtek1000,

I have my L9110 connected to a 6 V battery source (4x1.5 battery holder), and the motors work. Thank you very much for your guidance!

I have one last question- would it also be advisable to connect my Arduino Uno R3 to another power source( after I have upload sketches)? If yes, what kind of power source is recommendable?

Thank you!

@snow_leopard:. Please use your brief forum timeout to read the forum guidelines about not posting the same question multiple times in different parts of the forum.