What is Ultrasonic Sensor
Ultrasonic sensor, as the name suggests, uses ultra sound of frequency outside human audible range to operate. Ultrasonic sensor is basically a transducer which converts sound energy to electrical energy and vice versa.
Ultrasonic sensors work on the principle that sound waves have a constant velocity. This property of sound is used by the sensor to find the distance of the object. Ultrasonic sensors send a sound pulse, called trigger pulse, which strikes the object and returns back which is sensed by the echo pin. The time difference between the sent pulse and the received pulse is used to calculate the distance of the object.
Things to consider while using Ultrasonic sensors:
- Hard objects like metals can be easily detected by the sensors but soft objects, like cotton, cloth, that absorb sound waves cannot be easily detected.
- The object should be within the range of the sensor.
- The object must be almost parallel to the sensor orientation.
- The object should not be very rough otherwise the sound wave would be reflected in another direction.
Interfacing HC-SR04 Ultrasonic sensor with Arduino:
HC-SR04 has 4 pins as shown in figure viz. Vcc, Gnd, TRIG and ECHO. Vcc is connected to +5V dc supply, gnd is connected to ground, TRIG sends the sound wave and ECHO receives/senses the reflected sound wave.
- Power Supply : +5V dc
- Quiscent Current : <2 mA
- Working current : 15mA
- Field of Vision : <150
- Ranging Distance : 2cm - 400 cm ( for ideal environment)
- Trigger Input Singal : 10 uS TTL pulse
and the code is given below