HC-SR04 Ultrasonic Sensor
NOTE :- NewPing is a arduino library, that makes easier to use HC-SR04 with arduino.
HC-SR04 Ultrasonic sensor Technical Specification
HC-SR04 |
power supply :- 5DC
Quiescent Current :- 2mA
Working Current :-15mA
Effect Angle :<15 degrees
Distance :- 2cm to 400cm
Resolution :-0.3cm
Trigger input pulse width :-10us
Ultrasonic Frequency :-40KHz
Pins
VCC :- arduino 5v pin
TRIG :- arduino Digital pin
ECHO :- arduino Digital pin
GND :- arduino GND pin
TRIG pin will be used to send ultrasonic sound and ECHO pin will be used to listen.
Example
int triggerPin= 8;
int echoPin= 7;
long pulsDuration =0;
long distanceCM =0;
long distanceINC =0;
void setup() {
// put your setup code here, to run once:
pinMode(triggerPin,OUTPUT);
pinMode(echoPin,INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(triggerPin,LOW);
delayMicroseconds(5);
digitalWrite(triggerPin,HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin,LOW);
pulsDuration =pulseIn(echoPin,HIGH);
distanceCM = (pulsDuration/2) / 29.1;
distanceINC = (pulsDuration/2) / 74;
Serial.println("CM");
Serial.println(distanceCM);
Serial.println("INCH");
Serial.println(distanceINC);
delay(1000);
Serial.println("**********************************************");
}