0

I set up this circuit which uses L293D motor driver IC to control two DC motors.

LM298D motor driver

+6V input is connected to unregulated power supply. It's current rating is 500 mA.

There is a connection between Arduino's ground line and power supplies ground line. There is a parallel 0.1 uF capacitor connected between motor terminal pins.

There is a wheel at the end of the motors but they don't have a gearbox. The wheels are suspended so that they can rotate freely.

The source code of the software is as follows.

#include <Arduino.h>

unsigned int firstMotorPositive = 8;
unsigned int firstMotorNegative = 7;
unsigned int enableFirstMotor = 9;
unsigned int secondMotorPositive = 5;
unsigned int secondMotorNegative = 4;
unsigned int enableSecondMotor = 3;

void setup()
{
    pinMode(firstMotorPositive, OUTPUT);
    /*  I've changed this part as shown by @timemage  */
    //pinMode(secondMotorPositive, OUTPUT); // <------
    pinMode(firstMotorNegative, OUTPUT);
    pinMode(enableFirstMotor, OUTPUT);
    pinMode(secondMotorPositive, OUTPUT);
    pinMode(secondMotorNegative, OUTPUT);
    pinMode(enableSecondMotor, OUTPUT);

    // All motors are off
    digitalWrite(firstMotorPositive, LOW);
    digitalWrite(firstMotorNegative, LOW);
    digitalWrite(secondMotorPositive, LOW);
    digitalWrite(secondMotorNegative, LOW);
}

void turnOnMotors()
{
    // Set motors to maximum speed
    // For PWM maximum possible values are 0 to 255
    analogWrite(enableFirstMotor, 255);
    analogWrite(enableSecondMotor, 255);


    // Turn on motor A & B
    digitalWrite(firstMotorPositive, HIGH);
    digitalWrite(firstMotorNegative, LOW);
    digitalWrite(secondMotorPositive, HIGH);
    digitalWrite(secondMotorNegative, LOW);
    delay(2000);

    // Turn off motors
    digitalWrite(firstMotorPositive, LOW);
    digitalWrite(firstMotorNegative, LOW);
    digitalWrite(secondMotorPositive, LOW);
    digitalWrite(secondMotorNegative, LOW);

    analogWrite(enableFirstMotor, 0);
    analogWrite(enableSecondMotor, 0);

}

void speedControl()
{
    digitalWrite(firstMotorPositive, HIGH);
    digitalWrite(firstMotorNegative, LOW);
    digitalWrite(secondMotorPositive, HIGH);
    digitalWrite(secondMotorNegative, LOW);


    analogWrite(enableFirstMotor, 63);
    analogWrite(enableSecondMotor, 63);

    delay(3000);

    analogWrite(enableFirstMotor, 127);
    analogWrite(enableSecondMotor, 127);
    delay(3000);

    analogWrite(enableFirstMotor, 191);
    analogWrite(enableSecondMotor, 191);
    delay(3000);
/*
    analogWrite(enableFirstMotor, 255);
    analogWrite(enableSecondMotor, 255);
    delay(3000);
*/


    // All motors are off
    digitalWrite(firstMotorPositive, LOW);
    digitalWrite(firstMotorNegative, LOW);
    digitalWrite(secondMotorPositive, LOW);
    digitalWrite(secondMotorNegative, LOW);
    analogWrite(enableFirstMotor, 0);
    analogWrite(enableSecondMotor, 0);
}

void loop()
{

    /*
      turnOnMotors();
      delay(1000);
    */

    speedControl();
    delay(1000);
}

The problem is they need help to start rotating. They will only start rotating if I physically twist the shaft with my fingers first.

As far as I know the motors used in this circuit are two 6 volt DC motors.

When I measure the maximum voltage between motor terminals I read about 0.5 volts. If I twist the shaft I read about 4.5 volts.

4
  • 1
    does the motor spin when connected directly to the power supply?
    – jsotola
    Nov 23, 2020 at 20:11
  • 1
    Yes. If I connect motors to simple 1.5 volts battery it spins.
    – Erdem
    Nov 23, 2020 at 20:13
  • I've already tried that but it doesn't help either.
    – Erdem
    Nov 23, 2020 at 21:49
  • It is also possible that there are physical problems in the wiring. A clear picture of your actual wiring end to end may help someone spot something.
    – timemage
    Nov 24, 2020 at 13:52

3 Answers 3

1

