Introduction: Build a Simple Robot Using a Arduino and L293 (H-Bridge)

Hey folks, this is my first instructable, and I'm here to demonstrate how to build a simple robot with a bit of Arduino programming don't worry, I have attached the code file below, you can use it for reference.
Those who have no idea about an Arduino UNO and L298 or H-bridge, don't worry I will explain in much as detail as possible and this is a fairly simple instructable.

Arduino Uno: Is a popular tool for making projects that can sense and control more of the physical world than just your desktop (or) it's just a platform where it takes inputs from different kinds of switches or sensors and correspondingly control output device such as motors, led and much more (There are a bunch of microcontrollers which you can try but the Arduino UNO is the most popular).

.H-bridge (L298): It is an electronic circuit that enables voltage across a load in either direction (or) it is simply called as a motor driving tool, it has large application in robotics because it can change the direction of the motor depending on the logic state of the respective Arduino pin (reverse or backward).

So let's jump into building it.

Step 1: TOOLS REQUIRED:

So the parts/components required to start up the projects are:

  • 1 x Arduino uno (or similar boards)
  • 1 x H-bridge or L298
  • 2 x Geared motors (I used 12v motors)
  • Jumper wires
  • Chassis
  • Bearing ball
  • Breadboard
  • Bluetooth Module (HC:05)
  • 2 x Wheels suitable for gears

Step 2: BUILDING UP THE SKELETON(BODY) OF THE ROBO

The construction of the robot is really a very simple one, let me try to explain it as simple as possible.

In 1st picture I have shown the assemble of components in the rear side of the chassis:

1st Step: Fix the motors to the wheels through the holes given the chassis (the black metal thing that supports all component). Note: That the wheel is tightly fixed into the hole provided in the motor arm.

2nd Step: Place the battery below using a tape n provide the connection to the H-bridge to drive motors.if you using a 3v motor use 3 x AA battery and place them in a battery holder.

3rd Step: Fix the ball bearing(the red thing) the working of this is same as that of the old school ball mouse which had a ball for free movement, so to avoid the friction in the front part of the robot I used it. You can also use a long screw n wrap the tip with a plastic cover as an alternative.

Now 2nd picture shows the construction of the chassis in front part:

1st Step: Its very simple fix a breadboard to the front portion using double sided tape.

so now you are done with the body, it's time to place the piece of the body.

Step 3: THE MOTOR MODULE OR L298:

So here I start with motor module before I start with this I would like you to watch the video below for better understanding of it's uses and demonstration.

As I mentioned at starting of the instructables this IC is nothing but a motor module used to drive motors in both direction more over Arduino alone can't supply energy for the working of motor thus for this reason also I use this IC.

So the connections should be given as mentioned below:

1) Ground

2) Pin 1 of Left Side Motors

3)Pin 2 for Left Side Motors

4) +12v battery

5)Arduino Pin 2

6) Arduino Pin 3

7) Arduino Pin 4

8) Ground

9) +5v from Arduino

10) Arduino Pin 5

11) Arduino Pin 6

12) Arduino Pin 7

13) Pin 1 of Right Side Motors

14) Pin 2 of Right Side Motors

15) Ground

Step 4: Fixing Bluetooth Module to Arduino:

Now the last thing left for the construction left is fixing bluetooth module to the Arduino board.

Here check out the video for the easy fixing of module to the board.


NOTE: FIX THE MODULE AFTER YOU FINISHING THE CODING OF YOUR BOARD OR ELSE IT WILL DISPLAY SOME ERROR.

Step 5: Hardware Completed.

When you finished the above the above instruction, you should have something like this type so now we are two step left from completing the project.

1st one is powering up the Arduino using the 12 volt adapter pin which is fixed to a battery FIGURE 2

2nd coding your board, if u don't know how to program no worries have a seat out download the file give below and attach it to Arduino IDE.

So after you upload your code download application called Bluetooth Spp pro from Android Playstore or any other site

Before using this application you need to pair up the module with your mob then the led of the module will blink one per second.

Later connect the module through the application then the led will blink twice per second.

Here are the Controls

w - Forward

s - Reverse

a - Left

d - Right

If you are using PC download Teraterm thats it, this tutorial just came to the end. Next lined up is a series of fun instructables so stay tuned.

Step 6: Code

Here is the Code to uplaod to the robot or the Arduino UNO -

