How to make a Bluetooth Controlled Car using Arduino At Home

 


Materials:- 

Arduino uno = https://bit.ly/30v5XcY​ Motor Drive L298N = http://bit.ly/3bVldY7 Bluetooth Module= https://bit.ly/3ztrTFQ Gear motor = http://bit.ly/3cH2nmO

Diagram:-




Connections:-

Bluetooth Module to Arduino
  • Bluetooth Module VCC = Arduino 5V
  • Bluetooth Module GND = Arduino GND
  • Bluetooth Module TX = Arduino RX
  • Bluetooth Module RX= Arduino TX
Motor Drive(L298N) to Arduino
  • Motor drive IN1 = Arduino D8
  • Motor drive IN2 = Arduino D9
  • Motor drive IN3 = Arduino D10
  • Motor drive IN4 = Arduino D11
  • Motor drive 5V out = Arduino Vin
  • Motor drive GND = Battery pack GND & Arduino GND
  • Motor drive  12V IN = Battery pack VCC
You must remove RX,TX pin before uploading the code

Code

char val;
#define leftforward 8
#define leftreverse 9
#define rightforward 10
#define rightreverse 11
void setup() {
   pinMode(leftforward,OUTPUT);
   pinMode(leftreverse,OUTPUT);
   pinMode(rightforward ,OUTPUT);
   pinMode(rightreverse,OUTPUT);
  Serial.begin(9600);

}

void loop() {
  if (Serial.available()) {
    val = Serial.read();
    Serial.println();
  }
  if (val == '1')
  { digitalWrite(leftforward, HIGH);
   digitalWrite(rightforward,HIGH);
    digitalWrite(leftreverse, LOW);
    digitalWrite(rightreverse,LOW);

  }
  else 
  if (val == '2')
  {digitalWrite(leftforward, LOW);
    digitalWrite(rightforward,LOW);
    digitalWrite(leftreverse, HIGH);
    digitalWrite(rightreverse,HIGH);
  }
   else 
  if (val == '3')
  {
    digitalWrite(leftforward, HIGH);
    digitalWrite(rightforward,LOW);
    digitalWrite(leftreverse, LOW);
    digitalWrite(rightreverse,HIGH);
  }
   else 
  if (val == '4')
  {
    digitalWrite(leftforward, LOW);
    digitalWrite(rightforward,HIGH);
    digitalWrite(leftreverse, HIGH);
    digitalWrite(rightreverse,LOW);
  }

  delay(100);
}