The L2978D is a terrible motor driver (I really wish people wouldn't use it!). It is "bipolar" which means that both the high and low side switches of the H-bridge are Bipolar Junction Transistors. This means that you get about 1.4V voltage drop in total between the inputs and outputs.

To counter that you must provide at least 1.4V more than your motors need for them to operate properly.

1
  • I switched to unregulated power supply to 7.5 volts. I measured unregulated voltage with a DIMM. It was about 12.8 volts. Still, motors don't start. I've also tried with 9 volts. They don't also start with 9 volts.
    – Erdem
    Nov 23, 2020 at 20:22
1

no pinMode(firstMotorNegative, OUTPUT)

Well, here's a start at least:

pinMode(firstMotorPositive, OUTPUT);
pinMode(secondMotorPositive, OUTPUT); // <------
pinMode(enableFirstMotor, OUTPUT);
pinMode(secondMotorPositive, OUTPUT);
pinMode(secondMotorNegative, OUTPUT);
pinMode(enableSecondMotor, OUTPUT);

You are never setting firstMotorNegative to OUTPUT and probably intended to on the second line of this excerpt.

firstMotorNegative floating or pulled high

The AVR GPIO pins are INPUT on power-up. Writing to the PORT register, which is what digitalWrite does, takes on a different meaning when the pin's mode is INPUT. That is, it enables or disables the pull-up internal resistors. In other words, your digitalWrite(firstMotorNegative, HIGH); and digitalWrite(firstMotorNegative, LOW); are effectively toggling between pinMode(firstMotorNegative, INPUT_PULLUP) and pinMode(firstMotorNegative, INPUT) respectively.

So your L293D is seeing either this signal being weakly pulled up or floating. During the floating condition in particular maybe a problem when you're doing:

// Turn on motor A & B
digitalWrite(firstMotorPositive, HIGH);
digitalWrite(firstMotorNegative, LOW);

... because you're disabling the pull-up here, the "negative" pin is INPUT/floating rather than reliably LOW. So, it may be being intermittently interpreted as HIGH at the L293D, in which case there is no movement while that's happening.

2
  • Thanks I've edited the code as you suggested. But practically there is no difference.
    – Erdem
    Nov 24, 2020 at 13:30
  • @Erdem I will look for more problems again later and update this if I find anything I'm reasonably certain is a problem.
    – timemage
    Nov 24, 2020 at 13:51
0

That is operating as expected. Take a look at the data sheet. You can lose 1.8 volt on each output pin. Since you are in bridge configuration you now lose 3.6 Volts. Now assume your power is 6VDC with 1 volt ripple. That adds to the voltage drop through the driver so rounding it out you lose 4 volts from your supply (not counting wiring loses) before you start, that is assuming the voltage does not droop. Two simple solutions, use a power supply with more voltage or go to a MOSFET bridge device.

4
  • Thanks for the suggestions. I have an adjustable DC adapter which provides unregulated 1.5 V, 3 V, 4,5 V, 6 V, 7.5 V, 9 V and 12 V with up to 500 mA of current. I graudually switched from 6 volts to 12 volts. But motors don't spin. This confuses me since one of the motor with a small wheel attached starts spinning with only 1.5 volts battery but doesn't spins with an external DC adapter. I switched DC adapter to 6 V and measured unregulated voltage with a DIMM. It was about 17 volts. Isn't it a huge voltage for for such a small toy DC motor?
    – Erdem
    Nov 24, 2020 at 13:53
  • Your best bet is to use a regulated power supply with enough power to drive your load with some spair. An unregulated power supply has ripple, the amount depending on the design and components chosen. Not knowing your DMM and your adapter I can only guess but try measuring the output voltage in the AC range, it should be almost nothing. If you get a value it is a rough approximation of your AC content.
    – Gil
    Nov 25, 2020 at 22:13
  • I use pen type Mastech MS8211D multimeter. I switched unregulated DC adapter to 6 volts setting. I selected AC and used max function to measure maximum voltage. This is quite interesting because it reads maximum voltage as 5.1 volts AC. Also DC voltage was about 10.5 volts.
    – Erdem
    Nov 26, 2020 at 8:10
  • I think we need to go back to the beginning and have you go to this link electronics-tutorials.ws It is teaches the basics of electronics. While you are studying that get a regulated 10 or 12 volt power source rated at 2 amps or more. If you are in this for the long hall get a Lab Power supply, that runs about $60 on ebay, possibly a Christmas present. The only common thread is the power supply you are using. Also get an Arduino motor shield with FET outputs. This should get rid of the unknowns and get you started.
    – Gil
    Nov 26, 2020 at 23:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.