Make it mech
  • Home
  • How & Why
    • Arduino
    • Leapmotion with arduino
    • Sensors/Modules
    • Basic Electronics
    • NodeMcu
    • LabView
    • MATLAB
    • Industrial Automation
  • Projects
    • arduino projects
    • Robotics
    • Brain Wave Decoder
    • EEG
    • Leapmotion with arduino
    • Circuit Diagrams
    • Electrical
    • Mechatronics
    • IEE Projects
  • Ideas
  • Startups
  • Videos
No Result
View All Result
  • Arduino
  • Robotics
  • Circuits
  • LeapMotion
  • EEG
  • IOT
  • LabView
  • NodeMcu
  • Mechatronics
  • Sensors
  • Motivation
  • Soft skills
  • Success
Wednesday, January 13, 2021
Make it mech
No Result
View All Result
Home Arduino

How to Use Ultrasonic Sensor SR04 with arduino and How ultrasonic sensor works

496
SHARES
1.4k
VIEWS

Related posts

Mechatronics Projects for Final Year students with Industrial Aspect

Mechatronics Projects for Final Year students with Industrial Aspect

August 31, 2020
Top 10 Arduino Based Projects For Final Year Students | Arduino project ideas

Top 10 Arduino Based Projects For Final Year Students | Arduino project ideas

August 31, 2020

Ultrasonic Sensor SR04 with arduino

Welcome to the second Tutorial in the series of Arduino Learn by Doing.Today our task is to learn about Ultrasonic sensor. How and why to use ultrasonic sensor and the implementation of ultrasonic SR04 SONAR sensor module with Arduino. So today We will discuss some of the projects with ultrasonic sensor later in coming posts but before that, we will see the working and usage of ultrasonic sensor SR04 with Arduino.
So Let’s start with the contents list.

Contents:

  1. Introduction to Ultrasonic SR04 SONAR sensor
  2. How Ultrasonic sensor works
  3. Components list
  4. Circuit diagram
  5. Arduino code for Ultrasonic SR04 sensor

Step: 01Introduction to Ultrasonic SR04 SONAR sensor


The Ultrasonic Sensor as the name sounds like the sound it works on Sound waves. The Ultrasonic is a sensor device that actually works with sound waves.It works on the phenomenon of sending and receiving of ultrasonic sound waves.And by sound waves, it measures the distance and obstacles.It is a sensor that measures the distance or Detects obstacle.And it can be used either in both ways.The Ultrasonic Sr04 SONAR is a module created for interfacing with micro controllers.

The basic phenomenon of measuring distance or detecting an obstacle with ultrasonic sound waves comes from underwater communication.And If I’m not wrong we can say the communication way of fishes.


Step: 02How Ultrasonic SR04 SONAR sensor works


The Ultrasonic sensor works on the phenomenon of sending sound waves at a particular frequency and receive on bouncing back.The sensor measures distance and existence of the obstacle with in the time of sending and receiving of the sound wave.
The total traveling distance of sound wave can be calculated by using this formula:
distance measuring eq
The SR04 obstacle avoiding module easily interfaces with Arduino. This SR04 ultrasonic module is a high accuracy range detector module.The Distance range of SR04 SONAR is from 2 cm to 400 cm.
The ultrasonic module works fine in almost all good conditions but remembers in high noise and in some situations and materials the module will not work. It also not works in dead band. The dead band is in the too much less distance below 2 cm.
The good thing about ultrasonic SR04 is it’s quite cheap and has built-in transmitter and receiver.You don’t need to buy two modules to communicate with each other.

The SR04 module has 4 pins other than the power supply and ground one is an echo that is used for receiving signals and the other is the trigger that is used for triggering the signal.


Step: 03Components List


  1. 1x Arduino Board Uno  (any of your choice)
  2. HC-SR04 Ultrasonic SONAR sensor
  3. 1x Bread board
  4. jumper wires

Step: 04Circuit Diagram


sr04
The working current of Ultrasonic SR04 module is 15 mA.
  • Connect the Vcc pin to the 5v on Arduino and Ground pin to GND on Arduino
  • Connect Trig pin to any digital pin on Arduino
  • Connect echo pin on any digital PWM pin on Arduino as echo pin is our INPUT

Connect all pins correctly and test the sample code first then try to implement more sensor and complex code.The Arduino code is, as usual, simple so let’s see the coding part.


Step: 05Arduino Code

Test the Arduino code first then try to change for more sensors and complex situations.The output is in voltages in modules so we need to convert it into cm or inches so divide the time duration by 29.
 #define trigPin 11         .........
 #define echoPin 10     ........
 void setup() {         // .................
 Serial.begin (9600);
 pinMode(trigPin, OUTPUT);   //.................
  pinMode(echoPin, INPUT);     ...........
}                  //....................
void loop()      //  ............




{
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);  // .................................
distance = (duration/2) / 29.1;             // ..................................
Serial.print(distance);
Serial.print("cm");
Serial.println();
delay(100);
}

 

You can connect any output motors or LEDs depends on your application.For that, we need to add some extra code just add conditions to the code but remember to define any output first.

if (distance < 4) {
digitalWrite(led,HIGH);
digitalWrite(led2,LOW);
}
else {
digitalWrite(led,LOW);
digitalWrite(led2,HIGH);
}
if (distance >= 200 || distance <= 0){
Serial.println("Out of range");
}
else {
Serial.print(distance);
Serial.println(" cm");
}
delay(100);
}

 

Define the led pins as we define echo and trig pin as an in put or output.

We will see some of the great projects using the Ultrasonic sensor in coming posts.Here is the picture of the Obstacle avoiding Robot that I have made.The Robot has many functionalities we will see this in coming soon so stay connected and subscribe to our YouTube channel for video Tutorials.Stay motivated and happy.

Tags: distance sensor with arduinosr04
Previous Post

How to use LM35 Temperature Sensor with Arduino | arduino tutorials

Next Post

How to Use IR Sensor module with Arduino | How Arduino IR obstacle detector module works

Mak

Mak

Mechatronics Engineer - Entrepreneur - Solution Architect Love writing & Traveling - Being Average isn't a Choice Stay Happy - Live in Freedom & Always have Faith on Yourself...

Related Posts

Mechatronics Projects for Final Year students with Industrial Aspect
Ideas

Mechatronics Projects for Final Year students with Industrial Aspect

August 31, 2020
Top 10 Arduino Based Projects For Final Year Students | Arduino project ideas
Arduino

Top 10 Arduino Based Projects For Final Year Students | Arduino project ideas

August 31, 2020
ldr with arduino
Arduino

How to control (LDR) Light Dependent Resistor with Arduino | LDR Circuit

August 31, 2020

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Contents

RECOMMENDED ARTICLES

Material required for portable EEG system development

Material required for portable EEG system development

3 years ago
How to use NodeMCU Getting started with NodeMcu the Basics

How to use NodeMCU Getting started with NodeMcu the Basics

4 years ago

Top 10 Skills that Every Engineering student must have

2 years ago
Battery Level Indicator Circuit With Low Charge Alarm | Inverter Battery Circuit

Battery Level Indicator Circuit With Low Charge Alarm | Inverter Battery Circuit

1 year ago
  • Privacy Policy
  • About Us
  • Contact Us
Subscribe Our YouTube Channel

© 2020 Make it mech

No Result
View All Result
  • Home
  • How & Why
    • Arduino
    • Leapmotion with arduino
    • Sensors/Modules
    • Basic Electronics
    • NodeMcu
    • LabView
    • MATLAB
    • Industrial Automation
  • Projects
    • arduino projects
    • Robotics
    • Brain Wave Decoder
    • EEG
    • Leapmotion with arduino
    • Circuit Diagrams
    • Electrical
    • Mechatronics
    • IEE Projects
  • Ideas
  • Startups
  • Videos

© 2020 Make it mech

Go to mobile version