June 8, 2009


After a long struggle with never ending commands and long lists of packages, not forgetting some tedious circuitry, we finally managed to blink an LED using an Atmel ATMEGA16 microcontroller. I’ll explain what we did in some simple steps.
1. Building a programmer (hardware) to program the Microcontroller( MuC )

2. Installation of necessary packages, for compiling and burning the MuC.

3. Burning the MuC

4. Sample program

All the installation and applications are  based on GNU Linux Debian / Ubuntu . Please bear with it.

I. Building a Programmer.
We need a hardware circuit to interface the MuC with a PC via its parallel port so that we can transfer our program from the latter to the former. We have used a circuit compatible with Uisp programming application. The circuit is available here.

The hardware on the bottom right hand side is that for supplying Vcc.
Pin 9 is RESET (active low) and so it is always kept HIGH by connecting it to Vcc via 10k resistor as shown.
Make sure that the GND of Parallel port and that of Power supply are shorted.
Q1 is 4MHz crystal for clock.

II. Packages
Several packages/libraries need to be installed on linux for compiling our program(specifically for MuC) as well as uploading it onto the microcontroller’s (flash) memory using the programmer we discussed above. They are build-essential, avr-libc, gcc-avr, binutils, uisp. To install these packages, type as root user :

#apt-get install  build-essential avr-libc  gcc-avr  binutils uisp

You may skip rest of this section if the above command worked fine!!!

If any error creeps up showing invalid repositories or something similar, we may need to update the repositories file of aptitude (apt). The new repositories to be added for Debian are:

deb http://http.us.debian.org/debian testing main
deb http://www.uk.debian.org/debian stable main contrib non-free

These are to be added/written to the file sources.list in the directory.


( Check whether the current repositories of your apt have the packages  or not, even if your distro is/is not Debian/ Ubuntu. And if needed you may have to find out the necessary ones from the internet )

With our new repositories in place, we need to update our apt with this command:

#apt-get update

If you end up with an error indicating wrong key or something like below


Reading package lists… Done
W: There is no public key available for the following key IDs:

try the following commands :

#gpg –keyserver pgpkeys.mit.edu –recv-key your-key

/* in this particular case, ‘your key’ is 9AA38DCD55BE302B */

#apt-key add /root/.gnupg/pubring.gpg

The second command should give a result OK. Else try this one also.

#gpg –export your key | apt-key add –

A possible screen-shot:

#gpg –keyserver pgpkeys.mit.edu –recv-key 9AA38DCD55BE302B

gpg: requesting key 55BE302B from hkp server pgpkeys.mit.edu
gpg: key 55BE302B: public key “Debian Archive Automatic Signing Key (5.0/lenny) <ftpmaster@debian.org>” imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)

# apt-key add /root/.gnupg/pubring.gpg

So we are done with updating apt-get. Now the next step is installing the packages. Retype the first command of this section.

The installation part is done!

III. Burning the MuC
Several commands are listed below, which will compile a file ‘a.c’ for running on a MuC, create ‘a.hex’ and burn it onto the MuC. They are as follows

To compile and make a.out :
#avr-gcc -mmcu=atmega16 -Os a.c

To convert it into a.hex
#avr-objcopy -j .text -j .data -O ihex a.out a.hex

To detect MuC

#uisp -dprog=dapa .

To erase any existing program:
#uisp -dprog=dapa -dlpt=0x378 –erase

To load it into MuC
#uisp -dprog=dapa -dlpt=0x378 –upload –verify if=a.hex

#uisp -dprog=dapa
Atmel AVR ATmega16 is found

#uisp -dprog=dapa -dlpt=0x378 –erase
Atmel AVR ATmega16 is found.
Erasing device …
Reinitializing device
Atmel AVR ATmega16 is found.

# uisp -dprog=dapa -dlpt=0x378 –upload –verify if=a.hex
Atmel AVR ATmega16 is found.
Uploading: flash
Verifying: flash

IV.Sample Program

Here is a sample program for testing the MuC, The LED to be blinked has to be connected as per the diagram given above, on the 19th PIN. Remember, this is just a sample program. So don’t jump into conclusions straight away if you are new to programming a MuC

#include <avr/io.h>
#define LED PD5

int main(void)
/ * enable PD5 as output */

