Sunday, November 30, 2008

4x4 Matrix Key-board Interfacing with ATmega32

Hi guys,
Here is a project for beginners to interface a 16-key (4x4) keypad with ATmega32 using 8-pins i.e. one port of the microcontroller. This is useful particularly where we need more keys but don't want to spend more uC pins for interfacing.
The 4x4 keypad is a standard one available in the market. I've used here one from my earlier project. The LED shown in the schematic is just extra, which can be used anyway you like.
Here, the mega32 reads the code of key pressed and sends relevant character to display on LCD 2nd line. The first line displays 'WELCOME' all the time.

The figure below shows ISIS Proteus Simulation of this code:

Source Code (AVR-GCC, winAVR, AVRStudio format)
Proteus Simulation model
Source Code (CodeVision AVR format)
Source Code with 4-bit LCD Implementation (ICCAVR)
Source Code (ICCAVR) with Schematic on Google Docs


Sunday, November 23, 2008

Simple PWM DC motor control using MOSFET H-Bridge with AVR ATmega8

Hi friends,
here is a very simple project of controlling a small DC-motor (taken from an old personal cassette player) with ATmega8. The ATmega8 is having three PWM channels, out of which two are used here. PWM waveforms are fed to MOSFET (RFD3055) H-bridge.
Here, direction is controlled using a two-position toggle switch and speed of the motor is controlled by two push-buttons, one for increasing the speed and other for reducing.
The schematic is geiven here (click on the image to enlarge):

When switch SW1 is closed, OC1A channel is active which will feed the PWM signal to Q1 & Q4 MOSFETs. The OC1B pin will remain low keeping the Q3 & Q2 in OFF condition. When SW1 is toggled to open position, OC1A pin will become low, making Q1 & Q4 OFF and OC1B will feed the PWM signal to Q3 & Q2, resulting in the change in the direction of current flow hrough motor. Hence, motor rotation direction will change.
The speed is controlled by Push-buttons S2 & S3. Pressing S2 will increase the speed in fixed steps. Similarly, pressing S3 will reduce the speed in fixed steps.

The closer look to the motor and the circuit:

Here on the bread-board, I've used two push-buttons but the direction control switch is replaced by a small wire which was connected to ground or kept open for changing the direction (since I was not having the toggle switch in stock at the moment). The bread-board also includes 6-pin In-System Programming connector which is not shown in the schematic.

(The InSystemProgramming (ISP) connector is shown in my earlier posts, hence omitted here!! But, if you are new to ISP, refer to my post DIY AVR Programmers to make one yourself!!)

The schematic and code for this PWM motor control can be downloaded from here:

Schematic & Code on Google Docs
Source code in CodeVision format (C file)

Download datasheet: RFD3055


Monday, October 20, 2008

8-Channel ADC Project with ATmega32

Hi friends,
here is a small project of Analog to Digital Converter using ATmega32 which is having on-chip 8-channel ADC.
The circuit also consists of an intelligent 16x2 LCD for displaying the value of the voltage applied at each channel. There is also a push-button to scroll throgh the different channels. The schematic is as shown in the figure:

When powered on, the LCD displays"ADC Testing.." on the first line and the value of the voltage applied at the channel0 on the second line. When the push-button is pressed, the second line displays the value of channel1. Like-wise, all the channels can be checked one-by-one by pressing the push-button. The channel count will roll back to channel0 after going to channel7.

The displays shown in the pictures on top show values at channel0 and channel1. Here a AA battery was connected to channel0 and the channel1 was connected with the +5v supply.
A 9-pin connector is used for ADC, 8 ADC channel pins and 1 ground pin. (the values displayed on LCD will fluctuate for a channel if nothing is connected to that channel)

The software is created in C using ImageCraft ICCAVR compiler.
The Schematic and code for this project can be downloaded here:

Download Schematic and Code
Download HEX file


Thursday, October 9, 2008

Home-made Double Layer ATmega32 PCB for RS232/RS422 Communication testing

Hi guys,
after making my single layer starter's kit M32_Card, I was looking for making a double layer M32 PCB at home. So, here is my attempt to make it. Well, it didn't turn out to be as difficult as I had thought it to be earlier. I had to dump one PCB before making this one as the top-layer routine was not solder-friendly!!

I've made this one mainly for an application where RS232 & RS422 testing was required. It uses MAX232 & MAX488 ICs from for those serial communication. Selection between RS232 & RS422 is through jumpers. The board is using ATmega32 controller, just like my single layer pcb. It also has 4x4 matrix keyboard, an LCD interface, ADC connector, SPI connector (for In System Programming), a reset switch and an LED for beginner's programming. It operates with the standard 12v DC adapter.

