My HC05 bluetooth module is not working with Arduino Uno. I am using a L293D IC to control 2 DC Motors.
The LED in the module blinks fine and connects to mobile too but it doesn't receive or transmit any signal. When I send a signal from the serial monitor, the motors move. Here is the schematics for the module -
5V - Arduino's 3.3V
GND - Arduino's GND
TX - Arduino's Digital Pin 2
RX - Arduino's Digital Pin 3
Here is the code -
#include <SoftwareSerial.h>
#define M1A 7
#define M1B 9
#define M2A 4
#define M2B 10
SoftwareSerial BT(3,2); //RX | TX
void setup() {
// put your setup code here, to run once
BT.begin(9600);
Serial.begin(9600);
pinMode(M1A,OUTPUT);
pinMode(M1B,OUTPUT);
pinMode(M2A,OUTPUT);
pinMode(M2B,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()){
char input = Serial.read();
if(input == '1'){
Serial.println("Moving Car Forward...");
digitalWrite(M1A,HIGH);
digitalWrite(M1B, LOW);
digitalWrite(M2A,HIGH);
digitalWrite(M2B,LOW);
}
else if(input == '2'){
Serial.println("Moving Car Backward...");
digitalWrite(M1A, LOW);
digitalWrite(M1B, HIGH);
digitalWrite(M2A,LOW);
digitalWrite(M2B,HIGH);
}
else if(input == '3'){
Serial.println("Moving Car Leftward...");
digitalWrite(M1A,LOW);
digitalWrite(M1B,LOW);
digitalWrite(M2A,HIGH);
digitalWrite(M2B,LOW);
}
else if(input == '4'){
Serial.println("Moving Car Rightward...");
digitalWrite(M1A,HIGH);
digitalWrite(M1B,LOW);
digitalWrite(M2A,LOW);
digitalWrite(M2B,LOW);
}
else if(input == '0'){
Serial.println("Stopping Car...");
digitalWrite(M1A,LOW);
digitalWrite(M1B,LOW);
digitalWrite(M2A,LOW);
digitalWrite(M2B,LOW);
}
}
if(BT.available()){
char input2 = BT.read();
if(input2 == '1'){
Serial.println("Moving Car Forward...");
digitalWrite(M1A,HIGH);
digitalWrite(M1B, LOW);
digitalWrite(M2A,HIGH);
digitalWrite(M2B,LOW);
}
else if(input2 == '2'){
Serial.println("Moving Car Backward...");
digitalWrite(M1A, LOW);
digitalWrite(M1B, HIGH);
digitalWrite(M2A,LOW);
digitalWrite(M2B,HIGH);
}
else if(input2 == '3'){
Serial.println("Moving Car Leftward...");
digitalWrite(M1A,HIGH);
digitalWrite(M1B,LOW);
digitalWrite(M2A,LOW);
digitalWrite(M2B,LOW);
}
else if(input2 == '4'){
Serial.println("Moving Car Rightward...");
digitalWrite(M1A,HIGH);
digitalWrite(M1B,LOW);
digitalWrite(M2A,LOW);
digitalWrite(M2B,LOW);
}
else if(input2 == '0'){
Serial.println("Stopping Car...");
digitalWrite(M1A,LOW);
digitalWrite(M1B,LOW);
digitalWrite(M2A,LOW);
digitalWrite(M2B,LOW);
}
}
}
It will be great if you please figure out the mistake fast because I have to show this in an exhibition in a week.