Arnov Sharma
Published © GPL3+

Simple HC05 robot

Create a minimal robot setup with L298N motor driver and HC-05 Bluetooth module.

IntermediateFull instructions provided30 minutes1,143
Simple HC05 robot

Things used in this project

Hardware components

Arduino Pro Mini 328 - 5V/16MHz
SparkFun Arduino Pro Mini 328 - 5V/16MHz
×1
SparkFun Full-Bridge Motor Driver Breakout - L298N
SparkFun Full-Bridge Motor Driver Breakout - L298N
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
11.1V lithium ion battery pack
×1
UTSOURCE Electronic Parts
UTSOURCE Electronic Parts
everything above can be found here for a low price
×1

Software apps and online services

bluetooth terminal

Story

Read more

Schematics

controlador-de-motores-doble-puente-h-l298_jEnV1TuHgp.jpg

Code

code

C/C++
int motorLpin1 = 2;
int motorLpin2 = 3; 
int motorRpin1 = 4;
int motorRpin2 = 5;
int rightMotorENA = 6;
int leftMotorENB = 9;



int motorSpeed = 255;
int turn=50;
void setup()
{
  Serial.begin(9600);
  Serial.flush();
  pinMode(motorLpin1,OUTPUT);
  pinMode(motorLpin2,OUTPUT);
  pinMode(motorRpin1,OUTPUT);
  pinMode(motorRpin2,OUTPUT);
  pinMode(rightMotorENA,OUTPUT);
  pinMode(leftMotorENB,OUTPUT);

}

void loop(){
  String input="";
  while(Serial.available()){
    input+=(char)Serial.read();
    delay(5);
  }
    
  if(input=="n"){
    MotorStop();
  }
  else if(input=="F"){
    MotorForward();
  }
  else if(input=="R"){
    MotorBackward();
  }
  else if(input=="TL"){
    MotorLeft();
  }
  else if(input=="TR"){
    MotorRight();
  }
  
  else if(input=="RR"){
    rightRight();
  }
  
  else if(input=="M"){
    StraightStraight();
  }

 
 
}

void MotorForward(void)
{
  digitalWrite(motorLpin1,HIGH);
  digitalWrite(motorLpin2,LOW);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
}

void MotorBackward(void)
{
  
  digitalWrite(motorLpin1,LOW);
  digitalWrite(motorLpin2,HIGH);
  digitalWrite(motorRpin1,LOW);
  digitalWrite(motorRpin2,HIGH);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);  
}
void MotorLeft(void)
{
  digitalWrite(motorLpin1,HIGH);
  digitalWrite(motorLpin2,LOW);
  digitalWrite(motorRpin1,LOW);
  digitalWrite(motorRpin2,HIGH);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
}
void MotorRight(void)
{
 
  digitalWrite(motorLpin1,LOW);
  digitalWrite(motorLpin2,HIGH);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255); 
}
void MotorStop(void)
{
  
  digitalWrite(motorLpin1,LOW);
  digitalWrite(motorLpin2,LOW);
  digitalWrite(motorRpin1,LOW);
  digitalWrite(motorRpin2,LOW);
  digitalWrite(leftMotorENB,LOW);
  digitalWrite(rightMotorENA,LOW);
}




void rightRight(void){
  
  digitalWrite(motorLpin1,LOW);   //turn right 
  digitalWrite(motorLpin2,HIGH);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
  delay(600);
  analogWrite(leftMotorENB,LOW);
  analogWrite(rightMotorENA,LOW);
  delay(600);
}

