Can you guys help me to check if the coding was wrong or not?

Im using this code to program my project which is using bluetooth hc-05 to control 2 dc motor and im using L298N motor driver. After im upload the code and i send data to the arduino and it didn’t respond anything but phone can detect the bluetooth module. Can you guys help me to solve the problem?

sorry for being rude for the post and thanks for the respond guys. My circuit has been attached.

This is my code

#include <SoftwareSerial.h>
SoftwareSerial BlueTooth(1, 0);    // (TXD, RXD) of HC-05
char BT_input;                    // to store input character received via BT.
int motorPin1 = 2;                // pin 2 on L298N 
int motorPin2 = 3;                // pin 3 on L298N 
int motorPin3 = 4;               // pin 4 on L298N 
int motorPin4 = 5;               // pin 5 on L298N 

void setup()  
{
  BlueTooth.begin(9600);  
  Serial.begin(9600);
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
}

void loop() 
{
  if (BlueTooth.available())
  {
   BT_input=BlueTooth.read();
    if (BT_input=='s')
    {
      digitalWrite(motorPin1, LOW);   
      digitalWrite(motorPin2, LOW);   
      digitalWrite(motorPin3, LOW);   
      digitalWrite(motorPin4, LOW);   
      Serial.println("Motors are Off");
    }
    else if (BT_input=='b')
    {
      digitalWrite(motorPin1, LOW);   
      digitalWrite(motorPin2, HIGH);  
      digitalWrite(motorPin3, LOW);   
      digitalWrite(motorPin4, HIGH);  
      Serial.println("Motors are rotating left");
    }
    else if (BT_input=='f')
    {
      digitalWrite(motorPin1, HIGH); 
      digitalWrite(motorPin2, LOW); 
      digitalWrite(motorPin3, HIGH); 
      digitalWrite(motorPin4, LOW); 
      Serial.println("Motors are rotating right");
    }
   else if (BT_input=='r')
    {
      digitalWrite(motorPin1, HIGH); 
      digitalWrite(motorPin2, LOW); 
      digitalWrite(motorPin3, LOW); 
      digitalWrite(motorPin4, HIGH); 
      Serial.println("First Motor is rotating right & Second is left");
    }
    else if (BT_input=='l')
    {
      digitalWrite(motorPin1, LOW); 
      digitalWrite(motorPin2, HIGH); 
      digitalWrite(motorPin3, HIGH); 
      digitalWrite(motorPin4, LOW); 
      Serial.println("First Motor is rotating Left & second is right");
    }
  }
 
}

motor_control_with_hc-05.ino (1.91 KB)

Arduino to hc-05.png

Your post is very rude.

Please edit your title and your post to use lower case letters.

Please don’t SHOUT. As well as being rude, text in all-capitals is very hard to read.

What happens when you run your program?

It is much easier to help when you tell us that, and also what you want the program to do that is different.

If the program will not compile then please post the error message.

…R

SoftwareSerial BlueTooth(5, 6);    // (TXD, RXD) of HC-05

int motorPin4 = 5;               // pin 5 on L298N

You cannot use pin 5 for both the motor control and the software serial port.

Please read the "how to use this forum-please read" stickies to see how to properly post code and error messages and some hints on how tho ask a good question.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom. :slight_smile:

jremington:
Your post is very rude.

Please edit your title and your post to use lower case letters.

Sorry and thanks for the remind:D

Robin2:
Please don't SHOUT. As well as being rude, text in all-capitals is very hard to read.

What happens when you run your program?

It is much easier to help when you tell us that, and also what you want the program to do that is different.

If the program will not compile then please post the error message.

...R

Sorry for being rude and thanks for the remind:D Btw i successfully upload my coding to arduino. But im using the serial monitor to send data to arduino and it didn't respond anything. but the bluetooth module is on and can be pair.

Nizamniizamm:
But im using the serial monitor to send data to arduino and it didn't respond anything. but the bluetooth module is on and can be pair.

Because your code does not respond to serial input; it responds to bluetooth input

TomGeorge:
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom. :slight_smile:

Thanks for the information:D Btw im just attached the circuit. Thanks for the reply

groundFungus:

SoftwareSerial BlueTooth(5, 6);    // (TXD, RXD) of HC-05

int motorPin4 = 5;              // pin 5 on L298N




You cannot use pin 5 for both the motor control and the software serial port.

Please read the "[how to use this forum-please read](http://forum.arduino.cc/index.php/topic,148850.0.html)" stickies to see how to properly post code and error messages and some hints on how tho ask a good question.

Thanks for the information:D I’ll try to fix it.

Nizamniizamm:
Thanks for the information:D Btw im just attached the circuit. Thanks for the reply

I don't see any attachment

...R

SoftwareSerial BlueTooth(1, 0);    // (TXD, RXD) of HC-05

An Arduino Uno uses these pins for hardware serial, doesn't it?