This post is all about the Ultrasonic Sensor HC – SR04.
I’ll explain how it works, show some features and share an Arduino
Project example to help you with your projects.
Description
The HC-SR04 ultrasonic sensor uses sonar to determine
distance to an object like bats do. It offers excellent non-contact
range detection with high accuracy and stable readings in an easy-to-use
package. From 2cm to 400 cm or 1” to 13 feet. It operation is not
affected by sunlight or black material like Sharp rangefinders are
(although acoustically soft materials like cloth can be difficult to
detect). It comes complete with ultrasonic transmitter and receiver
module.
Features
- Power Supply :+5V DC
- Quiescent Current : <2mA
- Working Current: 15mA
- Effectual Angle: <15°
- Ranging Distance : 2cm – 400 cm/1″ – 13ft
- Resolution : 0.3 cm
- Measuring Angle: 30 degree
- Trigger Input Pulse width: 10uS
- Dimension: 45mm x 20mm x 15mm
Pins
- VCC: +5VDC
- Trig : Trigger (INPUT)
- Echo: Echo (OUTPUT)
- GND: GND
Arduino with HC – SR04 Sensor
This sensor is really cool and popular among the Arduino Tinkerers. So I’ve decided to post a project example using this sensor. In this project the ultrasonic sensor read and write the distance in the serial monitor. It’s really simple.
RELATED CONTENT: Like ESP8266? Check out Home Automation Using ESP8266
Note: There’s an Arduino library called NewPing that can make your life easier when using this sensor.
Schematics
Source code
/* * created by Rui Santos, http://randomnerdtutorials.com * * Complete Guide for Ultrasonic Sensor HC-SR04 * Ultrasonic sensor Pins: VCC: +5VDC Trig : Trigger (INPUT) - Pin11 Echo: Echo (OUTPUT) - Pin 12 GND: GND */ int trigPin = 11; //Trig - green Jumper int echoPin = 12; //Echo - yellow Jumper 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); }
For Further Information Contact Us:
Shipping All Across Pakistan
COMPANY: MATRIX ELECTRONICS
CONTACT PERSON:
FAIZAN MUNIR
Mobile:03002785860
Email : sales@matrixelectronic.com
www.matrixelectronic.com
Address: Shop#2, Hassan Center Near Passport Office Sadder Karachi
COMPANY: MATRIX ELECTRONICS
CONTACT PERSON:
FAIZAN MUNIR
Mobile:03002785860
Email : sales@matrixelectronic.com
www.matrixelectronic.com
Address: Shop#2, Hassan Center Near Passport Office Sadder Karachi