Title: Help Needed with Arduino Uno Project: Motor Control Issue
Hello Everyone,
I hope you're all doing well. I'm reaching out to seek some assistance with a project I've been working on involving an Arduino Uno and a motor control setup.
Project Overview:
- Components: Arduino Uno, L293D motor driver, TT gear motors (4x), 7.4V lithium-ion battery.
- Objective: Control the movement of a car using the Arduino and Bluetooth module.
- Issue: Despite extensive troubleshooting, the motors are not responding to control commands.
Problem Details:
- I've wired the components according to the circuit diagram provided in the project documentation.
- The Arduino code has been uploaded without errors, and the Bluetooth module is successfully paired with my smartphone.
- When sending control commands ('F' for forward, 'B' for backward, etc.) via the Bluetooth module, the motors do not respond.
- I've checked the power supply voltage and current, and they seem to be within the required range for the motors and motor driver.
What I've Tried:
- Double-checked all connections and wiring.
- Tested the motors individually to ensure they're functional.
- Verified the Arduino code for any logical errors or issues.
- Used debug print statements to monitor the behavior of the code and components.
- Reviewed the datasheets and documentation for each component to ensure correct usage.
Seeking Assistance: Despite my efforts, I haven't been able to identify the root cause of the issue. If anyone has experience with similar projects or expertise in troubleshooting Arduino and motor control setups, I would greatly appreciate any insights or suggestions you can provide.
Additional Information:
- I can provide more detailed information, including the circuit diagram, Arduino code, and any other relevant details upon request.
- Any guidance or advice you can offer would be immensely helpful and greatly appreciated.
Thank you in advance for your time and assistance. I'm eager to overcome this obstacle and complete my project successfully.
Best regards,
Khushit
Here is the code
Arduino Bluetooth Controlled Car
Install Adafruit Motor Shield Library before uploading this code.
AFMotor Library https://learn.adafruit.com/adafruit-motor-shield/library-install
-> If you need helping guide on how to install library for the motor shield or how to use motor shield then
watch this: https://youtu.be/vooJEyco1J4
Caution: Remove the jumper or switch off the battery switch before connecting the Arduino board to computer.
For more support contact me on Telegram: @UtGoTech
*/
#include <AFMotor.h>
#include <SoftwareSerial.h>
SoftwareSerial bluetoothSerial(9, 10); // RX, TX
//initial motors pin
AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);
char command;
void setup()
{
bluetoothSerial.begin(9600); //Set the baud rate to your Bluetooth module.
}
void loop() {
if (bluetoothSerial.available() > 0) {
command = bluetoothSerial.read();
Stop(); //initialize with motors stoped
switch (command) {
case 'F':
forward();
break;
case 'B':
back();
break;
case 'L':
left();
break;
case 'R':
right();
break;
}
}
}
void forward()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(FORWARD); //rotate the motor clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(FORWARD); //rotate the motor clockwise
motor3.setSpeed(255); //Define maximum velocity
motor3.run(FORWARD); //rotate the motor clockwise
motor4.setSpeed(255); //Define maximum velocity
motor4.run(FORWARD); //rotate the motor clockwise
}
void back()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(BACKWARD); //rotate the motor anti-clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(BACKWARD); //rotate the motor anti-clockwise
motor3.setSpeed(255); //Define maximum velocity
motor3.run(BACKWARD); //rotate the motor anti-clockwise
motor4.setSpeed(255); //Define maximum velocity
motor4.run(BACKWARD); //rotate the motor anti-clockwise
}
void left()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(BACKWARD); //rotate the motor anti-clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(BACKWARD); //rotate the motor anti-clockwise
motor3.setSpeed(255); //Define maximum velocity
motor3.run(FORWARD); //rotate the motor clockwise
motor4.setSpeed(255); //Define maximum velocity
motor4.run(FORWARD); //rotate the motor clockwise
}
void right()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(FORWARD); //rotate the motor clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(FORWARD); //rotate the motor clockwise
motor3.setSpeed(255); //Define maximum velocity
motor3.run(BACKWARD); //rotate the motor anti-clockwise
motor4.setSpeed(255); //Define maximum velocity
motor4.run(BACKWARD); //rotate the motor anti-clockwise
}
void Stop()
{
motor1.setSpeed(0); //Define minimum velocity
motor1.run(RELEASE); //stop the motor when release the button
motor2.setSpeed(0); //Define minimum velocity
motor2.run(RELEASE); //rotate the motor clockwise
motor3.setSpeed(0); //Define minimum velocity
motor3.run(RELEASE); //stop the motor when release the button
motor4.setSpeed(0); //Define minimum velocity
motor4.run(RELEASE); //stop the motor when release the button
}
circuit diagram