void StraightStraight (void){
  
  digitalWrite(motorLpin1,HIGH); //staright
  digitalWrite(motorLpin2,LOW);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
  delay(4000);
  analogWrite(leftMotorENB,LOW);
  analogWrite(rightMotorENA,LOW);
  delay(500);

  digitalWrite(motorLpin1,LOW);   //turn right 
  digitalWrite(motorLpin2,HIGH);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
  delay(100);
  analogWrite(leftMotorENB,LOW);
  analogWrite(rightMotorENA,LOW);
  delay(500);

  digitalWrite(motorLpin1,HIGH); //straight
  digitalWrite(motorLpin2,LOW);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
  delay(4000);
  analogWrite(leftMotorENB,LOW);
  analogWrite(rightMotorENA,LOW);
  delay(500); 

  digitalWrite(motorLpin1,LOW);   //turn right 
  digitalWrite(motorLpin2,HIGH);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
  delay(100);
  analogWrite(leftMotorENB,LOW);
  analogWrite(rightMotorENA,LOW);
  delay(500);

  digitalWrite(motorLpin1,HIGH); //straight
  digitalWrite(motorLpin2,LOW);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
  delay(4000);
  analogWrite(leftMotorENB,LOW);
  analogWrite(rightMotorENA,LOW);
  delay(500);

   digitalWrite(motorLpin1,LOW);   //turn right 
  digitalWrite(motorLpin2,HIGH);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
  delay(100);
  analogWrite(leftMotorENB,LOW);
  analogWrite(rightMotorENA,LOW);
  delay(500);

  digitalWrite(motorLpin1,HIGH); //straight
  digitalWrite(motorLpin2,LOW);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
  delay(4000);
  analogWrite(leftMotorENB,LOW);
  analogWrite(rightMotorENA,LOW);
  delay(500); 

  digitalWrite(motorLpin1,LOW);   //turn right 
  digitalWrite(motorLpin2,HIGH);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
  delay(100);
  analogWrite(leftMotorENB,LOW);
  analogWrite(rightMotorENA,LOW);
  delay(500);

  digitalWrite(motorLpin1,HIGH); //straight
  digitalWrite(motorLpin2,LOW);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
  delay(4000);
  analogWrite(leftMotorENB,LOW);
  analogWrite(rightMotorENA,LOW);
  delay(500);

    digitalWrite(motorLpin1,LOW);   //turn right 
  digitalWrite(motorLpin2,HIGH);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
  delay(100);
  analogWrite(leftMotorENB,LOW);
  analogWrite(rightMotorENA,LOW);
  delay(500);

  digitalWrite(motorLpin1,HIGH); //straight
  digitalWrite(motorLpin2,LOW);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
  delay(4000);
  analogWrite(leftMotorENB,LOW);
  analogWrite(rightMotorENA,LOW);
  delay(500); 

  digitalWrite(motorLpin1,LOW);   //turn right 
  digitalWrite(motorLpin2,HIGH);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
  delay(100);
  analogWrite(leftMotorENB,LOW);
  analogWrite(rightMotorENA,LOW);
  delay(500);

  digitalWrite(motorLpin1,HIGH); //straight
  digitalWrite(motorLpin2,LOW);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
  delay(4000);
  analogWrite(leftMotorENB,LOW);
  analogWrite(rightMotorENA,LOW);
  delay(500);

   digitalWrite(motorLpin1,LOW);   //turn right 
  digitalWrite(motorLpin2,HIGH);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
  delay(100);
  analogWrite(leftMotorENB,LOW);
  analogWrite(rightMotorENA,LOW);
  delay(500);

  digitalWrite(motorLpin1,HIGH); //straight
  digitalWrite(motorLpin2,LOW);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
  delay(4000);
  analogWrite(leftMotorENB,LOW);
  analogWrite(rightMotorENA,LOW);
  delay(500); 

  digitalWrite(motorLpin1,LOW);   //turn right 
  digitalWrite(motorLpin2,HIGH);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
  delay(100);
  analogWrite(leftMotorENB,LOW);
  analogWrite(rightMotorENA,LOW);
  delay(500);

  digitalWrite(motorLpin1,HIGH); //straight
  digitalWrite(motorLpin2,LOW);
  digitalWrite(motorRpin1,HIGH);
  digitalWrite(motorRpin2,LOW);
  analogWrite(leftMotorENB,255);
  analogWrite(rightMotorENA,255);
  delay(4000);
  analogWrite(leftMotorENB,LOW);
  analogWrite(rightMotorENA,LOW);
  delay(500);  
}

Credits

Arnov Sharma

Arnov Sharma

51 projects • 83 followers
Just your average MAKER

Comments