Measuring Distance using SR04

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

  1. Wire SR04 as shown in the ExpEYES setup.
  2. Place a flat reflecting target in front of sensor.
  3. Move target periodically (hand oscillation / spring-mass / pendulum).

5. Procedure

  1. Run acquisition for ~5 seconds and save data to sr04.csv.
  2. Plot distance vs time.
  3. Select a clean oscillation segment.
  4. Fit to sinusoid and extract frequency.
  5. Compare measured period with theoretical model (if applicable).
Transistor Amplifier - Mobile App

Measurements Screenshot

Transistor Amplifier - Desktop App

Setup Photo


6. Observation Table

TrialMean 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

  1. Keep reflector flat and roughly perpendicular to sensor.
  2. Avoid nearby moving objects causing false echoes.
  3. Ensure target remains within SR04 sensing range.

9. Troubleshooting

SymptomPossible CauseCorrective Action
Unstable distance valuesWeak/angled reflectorUse larger flat target
Missing pointsOut-of-range targetKeep target within rated range
Poor fit qualityNon-periodic motionUse 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.