top of page


The Sonar RADAR, is to find any obstacle within a distance range by oscillating Ultrasonic Sensor fitted on a Stepper motor shaft.  The distance of obstacle(s) are read by the ATMEGA16 micro-controller for each step of Stepper Motor and the distance is proportionally represented as a ray on GLCD (Graphical Liquid Crystal Display).


ATMEAG16 is 40 pin Micro-controller is selected for the project, since GLCD requires more pins for its display system. ATMEAGA16 works on 1MHz default clock frequency, is heart of the system. 

GLCD (JHD12864E) display used in this project, has good viewing size of pixel size (0.48mm x 0.48 mm) and screen area (66mm X33mm approx.) with 128 x 64 pixel resolution, works on 5VDC supply. It has 20 pins, out of which 2 for power supply, another 2 for back-light LED, on extreme ends.  8 pins are used as data lines and 6 pins for control lines and two pins (3 and 18) are for contrast adjustment.  The screen is logically divided into two panes as 64X64 pixels on left side and 64X64 pixels on right side, which makes 128X64 pixels in total.  The left side pane is selected using CS1 pin and similarly right side pane is selected using CS2 pin.  The data and command to GLCD is transmitted in 8 bit format by selecting RS pin setting high/low. 


The following two functions are used to write pixels and lines as rays, on the GLCD in source code. 

GLCD_writePixel ( int x, int y ) 

GLCD_showRay ( long dist, float xstep )

Working Concept/Description:


The circuit shown below should be made on a general purpose PCB, except, Stepper Motor and Ultrasonic sensor (HC-SR04).  The Ultrasonic Sensor should be placed above the Stepper motor shaft, using proper wheel and fixing arrangement (view video), so that, the ultrasonic sensor, rotates  to a particular angle, matching to stepper motor shaft.

The ATMEAG16 continuously generates/reads signals and process them in the following order in a while loop:

1) Rotates the Stepper motor in a specified steps.

2) Sends Trigger pulse to Ultrasonic Sensor.

3) Reads the Echo pulse timing

4) Calculates the distance.

5) Draws a line (ray) proportional to the distance.

6) Once the motor rotates required number of steps, then, it rotates in opposite direction, which makes oscillations of ultrasonic sensor.


The DC power supply (8V to 12V) is connected to Stepper motor driver. A 5VDC is derived from the same board, which is used as power supply for micro-controller, ultrasonic sensor and GLCD.  In case, the board does not have the 5VDC output, then use separate 5VDC supply through IC 7805.

Full circuit-diagram is available below:


​Initial Setup and Usage:


After assembling the circuit on a PCB, connect 8V to 12V DC power supply to the stepper motor control board and switch ON the power switch SW_1  Then load/burn the SonarRadar.hex file to the Micro-controller (ATMEGA16) using AVR programmer.  You may connect Stepper motor, Ultrasonic sensor and GLCD before or after writing HEX file to ATMEGA16.


Once you upload and switch ON the power supply to the circuit board, two types of triangular patterns will be displayed for a while, which is a self-test for the GLCD,  then the radar system starts. 


Then, the stepper motor rotates with fixed steps, which changes the angle of ultrasonic sensor direction, for each step.  The ATMEGA16, reads the distance using ultrasonic sensor at that angle and a line is drawn like a ray on the GLCD proportional to the calculated distance.

In case, the stepper motor is not rotating to the required direction, then change the input and/or output connections of the stepper motor, until it rotates to match the direction of rays drawn on the GLCD.




The code is developed using C language and compiled using AVR studio 4. The code may be uploaded/ written to ATMEGA16 microcontroller (MCU) using any suitable AVR programmer through ISP port as shown in the circuit.


All the Variables and functions are named for easy identification of purpose using prefix name for easy identification of the controlling component


The user define variables are defined initially in the SonarRadar.C file like,

#define STEPPER_DELAY  25  // delay to settle the stepper
#define STEPPER_STEPS 3   // number of step signals sent to stepper driver

So, the value may be varied as per requirement and recompile using AVRstudio4  (or next version) and upload to ATMEGA16.



click the link / attachment to download the file and rename as SonarRadar.HEX , then upload to ATMEAGA16 using any suitable AVR programmer.

For source code (in C-language), (SonarRadar.C) please send message through contact formThe code will be sent to your e-mail.


Knowing is not enough; we must apply         Willing is not enough; we must do

– johaan wolfgang von goethe

bottom of page