Infrared and Ultrasonic Scanner (ATMEGA32 microcontroller)
Author: Matt Meerian

Downloads are at the bottom of the page

scanner project

What it does:
This project scans a 180 degree area from about 6 to 21 inches (15cm to 53cm) away and displays the information on a color LCD

How it does it:
An infrared distance sensor from Sharp and an ultrasonic sensor from MaxBotix.

Why it does it:
'Seemed like a good idea.

This project is a short range, infrared and ultrasonic scanner that uses a standard hobby servo to move the sensors and a color LCD screen to display the information from the sensors.  The information displayed on the LCD is an overhead view of the scanning area, with increments of distance from the sensors.  
LCD screen

Above is a photo of the LCD in its scanning state.   Starting at the bottom, the "046" number is the raw value from the ADC on the ATMEGA32.  The "US" lets the user know an ultrasonic scan is taking place.  The square directly above "US" represents the scanner (origin) in an overhead view.  The semicircles radiating out from the origin represent a distances from the sensor.  The big blue squares represent objects placed around the sensor.  The servo starts with the sensor looking to the right.  About every half a second, the servo moves the sensor a small amount to the left and the sensor takes another reading.    Once the sensor is looking to the left side, the servo will start moving the sensor back to the right side.  The only difference this time is the targets will be represented by red squares.  (not on the photo above)  When the right hand side has been reached, the screen is wiped clean of targets and the scan starts again.

Hardware Details:

The core of the project is the ATMEGA32 microcontroller from Atmel.  It controls the servo, gathers information from the sensors and places the information on the LCD screen.  There is 32K of flash in the microcontroller and the software uses about 13K of that.  Since the LCD uses a maximum of 3.3V, the microcontroller is run at 3.3V.

Like many applications of today, the schematic has parts that are run at different voltages.  The hobby servo, infrared sensor, and ultrasonic sensor all run at 5V.  This does not cause a problem since the output of the sensors is in the 0 to 3.3V range and the servo seems to not have any problems with being driven at 3.3V, even though its power pin is at 5V.  See the link at the bottom of the page to download the schematic.

The circuit board I used in the project is a heavily modified previous project board.  As you can see from the photo, there was heavy use of mod (wire-wrap) wire to create the appropriate connections. 

circuit board

