# Behavior Based Artificial Intelligent Mobile Robot with Sharp GP2D120 Distance Measuring Sensor – BRAM Part 2 Using Pic

What is the intelligent anyway; could we categories how the bees building their tiny hexagonal compound nest, ants searching for their food or birds migration using precision navigation over continental are the intelligent acts; or we as the human being with our cultures and civilizations is the only one that can be categories as the intelligent being? These kinds of question probably will not have satisfied answer as the answer is more philosophy terms rather than physics or mathematics law; therefore I think anyone could give their own opinion to this question.

Continuing our tutorial about BRAM (Building BRAM your first Autonomous Mobile Robot using Microchip PIC Microcontroller – Part 1); this time we will learn how to program BRAM brain and at the same time we learn how to use the Microchip PIC16F690 microcontroller EUSART (Enhanced Universal Synchronous Asynchronous Receiver Transmitter) peripheral for debugging BRAM program; later on we will add the distance measuring sensor for enhancing the obstacle avoidance capabilities to BRAM; this time we will use sharp GP2D120 analog distance measuring sensor.

As you learn through these two tutorials, building BRAM is not just a matter of building a robot; which of course is cool (…yeah…I’ve build a robot) but is more than that; building a robot required you to use your imagination and knowledge about how to build the robot chassis, choosing the right stuff to put on your robot, maximizing the microcontroller’s peripherals to support your robot and finally programming your robot; this kind of knowledge is very important in the embedded system control used in many industries.

BRAM Steering

BRAM steering method use what is called “differential drive“, this method use two DC motor mounted in fixed positions on the left and right side of BRAM chassis; each motor can rotate independently both in forward or reverse direction. By controlling these two DC motors rotate direction; we could control how BRAM move.

One of the important things is the DC motor polarity because the polarity will effect the DC motor rotate direction, you should experiment with it or you could simply change the logic truth table shown above to reflect your DC motor condition. For example in order to make your left DC motor to rotate counterclockwise than the L293D INPUT1 should be logical “1” and the INPUT2 should be logical “0” while the enable input for the buffer (ENABLE 1 and ENABLE 2) should be remain high (logical “1“) and vise versa.

The C function that control the BRAM steering is BRAM_steer(), which simply supply the right logic to the L293D input ports according to the truth table shown above:

```// Define BRAM Steering
#define MOVE_FORWARD 0
#define TURN_LEFT 1
#define TURN_RIGHT 2
#define ROTATE_LEFT 3
#define ROTATE_RIGHT 4
#define MOVE_BACKWARD 5
#define FULL_STOP 6
```