In this article I will describe how to interface a Ultrasonic Range Finder Module with a AVR ATmega8 microcontroller. I will provide a HEX file which you can burn into your ATmega8 directly to quickly test this whole setup.
Ultrasonic range finder modules helps find the exact distance to an object. This can have vast application in robotics.
These are more expensive than IR based obstacle detectors but the advantage is that they give accurate distance to the obstacle and also their performance is not affected by the colour of obstacle.
Ultrasonic Range Finder HC-SR04
Contains the core AVR circuit including 5v regulator, reset, ISP.
Alphanumeric LCD Module subsystem on board.
Used to interconnect the two boards. And the sensor.
To upload the program to the development board.
|5||Ultrasonic Range Finder Module|
Connect LCD Board
Please read this article on interfacing alphanumeric lcd module with AVR microcontrollers.
Connect the LCD Board with the development board using single pin f/f burg wires according to the table given below.
|LCD Board||AVR Dev Board|
|3 LED PWM||NOT CONNECTED|
|4 VCC||5V OUT (VCC)|
Fig. LCD Board and Dev Board Connected
Connect the Ultrasonic Sensor Module.
Connect the Ultrasonic Sensor Module with AVR Dev Board according to the table given below.
|Sensor||AVR Dev Board|
Connection for xBoard MINI v2.1
You can also use the xBoard MINI v2.1 development board to run this demo. The connection is same as the 28 PIN Development board with a difference that you don’t need the LCD board because xBoard MINI v2.1 has built in LCD Module. So you just need to connect the sensor module on PORTC pins and supply the module from 5 volt output pins. See the image below.
Fig. xBoard MINI and HC-SR04 Sensor
Supplying External Boards
External boards such as the LCD Board and Ultrasonic Range Finder Module requires 5v supply. You can easily supply them from the extra power output from the development board. The image below shows their position.
Fig. Extra Power Output
Burn the Program
Download the ready made program given below and burn it into your development board.
to burn the program you need a USB AVR Programmer as shown below. This will help you transfer the program from your PC to your development board.
Fig. AVR Programmer
Connect the programmer with the development board using a 10 pin FRC cable, then connect the programmer with your PC using USB Cable. On PC, launch eXtreme Burner – AVR, it is the software interface to command the programmer.
Fig. Programming Setup
Fig. eXtreme Burner – AVR
Verify the Performance
To verify the performance, keep the sensor horizontally over a flat surface. Put a measuring scale in from of the sensor on the same surface. Then bring your palm in from of the sensor. You can know the distance of your palm from the sensor by the measuring scale. This same reading (in cm) should be shown on the LCD. This verifies that the demo is working perfectly !
Fig. Testing HC-SR04
Fig. Testing HC-SR04
Fig. Schematic for HC-SR04 interfaced with ATmega8
|1||R1||100 Ohms||Resistor 1/4 watt||1|
|2||R2||330 Ohms||Resistor 1/4 watt||1|
|3||R3||4.7K Ohms||Resistor 1/4 watt||1|
|4||C1||470uF||Electrolytic Capacitor 25V||1|
|0.1uF(100nF)||Ceramic disk type capacitor||4|
|6||C3,C4||22pF||Ceramic disk type capacitor||2|
|8||D2||-||5mm LED – Round – RED||1|
|10||U2||7805||5V Voltage Regulator||1|
|12||RV1||10K Ohms||Preset (Variable Resistor)||1|
|17||-||-||28 PIN IC Socket||1|
|18||-||-||16 PIN Female Connecter||1|
|19||-||-||4 PIN Female Connecter||1|
|20||-||-||16 PIN Male Connecter||1|
|21||DISP1||-||LCD Module 16×2 GREEN B/L||1|
Buy this project
Fig. Made on custom PCB
We highly recommend EasyEDA for PCB Design and low cost PCB Prototype.
Facing problem with your embedded, electronics or robotics project? We are here to help!
Post a help request.