Here is the schematic (click on the image to enlarge):

There is a small mistake here in the schematic, the RX/TX pin connections in the RS232 connector are swapped, which I found while testing the PCB. So, I had to correct it by cutting those two tracks and placing jumpers. After the correction, the communication with PC was established. The schematic is similar to the M32_Card, accept that I've removed the RTC DS1307 and placed the MAX488. Also, the individual push buttons are replaced with the 16 key matrix key-board.
Click here to get more info and for downloading code to interface the 4x4 matrix keyboard shown here

The PCB etching is done with Ferric Chloride. In making the double layer PCB, as I don't have any PTH (printed through holes) facility, I've put small pieces of single core wire into the holes and soldered both sides. Check out the top and bottom layers here

If you have an application where the circuit can not be contained in a single layer, a home-made double layer PCB is worth a try!!


Friday, October 3, 2008

Thermometer using DS1621 and Nokia 3310 LCD interfaced with ATmega8

Hi friends,
in my last post I had discussed Nokia 3310 LCD interfacing with AVR ATmega8. It's really fun to work with this LCD.

Now, here I'm presenting one application with the same LCD: Designing a thermometer using DS1621 temperature sensor IC. DS1621 is 8-pin sensor from Maxim, with temp range of -55 to +125 degree C, which can be interfaced with microcontroller over two-wire serial i2c bus. It has operating voltage range from 2.7 to 5.5v. I'm operating it here at 3.3v, same as the one driving the LCD and ATmega8. DS1621 doesn't require any external components to measure temperature. It has got continuous or one-shot temperature reading capability to save power.
Check out the schematic:

Here is the Proteus ISIS simulation result:

I'm using here LM317 for getting 3.3v supply, any 3.3v rgulator can be used to replace it. The LED is only for checking the health of the circuit incase nothing comes up on display. The circuit is programmed to update temperature appx. every second.

I've taken help of LFG application for generating different sizes of fonts for the LCD, thanks o the author M.Ebrahimy. The application can be downloaded from here:
LCD Font Generator

I've created library functions for DS1621 interface with AVR using ICCAVR compiler. This functions can be used with i2c base routines discussed in my earlier posts. You can download the project source code here.

HEX file
Source code (including the 3310 & DS1621 Libraries)
Proteus Simulation Model

