Title: Help Needed with Arduino Uno Project: Motor Control Issue

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

Welcome to the forum

Start by printing the command received via Bluetooth. You will need to add the Serial,begin() command in setup()

1 Like

i got lost can you change the part of code if possible

Add

Serial.begin(115200);

to setup()

Add

Serial.println(command);

after you read the value of command and before you call the Stop() function in loop()

Open the Serial monitor and set its baud rate to 115200. What do you seen in the Serial monitor ?

as soon i send control to go forward serial monitor displays F
F
and as soon as i stop sending command it shows S. so hc 05

Do you mean that when you send a single F it prints F then prints F again on the next line ?

What is sending the commands and is it sending anything anything after the command character ?

yes F on another line if i hold the button and S if i do not press any button and printing nothing after F

i even gave arduino another power supply amd l293d another supply. so i dissconeted the power pins from l293d. in short only the analog pins a1 a2 a3 a4 a5 and pins 1 2 3 4 5 6 7 8 9 12 13 so no connection of power between l293d and arduino

I suspect that there are problems in the code that controls the car and/or the circuit or power to the motors but there is obviously something wrong with the data being received as well

The second F on a newline indicates that at least a Newline character is being received and possibly a Carriage Return as well. Receiving an S is also a mystery because according to you nothing is being sent

What exactly is sending the commands ? You refer to a button but what does that button control ?

S means stop so I use a app which has 4 controls left right forward backward. Whenever I click forward button it sends F. As soon i stop pressing any button maybe the app automatically sends Stop command. Maybe there might be error in app because as I click F within milliseconds the app sends S

Your code always stops the motors if any character is received and that includes the S and any line ending characters

Comment out the call to Stop() after reading the command

Are you sure the Adafruit board you're using today is the 1.2 Motor Shield? That product is discontinued acc to Adafruit and the youtube you're following is three years old.

Adafruit links to this if yours is the 2.0 shield

https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/using-dc-motors

You'll need to install different libraries if so then try a couple of their example sketches to see if you get any action. I've always found Adafruit's own tutorials to be among the best out there, if you haven't already, I'd look through there

On the first try 2 months ago I made it but only 3 motors were moving so I rebuilded the whole project but after rebuilding no motors were moving with same code. I bought 4 shields because I thought I fryed all boards. But after trying it with all boards still not moving. So how do I identify which version it is or which library to use

This could be your bluetooth function not passing the information to make your motors run... but verify your motors first...

Verify each motor is working by using the battery with each motor.

  • connecting battery(plus) to motor(plus)
  • touch battery(minus) to motor(minus)
  • the motor should be running at top speed in one direction.
  • exchange B+ and B-
  • the motor should run "backward" from the first test.

If all your motors work, next step is communicating with the Motor Driver board.

On this link to a forum page, search for the "MOTORS" section. You will find ten motor tests that should work through your shield if you can address the Arduino DIO/PWM pins connected to your motors. The first eight tests focus on one motor at a time. Test 9 and 10 will exercise two motors at a time, in both directions, at varying speeds.

tried it but still same issue I even tried using different libraries but the issues persists. motors are working

Please, explain what you tried, and what you observed. "it" made no mention of a library. Also "it" included direct battery-to-motor. Is your battery the right size, not charged, did the motors run at full speed? Reverse?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.