A lightweight Arduino project that measures object speed between two sensors and raises a servo "speed breaker" when the speed exceeds a threshold. Perfect as a classroom demo or a small physical prototype. βοΈπ
π Quick Snapshot
- Purpose: detect overspeed and trigger a servo barrier
- Distance used in code: 18 cm (fixed)
- Default threshold: 10 cm/sec
- Measured unit: cm/sec
β¨ Table of Contents
- Two digital sensors (pins
2and3) are placed a known distance apart (18 cm in the sketch). - The sketch timestamps when each sensor is triggered and calculates elapsed time.
- Speed is calculated as distance / time (cm/sec).
- If measured speed > threshold (default 10 cm/sec), the servo on pin
5raises the speed breaker and the red LED signals overspeed.
- Microcontroller: Arduino Uno (or compatible)
- Sensors: 2 Γ IR break-beam or digital switches
- Actuator: 1 Γ Servo motor (SG90 or similar)
- Indicators: 2 Γ LEDs (Red for overspeed, Green for normal) + resistors
- Misc: Jumper wires, breadboard, stable 5V power for servo
Pin mapping (in sketch):
- Sensor 1: pin
2(sen1) - Sensor 2: pin
3(sen2) - Servo signal: pin
5 - Red LED (overspeed): pin
6(l1) - Green LED (normal): pin
7(l2)
Wiring notes:
- Sensor outputs β pins
2and3(ensure correct Vcc/GND) - Servo signal β pin
5, servo Vcc β5V, servo GND βGND - LED anode β respective pin through resistor, LED cathode β
GND
β οΈ Note: the original sketch sets the LED pins withpinMode(..., INPUT)insetup(). Those should beOUTPUTfordigitalWrite()to work properly.
- Open
Speed_Detection.inoin the Arduino IDE. - Select board
Arduino Unoand the correct COM port. - Click Upload.
- Open Serial Monitor at
9600baud to view messages.
Example: open the Serial Monitor to see messages like:
Speed Measurement
Overspeed detected
12.3 cm/sec
Speed Breaker Raised
- Distance: change the
18.0value in the code to match your real sensor spacing. - Threshold: update the
if (Speed > 10)comparison to your chosen limit. - Debounce: for noisy sensors, add simple debouncing or use interrupts for better accuracy.
Code hints:
- Edit the distance here in the sketch:
Speed = (18.0 / Speed); - Edit the threshold here:
if (Speed > 10)
- Change LED pin modes to
OUTPUTinsetup():
pinMode(l1, OUTPUT);
pinMode(l2, OUTPUT);- Consider using pin change interrupts for precise timing instead of blocking
while()loops. - Add debouncing or filtering to avoid false triggers.
- Add logging or data export (CSV over serial) for offline analysis.
- No serial output: ensure Serial Monitor is set to
9600baud. - LED not lighting: confirm
pinModeusesOUTPUTand wiring is correct. - Servo jitter: use a dedicated power source for the servo if noisy.