Experiment: Measuring Distance using SR04
1. Aim
To measure distance versus time with SR04 and use the data to estimate oscillation frequency of periodic motion.
2. Apparatus / Components Required
- SEELab3 unit
- HC-SR04 ultrasonic sensor module
- Hard reflecting surface / mass-spring setup / pendulum target
- Connecting wires
- Python scripts (
sr04.py,sr04-analyse.py)
3. Theory & Principle
SR04 emits ultrasound and detects echo return time. Distance is obtained from time-of-flight of sound pulse. ExpEYES function:
tm, dist = p.sr04_distance_time()
For periodic motion, distance-time data can be fit to sine function to obtain frequency and period.
4. Circuit Diagram / Setup
- Wire SR04 as shown in the ExpEYES setup.
- Place a flat reflecting target in front of sensor.
- Move target periodically (hand oscillation / spring-mass / pendulum).
5. Procedure
- Run acquisition for ~5 seconds and save data to
sr04.csv. - Plot distance vs time.
- Select a clean oscillation segment.
- Fit to sinusoid and extract frequency.
- Compare measured period with theoretical model (if applicable).
Measurements Screenshot
Setup Photo
6. Observation Table
| Trial | Mean Distance (cm) | Frequency (Hz) | Period (s) | Remarks |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 |
7. Results and Discussion
- Distance tracking was successful over the 5 s acquisition window.
- Sinusoidal fit provided oscillation frequency of ____ Hz.
- Method works well for periodic systems with strong reflective surfaces.
8. Precautions
- Keep reflector flat and roughly perpendicular to sensor.
- Avoid nearby moving objects causing false echoes.
- Ensure target remains within SR04 sensing range.
9. Troubleshooting
| Symptom | Possible Cause | Corrective Action |
|---|---|---|
| Unstable distance values | Weak/angled reflector | Use larger flat target |
| Missing points | Out-of-range target | Keep target within rated range |
| Poor fit quality | Non-periodic motion | Use cleaner oscillatory motion |
10. Viva-Voce Questions
Q1. Why use curve fitting instead of a single peak count?
Ans: Fitting uses all samples, reducing random error in frequency estimation.
Q2. Can SR04 measure static distance accurately?
Ans: Yes, if alignment and reflection quality are good, 3mm step size can be expected. For poor quality surfaces, 5mm +/- variations can be seen.