Introduction
The SRF02 is a single transducer ultrasonic rangefinder in a small footprint PCB. It features both I2C and a Serial interfaces. The serial interface is a standard TTL level UART format at 9600 baud,1 start, 2 stop and no parity bits, and may be connected directly to the serial ports on any microcontroller. Up to 16 SRF02's may be connected together on a single bus, either I2C or Serial. New commands in the SRF02 include the ability to send an ultrasonic burst on its own without a reception cycle, and the ability to perform a reception cycle without the preceding burst. This has been as requested feature on our sonar's and the SRF02 is the first to see its implementation. Because the SRF02 uses a single transducer for both transmission and reception, the minimum range is higher than our other dual transducer rangers. The minimum measurement range varies from around 17-18cm (7 inches) on a warm day down to around 15-16cm (6 inches) on a cool day. Like all our rangefinders, the SRF02 can measure in uS, cm or inches. Reference Links: http://www.robot-electronics.co.uk/htm/srf02tech.htm;
Specification
- Range: 16cm to 6m.
- Power: 5v, 4mA Typ.
- Frequency: 40KHz.
- Size: 24mm x 20mm x 17mm height.
- Analogue Gain: Automatic 64 step gain control
- Connection Modes: 1 - Standard I2C Bus 2 - Serial Bus(connects up to 16 devices to any uP or UART serial port)
- Full Automatic Tuning: No calibration, just power up and go
- Timing: Fully timed echo, freeing host controller of task.
- Units: Range reported in uS, mm or inches.
- Light Weight: 4.6gm
Pin Function

"Mode" pin: Select the communication between MCU and SRF02 Ultrasonic sensor. It has an internal pull-up resistor. When in IIC mode,the "Mode" pin should be left unconnected. When in UART mode,it must be connected to GND.
Connection Diagram(IIC Mode)

Sample Code(IIC Mode)
Connection Diagram(UART Mode)

Sample Code(UART Mode)
Of course,if you don't have a Leonardo board, you can also use the Arduino UNO by the software serial. Just change "Serial1" into "mySerial" and add these sentence:
Change your connection according to your software serial pin defination. I tested OK.