(Do you wanna use this HEX file but don't want my name on the display?? Well, just learn how to play with hex file from intel HEX-file tutorial, find ascii characters of my name in the hex file and replace them with yours!!)

Download Datasheets:
1. DS1621
2. ATmega8

Contact: ccd@dharmanitech.com

Monday, September 22, 2008

NOKIA 3310 LCD interfacing with ATmega8

Hi friends,
using graphic LCD in a project gives itreally a good look and flexibility of displaying different characters and shapes. But, the graphic LCDs are quite costly.
The NOKIA 3310 LCD provides a really low-cost solution to add a small graphic display into your project and also good for learning purpose. The LCD is SPI bus compatible, saving many pins for other uses. It operates at 3.3v.

Here is a small circuit for interfacing the 3310 LCD with AVR microcontroller ATmega8. The schematic includes LCD connection with SPI port of ATmega8 with other connections required by LCD. The 3.3v is generated using adjustable voltage regulator LM317 (I was not having any 3.3v regulator at the moment). An LED is also connected with microcontroller just for making sure that the controller is working, particularly when you don't see anything on the display!

Here is the schematic and the pin details of the LCD:

The connector of LCD is 'touch' type. So, I made a small connecor PCB with tracks touching to the pins of LCD. The pcb was pasted at backside of LCD using cello tapes as shown in the back-view image

Here is a testing with Proteus ISIS Simulation:

The program routines are written in C with ICCAVR compiler. I've created a library for this display. The low-cost, easy availability has made me relly like this display.
I'm going to use it for
doing other stuffs, too!

3310 Library (ICCAVR)
3310 Library (AVR-GCC, winAVR, AVRStudio)
3310 project (CodeVision AVR)
Proteus Simulation Model (Simulation was done with CodeVision AVR Hex file)

Check out my thermometer project with this display:
Thermometer with Nokia3310

Download datasheets:
1. ATmega8
2. PCD8544 - nokia 3310 display controller


Sunday, September 14, 2008

Using M32_Card for Data Acquisition with on-board 8 channnel ADC

Hi friends,
I'm showing here one more application of the home-made M32_Card discussed in my earlier post. The microcontroller of the card is having 8-channel, 10 bit resolution ADC which can be used for analog data acquisition. Using the hyper terminal for the selection of menu, ADC can be selected to display value of the analog voltage applied to each channel (at the 9-pin header pin; 8 ADC channels & 1 GND).
The microcontroller reads the voltage at each channel and sends the data to PC via RS232 cable. At reciving end (PC), the incoming data can be converted into excel format to store the values at regular time intervals.
As shown in the screen-shot of the hyper terminal, I had connected here the 5v Vcc to Channel 0 and an Li cell to channel 7.
The M32 can also send a time impression along with the channel data using the on-board RTC DS1307 to record the voltage variation with time.

The project source code files can be downloaded from here:
Download Source Code


Wednesday, September 3, 2008

DIY AVR Programmers

Hi guys,
for those who are trying to make AVR kit at home, an AVR programmer which can be simple to make will be really useful, as it'll avoid buying the programmer!! Here I'm giving a few webpage links on how to make a programmers yourself.

- Here is a simple AVR serial programmer, works with PC serial port, easy to make:

For complete info check out the webpage:
AVR Serial programmer from Extremeelectronics.co.in

- For using the serial programmer discussed above, a driver software is required to be installed in your pc. Download it from here:
PonyProg : AVR serial programmer

- If you are using a laptop which doesn't have serial port then you can buy a low-cost AVR USB programmer shown in the figure. Visit this webpage for buying it:

Here is one more option for buying a cheap USB programmer for AVR at around $15 cost:
AVR USB Programmer lite

And if you want to make an USB programmer yourself, check out here an easy to make AVR USB programmer:
DIY AVR USB Programmer

- Atmel has given a detailed document on design of In-System Programmer for AVR. It inclludes the schematic of the programmer. Download this pdf document from here:
In-System Programmer for AVR, from Atmel

- For those who like pc parallel port better, here is a page containing data on how to make a parallel port AVR programmer along with the download for the pc:
Parallel port programmer for AVR

- Here is another parallel port programmer from AVRdude:
AVRdude parallel port programmer

- One more parallel port programmer using AT90S1200 microcontroller, with schematic and the .asm file. (Note: it need a pre-programmed AT90S1200 IC). Check out more on the webpage:
Psychogenic PPI AVR Programmer

- Apart from these, some more free designs are there, you'll find them by googling!! And if you want to buy, there are plenty of them available!!!

Hope this info is useful for your project work..

Saturday, August 30, 2008

Make-Yourself ATmega32 Starter's Kit with LCD, I2C, SPI, RTC, ADC interfaces

Hi friends,
here is my home-made kit of ATmega32 microcontroller interfacing. The ATmega32 controller is rich with features like onboard 32kB in-System programmable flash, 1 KB EEPROM, 2KB SRAM, 10bit ADC (8 channel), SPI bus inteface, TWI (compatible with I2C bus) interface, an USART, analog comparator, etc. That's why I've selected it to load my kit with all those features.

This M32 card is having an LCD inteface with contrast adjustment, an RS232 port for connecting with PC, a connector for 8 analog voltage inputs to measure by ADC, a Real Time Clock IC DS1307 from maxim with battery back-up, four general purpose keys, two keys for generating interrupts and an LED.
The circuit can be powered by an easily available 12v DC adapter. The voltage regulator IC 7805 used to convert the input into regulated 5v supply.

See below the kit in powered on condition and the schematic (click to enlarge the images)

The PCB is completely home-made, using the etching technique with the Ferric Chloride chemical. If you want to know how to make a PCB yourself from your layout, visit following webpage, it's really helpful:


The schematic and layout of the M32_card shown here are prepared using EAGLE. It's a single layer board for making the home-preparation easy. Check out the bottom layer and the layouts in the pics below:

The software for the ATmega32 controller is written using imageCraft AVR compiler. The software contains code for LCD interface, use of RTC and communication with PC with RS232 port. Using the Hyper terminal in windows, the functionality of the kit can be checked, as I've mentioned in my previous post of RTC_EEPROM interface with ATmega128.
Sown below are the pics of RTC circuit in test and related screen shot of the hyper terminal while interacting with the M32_Card

Here is Proteus ISIS Simulation:

The complete source code files including new addition of ADC (check out Here) can be downloaded below.

Source code
PCB files (in PDF & EAGLE formats)LinkProteus Simulation Model



Friday, August 15, 2008

Interfacing RTC & serial EEPROM using i2c bus, with ATmega128 uC

Hi friends,
here is my experiment with i2c bus for interfacing serial EEPROM (24C256) and RTC (DS1307) using AVR microcontroller ATmega128. The circuit is also provided with an RS232 port for connecting with PC to send commands for reading/writing EEPROM or setting date/time in RTC (Click on images to enlarge them).

Communication with PC is done through Hyper Terminal. A screen shot of the message sent to PC by microcontroller immediately after power ON is shown in the figure at the left, where the user is asked to enter choice from the menu options related to EEPROM and RTC. User can store data in EEPROM, or set RTC date and time by entering them using PC keyboard.
Hyper Terminal is used with 19200 Baud, No parity, No hardware flow control settings.

When the circuit is powered on, a welcome message is displayed on the Hyper Terminal window and a menu with 9 options (0-8) is displayed (refer to the figure). The options are explained here:

0: Erase EEPROM (fills eeprom with 0xff bytes)
1: Write EEPROM (starts writing eeprom starting with 0x0000 address)
2: Read EEPROM (reads eeprom starting with 0x0000 address)
3: Write eeprom page (writes one page of eeprom at specified page number)
4: Read eeprom page (Reads one page of eeprom at specified page number)
5: Display RTC Date (Displays current date from RTC)
6: Display RTC time (Displays current time from RTC)
7: Update RTC Date (Setting new date in RTC)
8: Update RTC time (Setting new time in RTC)

The option is selected from PC keyboard. While writing to eeprom or RTC the data is entered using PC keyboard as specified by the program.

The software routines include DS1307 library, 24C256 library & I2C library along with the main function.

The code is written in C using winAVR (inside AVRStudio). The complete project folder can be downloaded here in zip format (updated on 25-April-2009, earlier it was in ICCAVR format):

Here is running simulation on Proteus ISIS (click on image to enlarge it):

Complete Source code (winAVR, AVRStudio-4 format)
Proteus Simulation Model

ATmega128DS1307FM24C256,  MAX232


(last updated on 25-April-2009)

Wednesday, August 6, 2008

opamp Precision Rectifier

Hi friends,
this is a simple opamp precision rectifier. Very useful in rectifying or making bipolar signals unipolar, specially in small signals where we cannot afford to have that 0.7v drop across the normal diode bridge rectifier.
The circuit shown here gives rectified output going only in the negative direction, as my application required it that way. But if you want rectified positive output, just reverse the direction of both the diodes and you'll get it!

Sunday, July 27, 2008

USART-to-USB converter using FT232BM chip

Hi guys,
here is an easy an popular way to start using USB in your designs without going into learning the complicated USB protocol. This circuit converts normal USART signals from any microcontroller into USB compatible signals which can be directly connected to the PC. If u r designing a circuit and u need pc interface, then this is the best way, use USB, as the RS232 ports are disappearing from PCs and laptops very fast.

This circuit is as suggested by FTDI's datasheet for the device FT232BM. It also includes an EEPROM to input your device name which will appear in PC when u connect your circuit to PC. The Tx and Rx LED indication is also provided.

Drivers for this IC are available free on FTDI's website mentioned below. The drivers create virtual serial comm ports, hence keep the USB protocol completely in background. U can program yr controller just like u r designing it for RS232 communication!!

New! (21 May 2010)

FTDI has released a RS232 to USB converter in DB9 connector package, an easiest way to migrate from RS232 to USB without any change in your PCB, you can have the footprint of DB9 female connector but place this module instead and you are USB ready!! Really cool!!!

More info: http://www.ftdichip.com

Saturday, July 26, 2008

Ring Detector for Caller ID Unit

Hi Friends,
this is an addition to the caller ID circuit of my previous post. For deciding whether call is received call or missed call, u need to monitor the ringing signal along with the off-hook detector signal, which is discussed in the last post. If the off-hook detector signal goes low (i.e. receiver lifted) before the ringing signal stops, then the call is labeled as received call, otherwise it is a missed call.
This small circuit converts the ringing signal (sine wave 90vrms) into 5v dc pulses which can be directly fed to microcontroller pin. The circuit outputs a pulse for each ring. The delay between two pulses is to be monitered and if it exceeds 4 sec, then ring is dead, hence, the call is missed call.!
Try it out..

Friday, July 25, 2008

Design Caller ID using DTMF decoder MT8870

Hi friends,
one more circuit: DTMF decoder interface for designing Caller ID Unit. It's very simple circuit using DTMF decoder MT8870 (or CM8870). As shown in the circuit, u'll receive an interrupt ( if NAND output is connected to INT of the microcontroller) whenever u receive a call or make a call and then u can use yr program to read the digits coming out of pin 11 to 14 of the MT8870. I designed the circuit with additional features like seperating received calls, missed calls, dialled numbers along with telephone directory.

Download datasheet:

To determine whether number is dialled or received, u need to know whether receiver is on-hook or off-hook. following simple circuit will give u that indication:

I had used microcontroller 8951 with16x2 LCD and Dallas nvRAM for storing numbers and names. The code is in assembly language. It's really easy to make this one with lot of variations.

Check out my next post on telephone ring detector to check whether the call is received call or missed call.