Hello everyone,

We are glad to take you through the procedure involved in interfacing an Ultrasonic Sensor with ATmega 16/32 microcontroller board. 

Hardware Prerequisites:-

  • ATmega 16/32 board.
  • Ultrasonic sensor Sensor: 
  • LED array
  • AVR USB programmer:-USBasp. 
  • CP2102:-USB to TTL serial converter. 
  • Jumper Wires for making connections.

Software Prerequisites:-

  • AVR studio for coding and compiling
  • AVRdude for burning/uploading hexcode
  • PuTTy:- A terminal software.

ATMEGA 16

FEATURES

  • ATmega16 is an 8-bit high performance microcontroller from the Atmel’s Mega AVR family.
  • Atmega16 is a 40 pin microcontroller based on enhanced RISC architecture with 131 powerful instructions.
  • It has a 16 KB programmable flash memory, static RAM of 1 KB and EEPROM of 512 Bytes.
  • Most of the instructions execute in one machine cycle.
  • It can work on a maximum frequency of 16MHz.

Ultrasonic sensor

STEP 1:

Make clean connections for interfacing Ultrasonic sensor with ATmega 16/32 board by following these pin inter-connections.

ULTRASONIC SENSOR PINS ATMEGA 16/32 PINS
V 5V
TRIG  PB0
ECHO  PB1
GND GND

           

Also connect CP2102 to ATmega 16/32 microcontroller board as depicted in table below.

CP2102 pins ATmega 16/32 pins
TXD RXD
RXD TXD
GND GND
5V 5V

 

Below figure shows the hardware connection

STEP 2:

Open AVR studio. Copy the program source code along with its attachment libraries and headers. Save and Build the main program source code in AVR studio.

To set board and frequency go to Project>Configuration options in AVR studio. Select device as ATmega16/32 and set Frequency as 8000000 Hz

STEP 3:

Connect USBasp USB programmer to ATmega 16/32 board. Open AVRdude software. In configuration settings, select ATmega16/32 as microcontroller.

STEP 4:

In memories section of AVRdude, browse for hexcode generated for the main source code

STEP 5:

Also, check if the write button is ticked. If not ,tick it. After uploading hexcode. Press execute to burn the code into ATmega 16/32 board.

STEP 6:

In order to observe serial data available, connect USB to TTL serial converter to a USB port in PC. Open PuTTy. Select Serial button. Also, select the communication port and set baud rate as 9600. Click Open.


If obstacle is detected , ‘obstacle detected" and readings appears on screen else readings appears on screen.

OUTPUT SCREEN SHORT

PROGRAM CODE

Go through this link.Open atmega16 folder->open ultrasonic_test-> attach all the libraries to the AVR Studio,upload it to the board.