SRF05 (ultrasonic sensor) and arduino

35,389 Views
SRF05 (ultrasonic sensor) and arduino

style="display:inline-block;width:468px;height:15px"
data-ad-client="ca-pub-3507530299542268"
data-ad-slot="6937426494">

In this tutorial we are going to learn how to use a SRF05 ultrasonic sensor with arduino in a mode which uses only one digital output pin on your microcontroller.

While making the connections make sure you are holding the srf05 as shown in the below figure.

If you are connecting as per below figure then the LED on the srf05 should be up.The Holes/pins next to the LEDs are not supposed to be used.They are only used at the time of manufacturing for programming.

 

CODE

As we are using SRF05 in a mode which is same as for PING(((( sensor,you can use the example code  given for PING((( sensor in arduino IDE

Go to FILE > EXAMPLES > SENSORS > PING

 

Or you can use this code


// Community of Robots//

//SRF05 sample code//

int duration;                                                          //Stores duration of pulse in
int distance;                                                        // Stores distance
int sensorpin = 7;                                                 // Pin for SRF05

void setup()
{
Serial.begin(9600);
}

void loop()
{
  pinMode(sensorpin, OUTPUT);
  digitalWrite(sensorpin, LOW);                          // Make sure pin is low before sending a short high to trigger ranging
  delayMicroseconds(2);
  digitalWrite(sensorpin, HIGH);                         // Send a short 10 microsecond high burst on pin to start ranging
  delayMicroseconds(10);
  digitalWrite(sensorpin, LOW);                                  // Send pin low again before waiting for pulse back in
  pinMode(sensorpin, INPUT);
  duration = pulseIn(sensorpin, HIGH);                        // Reads echo pulse in from SRF05 in micro seconds
  distance = duration/58;                                      // Dividing this by 58 gives us a distance in cm
  Serial.println(distance);                                              // Wait before looping to do it again
  delay(100);   
}


If you have made the connections properly then you will see the LED on back of SRF05 blinking.

After this open the serial monitor in arduino IDE and take your hand infront of SRF05 and you will see the changes in readings/distances.

Comments

ashok.shah16151's picture

readings/distances

How to open the serial monitor in arduino IDE? Please elaborate.

Add a new comment

Login or register to post comments

New to community of robots ?

Ratings

0

Advertisement