Avr interfacing a switch

In this tutorial we check how to interface a push button to an Atmega8.

Here we will connect an external button to give input to a AVR. Button is connected to 5v if button pressed then delay of led lights changes if released then.here the program is configured in such a way that one pin B1 of Port B is configured as input and pin B0 as output.The input pin checks whether high or low is received and toggles the output pin.

Circuit Diagram



#include <avr/io.h>
#include <avr/delay.h>

int main()
	DDRB |= 1<<PINB0;
	DDRB &= ~(1<<PINB1);
	PORTB |= 1<<PINB1;
		PORTB ^= 1<<PINB0;

Use  the  same  Makefile
Change the TARGET name with the file name of the above program
Use the  commands  in  sequence

make elf

make hex

make flash

Switch in action

Happy Hacking 🙂

Avr LED Blinking

This program explains hello world LED blinking program.In this program an LED is connected through a resistor to PINB0.

#include <avr/io.h>
#include <avr/delay.h>

int main()
	DDRB |= 1<<PINB0;
		PORTB |= 1<<PINB0;
		PORTB &= ~(1<<PINB0);

The above program makes PINB0 blink with 100ms delay.
Compile and upload the hex file.You can use the blow make file for the whole process

CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
AVRDUDE = avrdude
REMOVE = rm -f

MCU =atmega8

TARGET = blink

AVRDUDE_PORT = /dev/parport0 

	$(CC) -mmcu=$(MCU) -Os -o $(TARGET).elf $(SRC)
	$(OBJCOPY) -j .text -j .data -O ihex  $(TARGET).elf $(TARGET).hex
	$(REMOVE) $(TARGET).hex $(TARGET).elf $(TARGET).c~

When your program name changes change name of the TARGET variable in Makefile.
Use the commands in sequence

make elf

make hex

make flash

HelloWorld in action

Happy Hacking 🙂

DIY Avr Parallel port programmer


There are several ways to wire the parallel port when you make a parallel port programmer.Am using the programmer in Linux along with avr-gcc and avrdude. Am using Atmega8 uc.

First install necessary development tools

sudo  apt-get install gcc-avr avr-libc gdb-avr avrdude

Now we need to create a cable to go between the LPT port on your PC and the AVR micro-controller

DB25 Male AVR
Pin 1 SCK
Pin 2 MOSI
Pin 11 MISO
Pin 16 RESET
Pin 21 GND

In all  variations of the the programmer, pins 18-25 are ground pins., bent these pins at right angles and soldered them all together.The data pins (1,2) should have a 1k or 330 ohms resistor in line, this is to stop you from killing either your LPT port, AVR, or both.

Now the Hardware Part connect the wires from parallel port exactly as given below.


For testing no need on crystal etc..Give 5v Vcc to Pin 7 and GND to pin 8.Now issue this command on terminal

sudo avrdude -p m8 -P /dev/parport0 -c dapa

you should receive this…

avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9307
avrdude: safemode: Fuses OK
avrdude done.  Thank you.

If you receive

avrdude: AVR device not responding
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

Crosscheck your connections the programmer is not identifying the controller

Screenshot from 2013-07-07 14_36_02

Happy Hacking 🙂

Fixing arduino stk500_recv(): programmer is not responding error

Screenshot from 2012-12-13 12:19:59

avrdude: stk500_recv(): programmer is not responding

In Debian squeeze and Ubuntu you may get an error like this while trying to upload your program…..To fix this error

First install arduino software with all its dependencies from the package manager

sudo apt-get install arduino arduino-core

Next, we’ll get a compatible (2.2pre2-3 or newer) version of librxrt-java to allow Java to handle the I/O (rx/rt);

you can check the files at this link


Now download the file

wget http://ftp.debian.org/debian/pool/main/r/rxtx/librxtx-java_2.2pre2-11_i386.deb
sudo  dpkg  -i  librxtx-java_2.2pre2-11_i386.deb

Now add yourself to the ‘dialout’ group:

sudo adduser `whoami` dialout

and log out and log back in, or reboot.  This is necessary for access to the serial (USB) port.

download the Arduino software, with it’s recent 1.0 release, from the Arduino.cc website.

We extract that software, enter the folder, and run the software:

tar -xvzf  arduino-1.0-linux.tgz
cd arduino-1.0/

Plug in your Arduino board via USB to your computer, wait a few seconds to register the new device, and again launch the Arduino software:


Go to the Tools menu, Board submenu, and select whatever your board is
Finally, again click the Tools menu, Serial Port submenu, and select correct device.

Now try uploading….. 🙂
Happy Hacking 🙂