0% found this document useful (0 votes)
4 views

Arduino with HC

Project for sensing distance using ultrasonic sensor and arduino

Uploaded by

RijendraNepali
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Arduino with HC

Project for sensing distance using ultrasonic sensor and arduino

Uploaded by

RijendraNepali
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Arduino with HC-SR04 Sensor to read and write the distance in the serial

monitor.

Introduction

HC-SR04 sensor is used to read and write the distance in the serial monitor.

On making this project we know about Ultrasonic sensor , Arduino , jumper


wire.

Hardware Components Requirements:

1) Arduino UNO
2) HC-SR04 sensor (Ultrasonic Sensor)
3) Few jumpers wire

Software Components Requirements:

1. Arduino IDE

Arduino IDE

It is the open source platform to write the code which is understood by


Arduino.

Link to download Arduino is : htttps://www.arduino.cc/en/software

Hardware description

Arduino UNO

It is one of the most popular microcontroller boards in the Arduino used


widely for prototyping and learning electronics. It is an open-source platform
based on the ATmega328P microcontroller. Applicable both for amateur and
professionals in the field of electronic projects.

Ultrasonic sensor

This device measures distance by emitting high frequency sound waves and
analyzing the echo that returns after hitting an object. These sensors are
widely used in various applications such as robotics, automative systems,
industrial automation, and smart home devices due to their ability to provide
accurate and reliable distance measurement without using physical contact.

Sound waves typically above 20kHz is sent from a transmitter; these waves
encounter an object and bounce back. The sensor’s receiver captures the
reflected waves.
The sensor determines the distance to the object using the formula

Distance = (Speed of sound x Time)/2

Jumper wires

Jumper wires are simple electrical wires with connector pins at both ends
designed to connect various components in a circuit without soldering. They
are widely used in prototyping and breadboarding allowing hobbyists and
engineers to quickly and efficiently build and test circuits.

Types of jumper wires

1. Male to Male : Both ends have pins that fit into female connectors or
breadboard holes.
2. Male to Female: One end has a pin(male), and the other has a
socket(female), making them suitable for connecting breadboards to
components or modules with male headers.
3. Female to Female: Both ends have sockets, ideal for connecting
components or modules with male pins.

Jumper wires are usually color-coded( eg., red for power, black for
ground) to help organize and distinguish connections.

Circuit Diagram
// for Ultrasonic sensor

Step 1: Connect the +5V of Ultrasonic Sensor to the 5V of Arduino

Step 2: Connect the GND of Ultrasonic Sensor to the GND of the Arduino

Step 3: Connect the Trigger pin of the Ultrasonic Sensor the pin 10 of the
Arduino.

Step 4: Connect the Echo Pin of the Ultrasonic Sensor the pin 11 of the
Arduino.

int trigPin=10;

int echoPin=11;

long duration, cm, inches;

void setup() {

// Serial port begin

Serial.begin(9600);
//Define inputs and outputs

pinMode(trigPin,OUTPUT);

pinMode(echoPin,INPUT);

void loop() {

// The sensor is triggered by a HIGH pulse of 10 or more microseconds.

// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:

digitalWrite(trigPin,LOW);

delayMicroseconds(5);

digitalWrite(trigPin,HIGH);

delayMicroseconds(10);

digitalWrite(trigPin,LOW);

//Read the signal from the sensor: a HIGH pulse whose

//duration is the time(in microseconds) from the sending

// of the ping to the reception of its echo off of an object.

pinMode(echoPin, INPUT);

duration=pulseIn(echoPin, HIGH);

//convert the time into a distance

cm=(duration/2)/29.1;

inches=(duration/2)/74;

Serial.print(inches);

Serial.print("in,");

Serial.print(cm);

Serial.print("cm");

Serial.println();

delay(250);
}

You might also like