Can you find the ATMEGA32???
(it's near the center of the photo, you can see the top, left side (and center) clearly)

The LCD is a Nokia cell phone knock-off bought from  They even provide a carrier board with a 0.1” header that makes assembly really easy.  The carrier board also boosts up the 3.3V supply to run the LED based backlight.  The LCD size is 1.2” x 1.2” so it is very small, it can display 4096 colors, but I limit that to 256 colors for an easier (and speedier) interface to the microcontroller.

The hobby servo that moves the sensors is a Hitec; model number HS-300 (RCD Apollo 5).  This is a relatively inexpensive servo that I have used in various projects through the years.  The signal used to control the servo is a 1mS to 2mS pulse about every 50mS.  There is a great deal of information on how to control a servo found on the Internet.

The front panel was created using software from Front Panel Express.  (  They also machined the front panel.  I have used their services in the past and have been very pleased with the results.  They allow the hobbyist to make a very professional looking front panel.  The only minor complaint I have is it takes about 3 weeks to get a front panel.

front panel screen capture

Screen capture of the front panel from Front Panel Express

To make the front panel, I started with a set of calipers measuring different dimensions needed (LCD, circuit board, enclosure, etc.)  and writing the results on a piece of scratch paper.  All of the X/Y dimensions originate from the lower left hand corner of the page.  Once that I got together a reasonable looking front panel, I printed off the front panel and used an exacto knife to slice out the cutouts.  (Use cardboard backing) The different components were then inserted into the paper as best as possible and then I looked to see if there was any interference between components or between components and the enclosure.  By the time I got the finalized version, I had printed out about 5 iterations of the front panel.  See the bottom of the page to download the front panel .FPD file.  The front panel is 1.5mm thick.  This depth was used because the rubber grommet for the cabling would fit into this the best.  (Rubber grommet: McMaster-Carr part number 1061T11)  The pushbuttons and power button was used because they were parts I had on hand.  A good portion of the hardware (standoff’s, stainless steel Allen head screws, rubber grommet, etc.)  to assemble the parts onto the front was obtained from McMaster-Carr.  (  They have a huge amount of small parts. 

Front Panel Express Experience:
First of all, I would like to say that I do not have any friends or family at Front Panel Express and I have no involvement in the company other than being a customer.  I have used Front Panel Express several times in the past and this is the first time I have had any problems with my order. 

I ordered the front panel from Front Panel Express on July 13, 2006.  I couple of days later, I received a phone message saying that they had been having server problems and that my order had been received.  It usually takes Front Panel Express about 3 weeks to do a front panel.  (Using their “standard” manufacturing and shipping)  I called on August 4, 2006 to ask about the status of my order.  I was told that ordered was never received and that I should place the order again.  I place the order for a second time.  Later that evening, I get an email from them saying that my credit card information was out of date.  (Which was the problem with the first order)  So, I updated my credit card information and sent the order for the third time.  On August 8, 2006, I got a notice that a package had shipped.  (YES!)  The front panel arrived on August 14, 2006.  The front panel was perfect.  Later that week, I noticed that my credit card had been billed twice.  I called up Front Panel Express and told them that I only ordered one front panel.  They took the second charge off the credit card. 

Even though there were several problems encountered, the staff at Front Panel Express was very courteous and accommodating.  They went out of their way to make sure I was a satisfied customer.  I recommend them and plan on ordering from them in future projects.

The enclosure is from Hammond.  The part number is 1554N2GYCL.  It is a waterproof enclosure, but I’m not using it for it’s waterproof properties.  It was an enclosure I had from a previous project and it was about the size I needed for the sensor project.  Since the screws that came with the enclosure only had threads on half of the screw, (the lid that came with the enclosure was much thicker than my front panel) I used some M4 screws, 12mm in length.  (McMaster-Carr # 91292A117)  The LCD was held to the front panel by nylon female threaded standoff, 7/32” length, 4-40 screw size, McMaster-Carr part number 96110A058.  Allen head screws were used on the front panel to give the project a more professional look.

The ultrasonic sensor is from  I am pleased with the sensor because of price, small size, and the flexibility of the output.  The analog output is the one I use, every 10 milli-volts represents 1 inch, with a maximum of 2.55Volts.  The sensor also has a serial (RS232) output and a PWM output.  The range is from 6 inches to 254 inches. 

The 2YOA21 IR sensor is from Sharp.  It has a range from 10 to 80cm and has a response time of 39ms.  Again, it has a simple analog output that makes it easy to attach to an analog to digital conversion port on the ATMEGA32 microcontroller.
Both of the sensors were mounted on some scrap PCB board.  The wire I used to go to the sensors is from a computer mouse.  I figured the wire would withstand the movement from the servo for a long time.


The software for the Atmel ATMEGA32 microcontroller was written in the “C” language with AVR-GCC version 3.4.1 as the compiler.  As with many of my other projects, I used a state machine type of structure.

State 1:  Main Menu

State 10:  Infrared Scan

State 20:  Ultrasonic Scan

State 40:  Options Menu

The operation of the software is rather strait forward.  The user has an up, down and enter button.  To run an ultrasonic scan, press the down button until the ultrasonic scan line is highlighted in the main menu, and then the user presses enter.  To stop a scan, press the enter button and it will take you back to the main menu.  To go to the options menu from the main menu, scroll down on the main menu using the down button and press enter when the Options menu is highlighted.

There are several notable routines.  The first and one of most useful, is “OneLineText”, which is used to put a line of text from flash at any X/Y location of the screen.  The text color and background color can also be set by using this routine.  The “LCD_put_pixel” routine allows the user to put a pixel anywhere on the screen and specify the color at the same time.  The “scanAndDisplay” routine displays a scan in real time, while the sensor information is being received.  The code is well commented, so you can download it at the bottom of the page and get a pretty good idea of what is going on.  Enjoy!


Infrared and Ultrasonic Scanner Schematic (PDF format)
Front Panel (in Front Panel Designer version 3.3 format)
Infrared and Ultrasonic Scanner "C" Source Code (WINAVR version 3.4.1)

 As always, use at your own risk!
*All rights reserved, all wrongs deserved*

Author:  Matt Meerian
Last Modified:  January 25, 2010
Return to Home page