#include 
Servo servoMain;
float temp;
int tempPin = 0;
int r_motor_n = 2;  //PWM control Right Motor -
int r_motor_p = 4;  //PWM control Right Motor +
int l_motor_p = 5;   //PWM control Left Motor +
int l_motor_n = 7;   //PWM control Left Motor -
int enable = 3;
int light = 9;
int enable2 = 6;
int incomingByte = 0; // for incoming serial data
void setup()
{
  servoMain.attach(10);
  pinMode(r_motor_n, OUTPUT);  //Set control pins to be outputs
  pinMode(r_motor_p, OUTPUT);
  pinMode(l_motor_p, OUTPUT);
  pinMode(l_motor_n, OUTPUT);
  pinMode(enable, OUTPUT);
  pinMode(enable2, OUTPUT);
  pinMode(light, OUTPUT);
 
  digitalWrite(r_motor_n, LOW);  //set both motors off for start-up
  digitalWrite(r_motor_p, LOW);
  digitalWrite(l_motor_p, LOW);
  digitalWrite(l_motor_n, LOW);
  digitalWrite(enable, LOW);
  digitalWrite(enable2, LOW);
  digitalWrite(light, HIGH);
  
 
  Serial.begin(9600);  
 
  Serial.print("Whats up im ATOM, geared up!!!! \n");
  Serial.print("w = Forward \n");
  Serial.print("s = Backward \n");
  Serial.print("d = Right \n");
  Serial.print("a = Left \n");
  Serial.print("f = Stop  \n");
  Serial.print("stive robotics");
}
void loop()
{
 
      
 
   if (Serial.available() > 0) {
  // read the incoming byte:
  incomingByte = Serial.read();
  }
 
 
 
  switch(incomingByte)
  {
     case 'f':
       digitalWrite(r_motor_n, LOW);  //Set motor direction, 1 low, 2 high
       digitalWrite(r_motor_p, LOW);
       digitalWrite(l_motor_p, LOW); 
       digitalWrite(l_motor_n, LOW);
       digitalWrite(enable, LOW);
       digitalWrite(enable2, LOW);
       Serial.println("Stop\n");
       incomingByte='*';
     
     break;
    
     case 'd':
       digitalWrite(r_motor_n, HIGH);  //Set motor direction, 1 low, 2 high
       digitalWrite(r_motor_p, LOW);
       digitalWrite(l_motor_p, HIGH); 
       digitalWrite(l_motor_n, LOW);
       digitalWrite(enable, HIGH);
       digitalWrite(enable2, HIGH);
       Serial.println("right\n");
       incomingByte='*';
     break;
   
      case 'a':
       digitalWrite(r_motor_n, LOW);  //Set motor direction, 1 low, 2 high
       digitalWrite(r_motor_p, HIGH);
       digitalWrite(l_motor_p, LOW); 
       digitalWrite(l_motor_n, HIGH);
       digitalWrite(enable, HIGH);
       digitalWrite(enable2, HIGH);
       Serial.println("left\n");
       incomingByte='*';
     break;
    
     case 'w':
       digitalWrite(r_motor_n, HIGH);  //Set motor direction, 1 low, 2 high
       digitalWrite(r_motor_p, LOW);
       digitalWrite(l_motor_p, LOW); 
       digitalWrite(l_motor_n, HIGH);
       digitalWrite(enable, HIGH);
       digitalWrite(enable2, HIGH);
       Serial.println("forward\n");
       incomingByte='*';
     break;
    
       case 's':
       digitalWrite(r_motor_n, LOW);  //Set motor direction, 1 low, 2 high
       digitalWrite(r_motor_p, HIGH);
       digitalWrite(l_motor_p, HIGH); 
       digitalWrite(l_motor_n, LOW);
        digitalWrite(enable, HIGH);
       digitalWrite(enable2, HIGH);
       Serial.println("backwards\n");
       incomingByte='*';
     break;
     
  case 'O':
    digitalWrite(light, LOW);
    break;
    
    case '1':
    servoMain.write(0);
    break;
   
     case '2':
    servoMain.write(45);
    break;
    
      case '3':
    servoMain.write(90);
    break;
   
     case '4':
    servoMain.write(135);
    break;
   
     case '5':
    servoMain.write(180);
    break;
    
    case 't':
    temp = analogRead(tempPin);
  temp = temp * 0.48828125;
  Serial.print("TEMPRATURE = ");
  Serial.print(temp);
  Serial.print("*C");
  Serial.println();
  delay(1000);
    break;
    
     case 'v':
     Serial.print("atom ");
     Serial.println();
     Serial.print("stive robotics atom");
     incomingByte='*';
     break;
    
    delay(5000);
  
  
  }