while (1) {
PORTD=(1<<LED); /* LED ON */
PORTD=(0<<LED); /* LED OFF */
return 0;

Note : It is two separate ‘-‘ characters where it appears to be one long ‘-‘ eg: ‘–erase’ is actually – – erase without spaces. ( wordpress magic it seems! )


January 16, 2009


Filed under: Gadgets,Projects — Rohith @ 11:44 pm
Tags: ,

At last we made a robot!

Here is our effort.

Theme :

Basically, you can think of this as a remote controlled toy car, on three wheels. You can control the two backwheels using your remote. The front wheel is free-rotation type. To move our robo forward, the two backwheels rotate forward, to move it left our left wheel rotates backward and our rightwheel rotates forward( imagine!) and similarly other two movements can be achieved.


Components :

To drive the two rear-wheels, we use two motors, which can be independently controlled. When we supply HIGH to a motor’s red and LOW to black wire, it rotates in clockwise direction. And in anti-clockwise direction vice-versa. So in this way we control the motors.(Here HIGH is +12V of battery. LOW is zero or negative of DC battery.)

We have to control these motors using a remote control. Thats our mission. The circuitry we are going to discuss about just enables us to do that. First, transmission of data( in bits, HIGH- 1, LOW -0). This transmission is done using RF(Radio Frequency) modules- RX+TX kit. We have a transmitter and a receiver in this kit. On our remote control, we can generate a signal 10,10 or 10,01 or so on with switches( HIGH- LOW /ON-OFF thingy!). Then we have to transmit this signal to the robot’s motors. The way it is done is that, its first encoded (using an encoder IC)and then fed into the transmitter of our remote, which transmits the signal. This encoded signal is received by a receiver(on the robot), which is fed into a decoder IC and the output is at its four o/p pins. So, say if we give a 1001(HIGH LOW LOW HIGH ) using the remote-control, we should get 1001 at the o/p pins of the decoder IC of the robot. This information is then used to drive its motors accordingly. The table below gives what signals we have to give to both the motors (Left- L, Right- R) simultaneously to control the direction.



10 10


10 01


01 10


01 01


But these motors need 9-12V supply, whereas our decoder only provides 5V at its o/p. So to drive the motors,instead of providing the decoder output directly to the motors, we use another IC( L293NE) . The working is discussed below.

List :

1. Chasis for the bot (Try to make one !)2. Wheels(2) 3. One Free wheel in front( Castor wheel) 4. Breadboard 5. RF modules( RX + TX kit) 6. Encoder +Decoder ICs (HT12D, HT12E ) 7. L293NE 8. 7805 Voltage Regulator (for +5V Vcc) 9. Resistors 10.Geared Motors (60 RPM) 11. Switches 12. PCB (or Option 4 or Both) 13. Single stranded Wires

Circuit + Working :


The above diagram is a simplified flowchart of our transmitter receiver setup. Now we’ll explain the circuit diagram.



So,in simple words, if we are to supply a 1001 to S1,S2, S3,S4 in the transmitter , we should get it at D1,D2, D3,D4 at the receiver.

Note : The Input and output pins of the transmitter and receiver ICs are Active Low type

Next step is driving the motors. We could connect D1 D2 to the first motor (10) and D3 D4 to the second motor(01). But we can get only a maximum of 5V from the o/p pins(D1-D4), whilst the motors require atleast 9V-12V for optimum performance. So to negotiate this, we use a motor driving IC L293NE.

l293pinoutIt works like this. When we supply a HIGH at Input1, we get the voltage Vc ( pin8 ) supplied by the battery, at the Output1(and zero for LOW i/p). And similarly at the other three inputs as well. For this, we have to keep the ‘Chip Inhibit’ (or Enable) labelled pins 1 & 9 HIGH.

Now, we connect D1 to Input1 and D2 to Input2. (1,0 here). When we make Pin 1 HIGH, we get the voltage Vc(9V or 12V, as supplied) at Output1 and zero at Output 2. These two signals can drive one motor. Thus we can drive two motors using one L293.

So, if all goes well, we should be able to drive our robot using our remote control.



Under Rs 1300/- or $30( Robokits)

PS : 1. BRAINs stands for Back Row Association Inc.

2. Any(if) reader who wishes to implement this circuit is expected to have atleast basic knowledge in electronics and ICs.

Create a free website or blog at WordPress.com.