Basic Stamp BS2 + SRF05 Ultrasonic Sensor Setup Guide
To use mode 2 with the Basic Stamp BS2, you simply use PULSOUT and PULSIN on the same pin.
Hardware Preparation
| Name | Model/SKU | Quantity | Purchase Link |
|---|---|---|---|
| SRF05 Ultrasonic Sensor | SEN0006 | 1 | DFRobot SEN0006 |
| Basic Stamp BS2 | 1 |
Wiring Diagram


Working Principle
You have that long to turn the trigger pin around and make it an input and to have your pulse measuring code ready. The PULSIN command found on many popular controllers does this automatically.
Procedure
| Step / Command | Description |
|---|---|
| SRF05 PIN 15 | Use a single pin for both trigger and echo |
| Range VAR Word | Define a 16-bit variable to store the range |
| SRF05 = 0 | Initialize the pin to LOW |
| PULSOUT SRF05, 5 | Send a 10 µs trigger pulse (5 × 2 µs) |
| PULSIN SRF05, 1, Range | Measure the echo pulse duration |
| Range = Range / 29 | Convert pulse width to distance in cm (divide by 74 for inches) |
Was this article helpful?
