0

I am trying to make a 4WD vehicle. I have uploaded the code, all connections are OK and I have used L298N and HC-05. But when running the Bluetooth app, the motors do not rotate. I tried with both an Uno and a Nano and nothing happens. Could anyone help me spot the errors?

I used this code in Arduino Uno:

#include <SoftwareSerial.h>

SoftwareSerial BT(0, 1); //TX, RX respetively
String readvoice;

void setup() {
  BT.begin(9600);
  Serial.begin(9600);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
}
//-----------------------------------------------------------------------//
void loop() {
  while (BT.available()) {  //Check if there is an available byte to read
    delay(10);              //Delay added to make thing stable
    char c = BT.read();     //Conduct a serial read
    readvoice += c; //build the string- "forward", "reverse", "left" and "right"
  }
  if (readvoice.length() > 0) {
    Serial.println(readvoice);

    if (readvoice == "*forward#")
    {
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(100);
    }
    else if (readvoice == "*back#")
    {
      digitalWrite(3, LOW);
      digitalWrite(4, LOW);
      digitalWrite(5, HIGH);
      digitalWrite(6, HIGH);
      delay(100);
    }
    else if (readvoice == "*left#")
    {
      digitalWrite(3, HIGH);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(800);
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(100);
    }
    else if (readvoice == "*right#")
    {
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(800);
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(100);
    }
    else if (readvoice == "*stop#")
    {
      digitalWrite(3, LOW);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(100);
    }
    else if (readvoice == "*keep watch in all direction#")
    {
      digitalWrite(3, HIGH);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(100);
    }
    else if (readvoice == "*show me Garba#")
    {
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(400);
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(600);
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, HIGH);
      digitalWrite(6, LOW);
      delay(500);
      digitalWrite(3, HIGH);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      digitalWrite(6, HIGH);
      delay(500);

      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(400);
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(600);
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, HIGH);
      digitalWrite(6, LOW);
      delay(500);
      digitalWrite(3, HIGH);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      digitalWrite(6, HIGH);
      delay(500);
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(400);
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(600);
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, HIGH);
      digitalWrite(6, LOW);
      delay(500);
      digitalWrite(3, HIGH);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      digitalWrite(6, HIGH);
      delay(500);
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(400);
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(600);
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, HIGH);
      digitalWrite(6, LOW);
      delay(500);
      digitalWrite(3, HIGH);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      digitalWrite(6, HIGH);
      delay(500);
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(400);
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(600);
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, HIGH);
      digitalWrite(6, LOW);
      delay(500);
      digitalWrite(3, HIGH);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      digitalWrite(6, HIGH);
      delay(500);
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(400);
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(600);
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, HIGH);
      digitalWrite(6, LOW);
      delay(500);
      digitalWrite(3, HIGH);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      digitalWrite(6, HIGH);
      delay(500);
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(400);
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(600);
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, HIGH);
      digitalWrite(6, LOW);
      delay(500);
      digitalWrite(3, HIGH);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      digitalWrite(6, HIGH);
      delay(500);
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(400);
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      delay(600);
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, HIGH);
      digitalWrite(6, LOW);
      delay(500);
      digitalWrite(3, HIGH);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      digitalWrite(6, HIGH);
      delay(500);
    }
    readvoice = ""; //Reset the variable
  }
}

This is the wiring diagram of the rover:

Wiring diagram

  • 1
    First try it without the bluetooth. What power source are you using for the motor? The L298 is a horribly lossy part and you'll need an extra AA cell or two just to offset its losses. Meanwhile the small 9v batteries wouldn't have the current capability for a motor project. And where are the other two motors to make this 4wd? – Chris Stratton Apr 14 '18 at 14:30
  • Sir i have used a 9v battery and i have connected the other 2 motor with the other motor and connected their positive and negative terminal together and please also tell me that the code is correct or not and if there is problem with L298N then what should i use.. – Aryan Dhall Apr 15 '18 at 5:05
  • Do not use 9v batteries for motor projects. Try 6 or 7 AA cells - with the absurdly lossy L298, maybe even 8 AA's. – Chris Stratton Apr 15 '18 at 16:37
  • 1
    Well, for one, you shouldn't use software serial on pins 0 and 1, those are hardware serial. Did you decide to do that on your own, or are you following directions written by someone who didn't know what they are doing? – Chris Stratton Apr 16 '18 at 13:51
  • 3
    Possible duplicate of Arduino 4wd rover – Code Gorilla May 23 '18 at 11:37
2

If you have the wiring right, which you have probably checked 100 times by now, then its probably the fact that you aren't supplying enough current to break the stall of the motor. Search the web for the motor's datasheet and look up the "Stall current" then see if you are supplying enough current.

Have you checked the motor without the gearbox attached, if that's possible?

The motor will have both voltage and current requirements. You are using a 6V motor but we also need to know the running current and stall current so you can workout if your batteries are capable of supplying that. Are you trying to run one motor or 4? Get one motor working first and then move up to 4 when you need to supply 4 times the power.

Also can I just check that you have the batteries in series (to give you 7.4V). This probably isn't enough if the motors require exactly 6v because of the 2V drop through the IC.

Measure the voltage into the bridge and into the motor, as shown in the web page. Also measuring the current would help, but you will have to search to see how best to do that.

  • Sir i have also used a 3.7 volt battery with 7800Mah for the gear motor.... – Aryan Dhall May 24 '18 at 10:45
  • Yes sir I have tried without gear and it still vibrates.... – Aryan Dhall May 25 '18 at 10:01
  • Please can you check the rest of the things in the answer too? – Code Gorilla May 25 '18 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.