Challenge

Project 2 - Measuring distance of an object using ultrasonic sensor (HC-SR04)

<form>

 

Overview of the Project: 

In this project, the implementation of code for “Measuring distance of an object using ultrasonic distance sensor (HC-SR04)

Goals:

  • Measuring the distance of an object using Ultrasonic Distance Sensor (HC-SR04)
  • Usage of Input Capture Mode

Key Highlights of the Project: 

  • Measuring the distance travelled by the wave to the object and gets bounced back from the object to sensor.
  • Measuring Pulse width using Input Capture Mode

Deliverables of this project: 

  • The distance travelled by a wave to the object for which we want to measure the distance using Ultrasonic Distance Sensor (HC-SR04).
  • Measuring Pulse width using Input Capture Mode of Timer 1

Expected Outcomes: 

The students will get the Knowledge on Ultrasonic sensor (HC-SR04) to measure the distance travelled by wave to the object, the hardware connection of Atmega328p and HC-SR04 and how to use input capture mode of Timer1

 

Aim:

To implement code for “Measuring distance of an object using ultrasonic distance sensor (HC-SR04).

Objective:

  • Measuring the distance of an object using Ultrasonic Distance Sensor (HC-SR04)
  • Usage of Input Capture Mode

Highlights:

  • Measuring the distance travelled by the wave to the object and gets bounced back from the object to sensor.
  • Measuring Pulse width using Input Capture Mode

Deliverables:

  • The distance travelled by a wave to the object for which we want to measure the distance using Ultrasonic Distance Sensor (HC-SR04).
  • Measuring Pulse width using Input Capture Mode of Timer 1

Code:

#include 
#define F_CPU 16000000ul
#include 
#include 
#include 
#include 


#define lcd_data_dir DDRD         
#define lcd_command_dir DDRC      
#define lcd_data_port PORTD       
#define lcd_command_port PORTC      
#define EN PC2                      
#define RW PC3                       
#define RS PC4                      

void lcd_command(char);                     
void lcd_char(char);                        
void lcd_init(void);                         
void lcd_string(char*);                   
void lcd_string_xy (char,char,char*);          

void lcd_command (char cmd)                    
{
 lcd_data_port = cmd;                          
 lcd_command_port&=~((1<Program:

Circuit:

  • The program is loaded in the Atmega 32 chip.
  • LCD pins are connected to the Atmega32 as shown above.
  • Osillocope and ultrasonic sensors are connected to view the output.

Output:

  • 60.38 cm is the distance of an object obtained.

Result:

Thus the implementation of code for “Measuring distance of an object using ultrasonic distance sensor (HC-SR04) is done.

</form>
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.