Hi!
My project is basically taking in a Bluetooth signal of a single value, based on which it will run the required motors to open or close a compartment of a water filter.
I am currently using an Arduino Uno, a Motor Shield L293D and a Bluetooth module hc05 to do this project.
Originally, I tried using the below code to run the project, however, the motors would never run, only buzz, unless I physically moved them. I had connected 4 double a batteries to the external power, and increased it all the way until I had 12 double a batteries to the external power, with the same result.
The Bluetooth module worked fine, and the code was fine to my knowledge, as the motors buzzing matched up to what I had them running as based on the code. All the motors work when connected to a single double a battery without the arduino, so the motors are not faulty.
The motors are only supposed to run one at a time, and the module only takes between 3.6 to 6V, so I assumed that in all, I would only need 9V or 10V, yet I don't get the proper output. The end result is that these motors should roll a string to lift up the edge of a 3d printed compartment about 3 by 5 inches, so relatively light, but for that I need this to run.
Below is my code for the original project, and my (poorly drawn) schematic.
#include <AFMotor.h>
#include <SoftwareSerial.h>
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
char value = ' ';
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()>0) { //If connected {
value = Serial.read();
}
switch (value) {
case '0': {
motor1.setSpeed(250); //0 to 255 speed settings
motor1.run(FORWARD);
delay(1000); //in milliseconds
motor1.run(BACKWARD);
delay(1000);
motor1.run(RELEASE);
motor3.setSpeed(100);
motor3.run(FORWARD);
delay(2000);
motor3.run(RELEASE);
break;
}
case '1': {
motor1.setSpeed(250); //0 to 255 speed settings
motor1.run(FORWARD);
delay(1250); //in milliseconds
motor1.run(BACKWARD);
delay(1250);
motor1.run(RELEASE);
motor3.setSpeed(100);
motor3.run(FORWARD);
delay(2000);
motor3.run(RELEASE);
break;
}
case '2': {
motor1.setSpeed(250); //0 to 255 speed settings
motor1.run(FORWARD);
delay(1500); //in milliseconds
motor1.run(BACKWARD);
delay(1500);
motor1.run(RELEASE);
motor3.setSpeed(100);
motor3.run(FORWARD);
delay(2000);
motor3.run(RELEASE);
break;
}
case '3': {
motor1.setSpeed(250); //0 to 255 speed settings
motor1.run(FORWARD);
delay(1750); //in milliseconds
motor1.run(BACKWARD);
delay(1750);
motor1.run(RELEASE);
motor3.setSpeed(100);
motor3.run(FORWARD);
delay(2000);
motor3.run(RELEASE);
break;
}
case '4': {
motor2.setSpeed(250); //0 to 255 speed settings
motor2.run(FORWARD);
delay(2000); //in milliseconds
motor2.run(BACKWARD);
delay(2000);
motor2.run(RELEASE);
motor3.setSpeed(100);
motor3.run(FORWARD);
delay(2000);
motor3.run(RELEASE);
break;
}
case '5': {
motor2.setSpeed(250); //0 to 255 speed settings
motor2.run(FORWARD);
delay(1000); //in milliseconds
motor2.run(BACKWARD);
delay(1000);
motor2.run(RELEASE);
motor3.setSpeed(100);
motor3.run(FORWARD);
delay(2000);
motor3.run(RELEASE);
break;
}
case '6': {
motor2.setSpeed(250); //0 to 255 speed settings
motor2.run(FORWARD);
delay(1250); //in milliseconds
motor2.run(BACKWARD);
delay(1250);
motor2.run(RELEASE);
motor3.setSpeed(100);
motor3.run(FORWARD);
delay(2000);
motor3.run(RELEASE);
break;
}
case '7': {
motor2.setSpeed(250); //0 to 255 speed settings
motor2.run(FORWARD);
delay(1500); //in milliseconds
motor2.run(BACKWARD);
delay(1500);
motor2.run(RELEASE);
motor3.setSpeed(100);
motor3.run(FORWARD);
delay(2000);
motor3.run(RELEASE);
break;
}
case '8': {
motor2.setSpeed(250); //0 to 255 speed settings
motor2.run(FORWARD);
delay(1750); //in milliseconds
motor2.run(BACKWARD);
delay(1750);
motor2.run(RELEASE);
motor3.setSpeed(100);
motor3.run(FORWARD);
delay(2000);
motor3.run(RELEASE);
break;
}
case '9':
motor2.setSpeed(250); //0 to 255 speed settings
motor2.run(FORWARD);
delay(2000); //in milliseconds
motor2.run(BACKWARD);
delay(2000);
motor2.run(RELEASE);
motor3.setSpeed(100);
motor3.run(FORWARD);
delay(2000);
motor3.run(RELEASE);
break;
case '-': //if the app sends the default value - this is for testing
Serial.println("Not a recognized value.");
default:
break;
}
value = ' ';
}
This morning, I decided to strip the entire project and just had one connected motor and 6 double a batteries connected to the external power source, with a USB connected to my laptop powering the arduino (so two different power sources). The motor works when twisted, but now, it does not buzz. It does work sometimes upon the power being connected to the arduino, but not always.
Any advice? What am I doing wrong?
Motors used:
Motor Shield:
If there is any other information necessary, please let me know and I will add it as soon as I see it, or if I need to switch out any parts for better results, any guidance would be helpful. Thank you so much!!!

