I set up this circuit which uses L293D motor driver IC to control two DC motors.
+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.