Hi and Welcome All,

In this tutorial series I will show you how to make a simple obstacle avoiding
robot using the xBoard
microcontroller board. xBoard v2.0 is well suited for developing
small intelligent robots as it is compact in size, has four DC motor controller,
can be programmed using USB Port and many other features. It is also very easy
to learn and use. The xAPI, which is a set of C functions which makes complex
programming tasks such as PWM ,LCD, Remote Control etc very easy for beginners.
You can buy it from here


Its design is open so if you don’t want to buy the board you can make it yourself
at home by the help of its schematic.

The Robo’s Task

The task of our robo is simple. To move randomly in an area avoiding obstacles,
that’s it ! Though the task is simple, its a complete autonomous robot in itself.
It has a brain which reads sensors
and makes decisions and command the motors.

In the course of making the robot you will learn various basic techniques which
will be of great use for your further projects.

Our Final Robot will look like this.

avr atmega32 based obstacle avoiding robot tutorial

AVR ATmega32 Based Obstacle Avoiding Robot

The following Video Demo Shows the Robo in Action

The following Video was submitted by Mr. André Giovann

We thanks Mr. Giovann for sharing his experience!

Mechanical Construction

The robot is built around a high
quality metal chassis
which you can purchase from any robotics
dealer. You can also buy it from our online
and we will appreciate your help. The robot is driven by
two 200
RPM DC Gear motor
. It uses differential drive system and has one
castor wheel in the front. The wheels
are directly coupled with the motors shaft.

The motors are mounted to the chassis by a nut provided in the shaft of the

differential drive robot

Differential Drive System with two back wheels and a front castor

The xBoard v2.0
is mounted by using the mounting kit provided with xBoard
. The mounting kit includes screws, nuts and standoffs. The
xBoard v2.0
is so designed that its mounting holes are neatly aligned with the holes in

xboard is the brain of our robot

xBoard v2.0 is the brain of our robot.

xboard the brain of our robots is easy to mount on the chassis

xBoard v2.0 is Easy to Mount


Mounting xBoard v2.0 with screws.


connecting motors with atmega32 xboard

Connecting Motor Wires


Just Plug and Play !

Differential Drive Explained

Differential drive is a drive system in which both motion and steering can
be done by two set of powered wheels. In differential drive their is a set of
LEFT wheels and a set of RIGHT wheels. Both are powered. It does not requires
turning of front wheel for the steering like we steer car or bikes. To turn
the vehicle (or robo) the LEFT and RIGHT wheels are rotated at "different"
speeds. That’s why its called differential drive. For example If the RIGHT wheels
rotates faster than the LEFT wheels then the robot will turn towards LEFT.

For this robot we will use the following rotation of wheel for the steering
and straight motion.

Motion LEFT Wheel RIGHT Wheel
Forward Counter Clockwise Clockwise
Backward Clockwise Counter Clockwise
Rotate LEFT Clockwise Clockwise
Rotate RIGHT Counter Clockwise Counter Clockwise

The following diagram explains robots differential drive in

Robotic Differential Drive System

Differential Drive System

So moving and steering the robot is just the matter of controlling two DC
motors. You can easily access DC
from xAPI. The details are given here.

Once you go through the articles you know how to start a particular motor either
in CW or CCW direction. Here MotorA will be the right motor and the MotorB will
be the left motor. So the following code snippets does the job.

Move Robo Forward

MotorA(MOTOR_CW,255);	//Right Motor Moves Clockwise (CW) with Full Speed (255)
MotorB(MOTOR_CCW,255); //Left Motor Moves Counter Clockwise (CCW) with Full Speed (255)

Move Robo Backward
MotorA(MOTOR_CCW,255);	//Right Motor Moves Counter Clockwise (CCW) with Full Speed (255)
MotorB(MOTOR_CW,255); //Left Motor Moves  Clockwise (CW) with Full Speed (255)

Rotate Robo Left
MotorA(MOTOR_CW,255);	//Right Motor Moves Clockwise (CW) with Full Speed (255)
MotorB(MOTOR_CW,255); //Left Motor Moves  Clockwise (CW) with Full Speed (255)

Rotate Robo Right
MotorA(MOTOR_CCW,255);	//Right Motor Moves Counter Clockwise (CCW) with Full Speed (255)
MotorB(MOTOR_CCW,255); //Left Motor Moves  Counter Clockwise (CCW) with Full Speed (255)

I have explained the code here so it does not create confusion when the whole
program (which is reasonably large)of the robot is presented to you.

To know more about the functions MotorA and MotorB please see their documentation

That’s all folks for this part! Don’t forget to post you comment and feedback.

And remember to subscribe your email to get the next part as soon as it is
published. Look For Feedburner
Box in the sidebar.

To Part II of This Tutorial >>