- The SRF005 ultrasonic range sensor detects objects in it’s path.
- It can be used to calculate the range of the object.
- It is sensitive enough to detect a 3cm diameter broom handle at a distance of over 3m.
Figure 1: SRF-05 Ultra sonic
Connetion:
Step 1: Connection from Sensor to Arduino board
- Connect the Gnd of the sensor to the Gnd of the board.
- Connect the VCC of the sensor to the 5V of the board.
- Connect the triger of the sensor to the digital pin 03 of the board.
- Connect the echo of the sensor to the digital pin 04 of the board.
Step 2: Connection From Leds to Arduino board
Led 1 connection:
- positive pin = 13
- negative pin = Gnd
Led 2 connection:
- positive pin = 12
- negative pin = Gnd
Programming
- #define ECHOPIN 03 // Pin to receive echo pulse
- #define TRIGPIN 04 // Pin to send trigger pulse
-
- void setup(){
- Serial.begin(9600);
- pinMode(ECHOPIN, INPUT);
- pinMode(TRIGPIN, OUTPUT);
- pinMode(13, OUTPUT);
- pinMode(12, OUTPUT);
- }
-
- void loop(){
- digitalWrite(TRIGPIN, LOW);
- delayMicroseconds(2);
- digitalWrite(TRIGPIN, HIGH);
- delayMicroseconds(10);
- digitalWrite(TRIGPIN, LOW);
- int distance = pulseIn(ECHOPIN, HIGH);
- distance= distance/58;
- Serial.println(distance);
- delay(50);
- digitalWrite(13, HIGH);
- digitalWrite(12, HIGH);
- delay(1000);
- digitalWrite(13, LOW);
- digitalWrite(12, LOW);
- delay(1000);
-
- }
Explanation:
- It is used to check the range of the water in a tank
- The pulse and distance are shown in the serial monitor
- When the tank meter is on, led is ON
- When the tank meter is off, led is OFF.
Output
Figure 2 : Output