SRF05 Ultrasonic Ranger

Table of Contents

  1. Hello World!
  2. Library
  3. Other

An ultrasonic rangefinder

/media/uploads/simon/srf05.jpg

Hello World!

» Import this program

00001 // Simple program to read the distance from an SRF05 using the SRF05 library
00002 
00003 #include "mbed.h"
00004 #include "SRF05.h"
00005 
00006 SRF05 srf(p13, p14);
00007  
00008 int main() { 
00009      while(1) { 
00010          printf("Distance = %.1f\n", srf.read());              
00011          wait(0.2); 
00012      } 
00013  } 
SRF05 pinSignalmbed pin
1+5v SupplyVu
2Echo outputp14
3Trigger inputp13
4Moden/c
50v GroundGND

/media/uploads/simon/srf05_breadboard.jpg

Library

» Import this library into a program

Public Member Functions

  SRF05 (PinName trigger, PinName echo)
  Create a SRF05 object, connected to the specified pins.
float  read ()
  A non-blocking function that will return the last measurement.
  operator float ()
  A short hand way of using the read function.

Other





6 comments:

08 Aug 2011

Hi Simon, How can I use the distance in the program Is it correct to write this for 7 cm

If(srf.read()==7)

I test this but it does not work

10 Aug 2011

Hi Simon, After my comment I found that I can use if(srf.read()==7) but there is a problem with this. I use srf05 in my robot to stop in 7 cm of a box. when my robot moves very slow it stops in 7 cm of the box but when it moves a little faster it does not stop in 7 cm of the box. Do you think the problem is in the library or in my code?

10 Aug 2011

Hi i would say your code. Because if your robot goes to fast in relation to the sample time you use for your range finder you will likely miss the 7 cm mark. I would suggest you try "if(srf.read()<=7)"

10 Aug 2011

user christian b wrote:

Hi i would say your code. Because if your robot goes to fast in relation to the sample time you use for your range finder you will likely miss the 7 cm mark. I would suggest you try "if(srf.read()<=7)"

Hi when I use 0.1 for duty cycle of my H bridge it stops but when I use 0.2 for duty cycle it does not stop do you think the speed is so much that SRF05 could not find the box? Should I write my own code for SRF05

10 Aug 2011

I find a mistake in library It is about tigger puls In the library it is 2us not 20us. 20us=0.00002, 2us=0.000002,

any way it does not solve my problem

13 Oct 2011

Hi, I am running HS-SR04 with the code above and it works fine but only if it is pointing to the flat surface like a wall, but if it is pointed to the desk full of stuff it stops responding and returns the last value repeatedly. After disconnecting GND or 5V and connecting it back sensor works again. Is the same thing happening with SRF05?