HY-SRF05 distance ultrasonic sensor module
  •  
HY-SRF05 distance ultrasonic sensor module

HY-SRF05 distance ultrasonic sensor module

SRF05 ultrasonic sensor
Sonar waves are sonic waves that cannot be heard by humans. However, we can see the presence of ultrasonic waves everywhere in nature. We have animals like bats, dolphins ... using ultrasound to communicate with each other, to hunt or locate in space.
Based on observations of their activity, we can see that the principle that animals use sound waves to locate is very simple, can be summarized in 3 steps:
• The host emits sound waves
• This sound wave collides with its surroundings and reflects back
• Based on the transmitter / receiver time, the distance between the host and the surroundings is calculated.
The distance calculation also depends heavily on the transmission medium, for example, sound waves propagating in water or metal will be much faster than sound waves transmitted in air. Note that sound waves cannot be transmitted in a vacuum.
According to this principle, based on the advancement of modern science and technology, we have seen the application of sound waves in many lives, including the undersea navigational equipment of submarines, equipment radar, environmental distance measuring devices like measuring the depth of the ocean ...

ss_1

SRF05 ultrasonic sensor also works according to the above principle, the device consists of 2 speakers - receiver and transmitter along with 5 pins to connect to Arduino. According to the manufacturer's documentation, the maximum operating range of this sensor is within 5m.

ss_2

The function of these pins is as follows:

 

  • Vcc: power the sensor.
  • Trigger: trigger the sound broadcast process. Activation process when a high / low power cycle occurs.
  • Echo: normally will be in 0V state, activated to 5V as soon as a signal returns, then return to 0V.
  • Gnd: connected to the cathode of the circuit
  • OUT: do not use

 ss_3

Circuit after completing the installation

ss_5

Programmable controller:

With the SRF05 sensor, we will illustrate the use by programming the sensor every 1 s, we activate the sensor and check if there are obstructions in the surrounding.

 

  • Perform every 1s cycle
  • Activate the sensor by turning on the PIN Trigger in the order LOW - HIGH - LOW via the digitalWrite function.
  • Calculate the distance obtained by using the pulseIn function and calculation formulas.
  • We assume that if the distance is less than 0.5m, a barricade message will be printed.
  • Repeat this cycle.

The code for this task is as follows:

  1. #define TRIG_PIN 8
  2. #define ECHO_PIN 7
  3. #define TIME_OUT 5000
  4.  
  5. float GetDistance()
  6. {
  7. long duration, distanceCm;
  8. digitalWrite(TRIG_PIN, LOW);
  9. delayMicroseconds(2);
  10. digitalWrite(TRIG_PIN, HIGH);
  11. delayMicroseconds(10);
  12. digitalWrite(TRIG_PIN, LOW);
  13. duration = pulseIn(ECHO_PIN, HIGH, TIME_OUT);
  14. // convert to distance
  15. distanceCm = duration / 29.1 / 2;
  16. return distanceCm;
  17. }
  18.  
  19. void setup() {
  20. Serial.begin(9600);
  21. pinMode(TRIG_PIN, OUTPUT);
  22. pinMode(ECHO_PIN, INPUT);
  23. }
  24.  
  25. void loop() {
  26. long distance = GetDistance();
  27.  
  28. if (distance <= 0)
  29. {
  30. Serial.println("Echo time out !!");
  31. }
  32. else
  33. {
  34. Serial.print("Distance to nearest obstacle (cm): ");
  35. Serial.println(distance);
  36. }
  37. delay(1000);
  38. }

Image

Product same category

 
Tư vấn ngay