# Control speed of motors with Arduino

I'm trying to control the speed of two motors with a code I found on the internet, in the beginning I was able to control the speed of the two motors and they'd spin at the same time but after a couple of days they don't want to spin, I have to spin a little bit the rotor shaft so they start spinning

``````#define E1 10  // Enable Pin for motor 1
#define E2 11  // Enable Pin for motor 2

#define I1 8  // Control pin 1 for motor 1
#define I2 9  // Control pin 2 for motor 1
#define I3 12  // Control pin 1 for motor 2
#define I4 13  // Control pin 2 for motor 2

void setup() {

pinMode(E1, OUTPUT);
pinMode(E2, OUTPUT);

pinMode(I1, OUTPUT);
pinMode(I2, OUTPUT);
pinMode(I3, OUTPUT);
pinMode(I4, OUTPUT);
}

void loop() {

analogWrite(E1, 153);
analogWrite(E2, 153);

digitalWrite(I1, HIGH);
digitalWrite(I2, LOW);
digitalWrite(I3, HIGH);
digitalWrite(I4, LOW);

}
``````

Here's the schematic diagram of the circuit that I used http://hardwarefun.com/tutorials/controlling-speed-of-dc-motors-using-arduino

The only difference between that circuit and mine is that my Arduino is connected to the computer and I didn't use the battery, therefore I'm not using pin 8 of the I.C or Vin from Arduino, strangely both motors work with the speed of 255, but not with 153.

It was working fine a couple of days ago, what could possible have gone wrong? Please I need help

Maybe the motor bearings are wearing? You might try starting the motors with 255, wait 15 - 20 milli seconds, then drop back to 153, giving them a “kickstart”.
Pin 8 is the input for motor power, looks like you’re trying to power the motors with logic voltage, only 5V and low current, how are you powering the motors?
From the datasheet:

9.1 Application Information
A typical application for the L293 device is driving a two-phase motor. Below is an example schematic displaying
how to properly connect a two-phase motor to the L293 device.
Provide a 5-V supply to V CC1 and valid logic input levels to data and enable inputs. V CC2 must be connected to a
power supply capable of supplying the needed current and voltage demand for the loads connected to the
outputs.

In the drawing, the 9v battery is supplying the power to the motors and also to the arduino. By removing the battery and using usb only, you are powering the arduino, which is trying to power the motors. Don't do that. Motors can pull a lot of current during start/stall, which the arduino/usb isn't capable of supplying.

You can use BOTH battery and usb if you do it right. The battery hooks to the H-bridge motor power and ground. The ground rail has to be connected from the motor ground to battery ground AND to the arduino gnd as well.

You must always have power to pin 8 of the chip or risk frying something.

Motors take a lot of current, you have to supply enough.