Motor Driver Test on an Arduino


There are prolly a billion tutorials for this and mine is prolly not the best but I am writing it anyways. Here is a piece of arduino code that can be used to test if your motor driver is connected correctly.


I am assuming that the motor driver L293D or L298 has been connected such that the Enable pin is high by default i.e. connected to VCC. In the next tutorial I will put up a circuit like how I think should be done. None the less, the direction 1 pin is connected to 12 pin of the Arduino and direction 2 pin is connected to 13 pin of the arduino.

The Code

The code is as follows:

*	\file		motorTest.ino
*	\author 	Inderpreet Singh (
* 	\license	GPL2(see license.txt)
*	\section 	Description
*	\section	HISTORY
*	v1.0
*        \description  This arduino firmware is used to test L293D motor Drivers
*                      Change the Motor driver pins at the beginning and the rest
*                      will work automatically.
* I put a lot of time and effort into our project and hence this copyright 
* notice ensures that people contribute as well as each contribution is 
* acknowledged. Please retain this original notice and if you make changes
* please document them along with your details.
* The latest copy of this project/library can be found at: 
// ----------------------------------------------------------------------------
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// L298D Pins
int D1=12
int D2=13
//int D3=
//int D4=
//int E1=
//int E2=

// Direction Routines
void motorStop(void){

void motor1CK(int t){
  digitalWrite(D1, LOW);
  digitalWrite(D2, HIGH);

void motor1ACK(int t){
  digitalWrite(D2, LOW);
  digitalWrite(D1, HIGH);
// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(D1, OUTPUT);     
  pinMode(D2, OUTPUT);

// the loop routine runs over and over again forever:
void loop() {
  motor1CK(5);               // Rotate motor Clockwise for 5 seconds
  motor1ACK(5);              // Rotate motor Anticlockwise for 5 seconds

copy and paste the code in the arduino IDE and upload. Test and lemme know.


The Poorman’s Robotics: Sensors

TSOP1738 as sensor with 55 based 38 khz Pulse generator

Sensors 101

 A sensor doesn’t necessarily mean sight. Some times a sensor is able to pick up much more information like temperature, light, color, velocity, acceleration, inclination, altitude, depth, pressure etc. Depending upon the quantity to be measured and the environment where it will be measured, the sensors will vary. The basic principle however remain the same. Balanced whetstone, conversion techniques etc all are used even in the most advanced sensors. I won’t go into the history of things since I expect that my readers have already read the books. I will however explain some basics and assembly of sensors at a more practical level.

Continue reading “The Poorman’s Robotics: Sensors”

The Poorman’s Robotics: Power

Power pack


A robot is not necessarily a machine with arms or legs or even wheels. If the robot is a stationary machine as in case of robots like arm(welding and assembly line) robots, then the power supply is usually as simple as having transformers or SMPS etc. then using regulators for supplying the required currents.

 If however the robot is a mobile autonomous robot, then we need to consider batteries. There are various types of batteries each with their own pros and cons. eg. Lead acid batts are longer lasting but are really heavy etc. Here is some info. as taken from the robot builder’s bonanza book.


 Zinc batteries are the staple of the battery industry and are often referred to simply as “flashlight” cells. The chemical makeup of zinc batteries takes two forms: carbon zinc and zinc chloride. Carbon zinc, or “regular-duty,” batteries die out the quickest and are unsuited to robotic applications. Zinc chloride, or “heavy-duty,” batteries provide a little more power than regular carbon zinc cells and last 25 to 50 percent longer. Despite the added energy, zinc chloride batteries are also unsuitable for most robotics applications. Both carbon zinc and zinc chloride batteries can be “rejuvenated” a few times after being drained. See the section “Battery Recharging” later in the chapter for more information on recharging batteries. Zinc batteries are available in all the standard flashlight (D, C, A, AA, and AAA) and lantern battery sizes.


 Alkaline cells use a special alkaline manganese dioxide formula that lasts up to 800 percent longer than carbon zinc batteries. The actual increase in life expectancy ranges from about 300 percent to 800 percent, depending on the application. In robotics, where the batteries are driving motors, solenoids, and electronics, the average increase is a reasonable 450 to 550 percent.


When you think “rechargeable battery,” you undoubtedly think nickel-cadmium—or “Ni-Cad” for short. Ni-Cads aren’t the only battery specifically engineered to be recharged, but they are among the least expensive and easiest to get. Ni-Cads are ideal for most all robotics applications.


Nickel metal hydride (NiMH) batteries represent one of the best of the affordable rechargeable battery technologies. NiMH batteries can be recharged 400 or more times and have a low internal resistance, so they can deliver high amounts of current (read more about internal resistance and current in “Battery Ratings,” later in the chapter). Nickel metal hydride batteries are about the same size and weight as Ni-Cads, but they deliver about 50 percent more operating juice than Ni-Cads. In fact, NiMH batteries work best when they are used in very high current situations. Unlike Ni-Cads, NiMH batteries do not exhibit any memory effect, nor do they contain cadmium, a highly toxic material.

While NiMH batteries are discharging, especially at high currents, they can get quite hot. You should consider this when you place the batteries in your robot. If the NiMH pack will be pressed into high-current service, be sure it is located away from any components that may be affected by the heat. This includes any control circuitry or the microcontroller.

A lot more material is available on the internet about batteries and battery care and recharging. From my experience however this is what I have to share.

For very small and short lived projects, you might consider simply using a step down transformer and using a regulator with it. The adapter is reuable and is cheap and is easy to use and store.

For mid-sized projects with time limits, I recomend using zinc or alkaline batteries. They are cheap and easily available and give you mobility.

For long lived projects that don’t require immediate ‘put the battery on the board’, consider going for a 12V lead acid battery. They dont need frequent recharges and give you mobility more or less.

For more permanently mobile battery solutions that I used, I used rechargable Ni-MH batts. Lots of em. clubbed with regulators. I bought them in bulk and I usually have one pair in the recharger all the time cause of my usage.

Power pack
Power pack

I simply put two packs together and on a small PCB put an 7805 with the necessary components and a whole lot of connectors. And this is what I use.

The Poorman’s Robotics: The Processor

Microcontroller Module

The Processor or Controller or Control Logic

For any robotic project it is important that the working logic be flexible enough to allow changes and modifications. In order to achieve that, a microcontroller is employed and the working algorithm is programmed into it using either assembly language or C language.

 In India the most commonly available microcontroller is the 8051 and its variants. There are a lot of books out there and the internet is full of information so I wont try to explain the 8051. Google it! Also download the datasheet if you can.

Microcontroller Module
Microcontroller Module

 I made a module for myself that I could reuse since I could have numerous project that needed a controller and I was not going to start putting the crystal and reset ckts again and again. Re use means that after I make a project, I take pics and videos and disassemble it and head for the next project.

 I made the circuit on a general purpose veroboard and the ports can be attached using burg-strip connector as shown. I have used a 40-pin ZIF socket to avoid damaging the controller in handlling.

The Schematic is not necessary here since there is only a crystal and reset circuit attached to it. The controller and connectors should suit your style of working and needs.

Another good example is the arduino. The arduino is an open source, AVR based prototyping platform that has become a standard on its own. The location of the connectors and connections have been fixed and all supporting boards or shield boards being produced follow the same pattern to allow compatibility and standardization.

The arduino Board
The arduino Board

At the end of the day it is your choice but I really suggest to get started, work with existing patterns. If you plan to use an external programmer as I did, a ZIF socket will be a good idea. If you have not thought about exactly how flexible you want to make your design or what else you might do then focus on the project at hand. Its all a learning exercise.

The Poorman’s Robotics: Introduction

I am doing a repeat of a a series I published on my site a few years back. This series most of the topics of DIY robots and related topics. Feedback is encouraged because I need to know what everyone wants to read. 🙂


The poorman’s robotics kit is the basic modules approach for a hoybist or student to start with robotics projects. In India resources like Multilayer PCBs, high-end micrcontrollers etc are not available everywhere. Lego Mindstorms does provide robotics materials but in India, instruments like CROs and microcontrollers are not very common.

So what is the purpose of this documents?

The answer is that when a student or interested individual goes to buy things for experimentation, he will know exactly what they are getting into and what are the basic components needed. I am not yet commercially selling such kits to individuals, but different versions of this kit are available to students that undergo training by us. I am not promising support to anyone, but the email ID of my friends and myself are given in the contacts section so you may email us doubts and questions and we will try our best to help you out.

I was involved briefly in some training projects in Pune, India. The students did a great jobm but while they were leaving, I could not help but think that some activities become restricted due to lack of resources like programmers. Since I have been experimenting with electronics for the past 15 years(since my 3rd grade in 1993) I have tried to add some cost effective solutions to robotics design and some of my own ideas on how to hack-up toys etc to get the electronics and mechanical parts needed. Where to find all that is in your hands now.

The Building Blocks

I wont start with table-top kits and all that because I assume you have worked with them at your colleges.

Q. Why do we have table-top kits since they are not the hardware that are going to be used in actual robots?

A. It is correct that the standard ‘kits’ are not going to be used in practical projects. These are not exactly developement tools, but rather learning tools. Imagine that you have to make a simple robot. After you freeze your specifications, you assemble your hardware and then write your software. When you put them together and they dont work where is the problem? Since both hardware and software are untested, how do you know where to start debugging? If however, you have a standard kit that you are sure works, then you can test the software and if the same working workware does not work on your hardware, you know where the fault is.

For any basic practical robotics experiment there are some fundamental modules necessary. These being:

  • Processor or Controller or Control Logic: This is the brain of your robot and has the algorithm on it. It is responsible for controlling the activities of the robot like reading from sensors, decision making and controlling the actuators etc.
  • The Power Supply: Other than the obvious, the power supply is expected to produced all required voltage levels and regulated/unregulated outputs that may be mutually isolated.
  • Sensors: The eyes of the robot- For any real-time task, the robot need inputs that may be regarding objects, temperature, voltage levels and even position. Advanced robots include electronic compases and gyros and accelerometers etc.
  • The Chassis: If your robot is needed to move around, it needs wheels. If it is an arm robot, then it needs the physical arm joints etc. A physical structure that will include the wheels, grippers, motors, gears etc.
  • Drivers: The Processor or Controller or Control Logic usually cannot supply enough to directly run motors etc. So transistors or FETS etc are used to drive them.
  • Programmer: To download the algorithm to microcontroller, or ROM or CPLD or FPGA.
  • Diagnostic Tools: Simple circuit that can be very useful
  • Communications: Sometime there is a need to connect to a robot.

I have made this kit in terms of modules. The modules can be connected to each other in different ways for different robots. I will be covering these in this series.

Roybot Strolls again.

OK this is not a boxy kinda entry. I made this little robot a few years back and I kinda lost its control hardware plus software when I was traveling through India. Well since I am in the process of readying a new Bot, so I thought it would be nice to give my old bot a little brain for now.
RoyBot Stroll Video on YouTube

Its nothing great I know, but its using 8 2200mAh 1.2V cells so its kinda power hungry but still running for like 40 minutes.
I called it ‘RoyBot Mark 1’. Now on to my Iron Man Project…

Design Of Autonomous Robot: The Birth Of Mark 1 :)


OK im not putting up the exact plans on how to make this robot, but I am putting up the important information and some points where to take care. I finally got this robot up and running but there is a lot of room for improvement. It took me a long time to actually get this together andworking because I have the habbit of exploring and documenting every problem that I come across. In the end the desire to ‘finish this thing on and move on’ was what actually helped me complete the robot to this extent.

I dealt with the whole thing in phases and thats how I am documenting my work. My official presentation and report are not going to be available online. So for those who either attended my lecture, demonstration or training session, you can contact me regarding help but no spoon-feeds.

Phase 1: Chassis Selection

I started with deciding the chassis for my robot. There are so many good options for the robot chassis. I could have made one myself by using aluminium or wood like my chassis design project, but I found a ready made chassis with a gearbox and DC motors. I took a small crane toy from the market and took out the plow extention and left the necessary plastic on the top part. The bottom and gearbox I left intact because skid-style steering is my favourite design. I thought I could use all four wheels but I did run into some problems later on when I finally tested its movement.

 The Image on the right is the image of the Basic Chassis with the Battery Mounted where the operator was sitting.

I had already decided that I was gonna use TSOP1738 sensors for the right and left sensors. I was planning to use ATMEGA8L for the controller so I had an inbuilt ADC to play with. This was a good idea for a more later stage. I will talk about this later. So with the help of an ADC I could easily interface a Sharp GP2D sensor.

But right now I needed to put it on a mobile platform. Instead of using an adaptor to power the robot and just do a “proof of concept” kind of thing, I wanted to make this an actual robot with all the problems addressed. Including… the battery and regulator.

I toyed with the power supply problem a lot. I did not want to use the 7805 voltage regulator for two reasons:

  1. The 78xx series regulators clamp the output voltage to a fixed value by basically dissipating extra energy as heat hence have lower efficiency.
  2. They require greater input voltages so as to provide regulated voltages e.g. for 7805 to produce 5v regulated, it requires an input of 7v to operate properly.

I wanted to use rechargable Ni-MH battery packs- each of 1.2v * 4 = 4.8v. With two such battery packs, I had a number of options.

  1. I could use one battery pack for the controller and one for the TSOP and motors. But this meant that I had a maximum of 4.8v at any given time. Hence I could not use a motor driver IC like L293 or L298D. I could only use an H-Bridge formed out of transistors or MosFETs. 
  2. I could use the battery packs in series and use a switching regulators like MAX638. These switching regulators have an efficiency of around 77%- 90%.
  3. I could simply use a 7805 with 2 battery packs.

Option 1 was a good one and I chose to go with it. The switching regulators are comparatively expensive and I was not sure about the availability. The battery packs fit in quite comfortably. So I was happy with what I had. But later on, I decided to go for option 3 because the H-Bridge transistors I used(TIP122) had their own voltage drop greater than what I had intended for the motors. So I ended up using an L298DL298D is really easy to interface with the microcontroller. The H-bridges I made out of TIP122 darlington transistors produced different voltages for the motors because the base resistances and individual temperates all accumulated upto a lot of variables. I simply did not go through all those adjustments. because this way I got a regulated 5v for the controller and the voltage I needed for the motors and also the

 I made a single PCB for a 555 based 38KHz wave generator. I made small sub PCBs in the shape that was available in between the wheels on each side.

Phase 2: The H-Bridge 

Since I had decided to use two different battery packs initially, I made 2 idenitical H-bridges from TIP122 transistors but since I was not getting the results I wanted, instead of going through with MOS-FET based H-bridges I went for the L298D. I did experiment with the transistorised h-bridges, but using them was causing me loose the same amount power for which I did not want to use a regulator. With the L298D I was free to concentrate my efforts on other things.

Phase 3: The Controller


I had planned to use the ATMEGA8L for the final robot but I wanted to do my intial testing with a controller that I was faimliar with. I suggest some of my students use a PC parallel port and it is a really good idea as well because you are programming in C and the cost goes down since you are not spending on a microcontroller or a programmer.

I did most of my design work using a prototyping AT89C52 card I had made for myself. I had made my own Microcontroller programmer for the AT89C52 thanks to resources from the internet. Instead of programming in assembly that would become useless as soon as I changed controllers, I chose to write test programs in embedded C and used the trial version of Keil microvision 3 tool.

So now I had a controller(with PCB) and programmer and a complier to easily do my software work. I made myself another PCB with a CPLD and an ATMEGA8L but more on that in some different project.

Phase 4:

Basic Tests I started basic testing by writing simple programs like flexing out the motors. Then I added the sensors and everything worked fine. The videos and pictures are available. Since I had no sensors in the front, I needed to add one. The intial tests went well and the robot worked as far as I can say. Neither the regulator nor the L298D heated as I expected and all tests went well. My mother was exceptionally happy to see the little toy started to run around everytime she tried to pick it up.

Phase 5: The obstacle avoidance robot

The purpose of this project was to design a multi purpose robotic platform where I and others could easily test algorithms as well as test sub modules like battery monitor etc. The robot can be converted into a line follower, a collision avoidance system, a color finder, a photovore, a micromouse or a wall follower. I wrote a simple code that would make this robot a basic obstacle avoidance system. I am not interested in following up with more experiments on this model though. Extra Features I designed some extra feature that I am afraid I will never use. The most significant one is the opto interrupters. Opto Interrupters: I cut small slots in the front wheels and installed opto-interrupters so that I could count the number of steps each side took. This way i could take care of course correction in case one of the two motors turned fasted than the other. I dont want to experiment more because I want to start work on a newer chassis which employs the acerman steering.