Hello! I'm fairly new to the Arduino world but I stupidly decided to use it for a school project, which's deadline is very close. I'm using a Arduino Uno and a l9110 h-bridge to move two motors. The problem I'm having is that the code never seems to reach the end, randomly stopping at different intervals. Sometimes the first motor will not spin at all, sometimes it reached the stage where motor B goes to spin for the second time. The fact that it is stopping in random places is making me believe it is a wiring problem but I would love for someone to take a look at my code
const int A1A = 8;
const int A1B = 9;
const int B1A = 10;
const int B1B = 11;
void setup(){
pinMode(A1A, OUTPUT);
pinMode(A1B, OUTPUT);
pinMode(B1A, OUTPUT);
pinMode(B1B, OUTPUT);
}
void loop(){
digitalWrite(A1A, HIGH); //STAIRS COME BACK
digitalWrite(A1B, LOW);
delay(2600);
digitalWrite(A1A, 0);
digitalWrite(A1B, 0);
delay(1000);
digitalWrite(B1A, HIGH); //LIFT GOES UP
digitalWrite(B1B, LOW);
delay(10000);
digitalWrite(B1A, 0);
digitalWrite(B1B, 0);
delay(5000);
digitalWrite(B1A, LOW); //LIFT GOES DOWN
digitalWrite(B1B, HIGH);
delay(10000);
digitalWrite(B1A, 0);
digitalWrite(B1B, 0);
delay(1000);
digitalWrite(A1A, LOW); //STAIRS GO FORWARD
digitalWrite(A1B, HIGH);
delay(2600);
}
At the end of loop(), motor A is going one direction and when loop() restarts the motor is slammed the other way. That motor will draw a lot of current when that happens.
Please post a schematic.
What is the motor power supply? Supply voltage? Supply current capacity?
One of these 9V batteries? Those lack the current capability to, reliably and for any length of time, supply current to a motor(s). You need a supply that can handle the combined stall currents of your motors. The stall current should be listed in the motor specification sheet.
Or study the schematic symbols and hand draw, photograph and post the schematic.
What are the voltage requirements of the project? Motor rated voltage? Motor stall current?
I would use a power supply capable of supplying the voltage and current to the motors and either a separate supply for the Arduino or supply the Arduino from a voltage converter from the motor supply voltage to the Arduino supply voltage.