Skip to content

Programming AtMega8535 with ultrasonic Sensor of distance HC-SR04

Notifications You must be signed in to change notification settings

MarkGoncharovAl/MicroController

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Measuring distance on ATmega8535

GitHub repo size

GitHub last commit

Batarin Egor, Goncharov Mark, Zaripov Ruslan

Introduction

This article is about Ultrasonic Sensor HC–SR04. We will explain how it works and present project example. We provide a schematic diagram on how to wire the ultrasonic sensor, and code for AVR.

Transferring data from microcontroller to computer is implemented through UART - communication protocol.

Educational project referred to Microcontoller courses in MIPT at 2nd grade.
Research supervisor: candidate of technical sciences Donov Gennady Innokentievich.

Project scheme

The scheme of the measuring device is a follows:

MD Scheme Our layout board

It consist of 4 main parts:

  1. ATmega8535 - microcontroller unit
  2. Two HC-SR04 - ultrasonic waves detectors
  3. USBASP - flash driver that allows to program MC
  4. USB to TTL - transmit data from MC to PC

Project description

The MD is powered by 5 volts.

When button is pressed, ATmega triggeres HC-SR04 to measure distance. Then distance is transfered to PC using UART protocol. Finally, using USB to TTL, we get data from serial terminal CuteCom. The distance is measured 2 times in a second.

Led is connected to port PBO and used for debug. It is blinking fastly when the button isn't pressed, and it is lighting permanently when the button is pressed.

Two HC-SR04 are connected to PD6 via two resistors, which are used to synchronize data transmition from these modules to ATmega8535.

HC-SR04 description

Ultrasonic Sensor HC-SR04 is a sensor that can measure distance. It emits an ultrasound at 40 000 Hz (40kHz) which travels through the air and if there is an object or obstacle on its path It will bounce back to the module. Considering the travel time and the speed of the sound you can calculate the distance.

HC-SR04 views

Pin Function Description

  1. VCC - power supply
  2. TRIG - input pin
  3. ECHO - output pin
  4. GND - ground

In order to generate the ultrasound we need to set the Trigger Pin on a High State for 10 µs. That will send out an 8 cycle sonic burst which will travel at the speed sound and it will be received in the Echo Pin. The Echo Pin will output the time in microseconds the sound wave traveled.

HC-SR04 views

For example, if the object is 20 cm away from the sensor, and the speed of the sound is 340 m/s or 0.034 cm/µs the sound wave will need to travel about 588 microseconds. But what you will get from the Echo pin will be double that number because the sound wave needs to travel forward and bounce backward. So in order to get the distance in cm we need to multiply the received travel time value from the echo pin by 0.034 and divide it by 2.

HC-SR04 views Cutecom

2021

About

Programming AtMega8535 with ultrasonic Sensor of distance HC-SR04

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages