fbpx

Interface Ultrasonic With Arduino Uno

Ultrasonic sensor act like a bats.

  • The HC-SR04 ultrasonic sensor uses sonar to determine distance.
  • It offers excellent range detection with high accuracy and stable reading.
  • It offers range detection from 2cm to 400 cm or 1 to 13 feet.
  • Ultrasonic sensor consist of Transmitter and Receiver module.

Working

  • Sensor trigger pin must receive a pulse of high (5V) for 10us.
  • Then sensor will transmit out 8 cycle of 40kHz ultrasonic burst.
  • Sensor wait for the reflected ultrasonic burst.
  • When the sensor detected ultrasonic from receiver, it will set the Echo pin to high (5V) and delay.
  • Delay period is a width which proportion to distance.
  • To obtain the distance, measure the width (Ton) of Echo pin.

Timing Diagram

Distance Calculation

  • Time = Width of Echo pulse, in uS (micro second).
  • Distance in centimeters = Time / 58.
  • Distance in inches = Time / 148.

Features

  • Power Supply :+5V DC.
  • Quiescent Current : less than 2mA.
  • Working Current: 15mA.
  • Effectual Angle: Less than 15 Degree.
  • Ranging Distance : 2cm to 400 cm/1 to 13ft.
  • Resolution : 0.3 cm.
  • Measuring Angle: 30 degree.
  • Trigger Input Ppse width: 10uS.
  • Dimension: 45mm x 20mm x 15mm.

Hardware Required

  • Ultrasonic HC-SR04.
  • Arduino.

Pin Diagram

  • VCC: +5VDC.
  • Trig : Trigger (INPUT).
  • Echo: Echo (OUTPUT).
  • GND: GND.

Circuit

Code

 #define utrigger 13
 #define uecho 12
 long duration, inches, cm;
 void setup()
 {
 Serial.begin(9200);
 pinMode(utrigger, OUTPUT);
 pinMode(uecho, INPUT);
 pinMode(11, INPUT);
 digitalWrite(11,HIGH);
 }
 void loop()
 {
 digitalWrite(utrigger, LOW);
 delayMicroseconds(2);
 digitalWrite(utrigger, HIGH);
 delayMicroseconds(10);
 digitalWrite(utrigger, LOW);
 duration = pulseIn(uecho, HIGH);
 inches = microsecondsToInches(duration);
 cm = microsecondsToCentimeters(duration);
 Serial.println(cm);
 }
 long microsecondsToInches(long microseconds)
 {
 return microseconds / 74 / 2;
 }
 long microsecondsToCentimeters(long microseconds)
 {
 return microseconds / 29 / 2;
 } 

Leave a Reply

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