DIY Speed Sensor Using Arduino

by Yogeshwaran in Circuits > Arduino

2443 Views, 27 Favorites, 0 Comments

DIY Speed Sensor Using Arduino

Arduino Speed Detector (Instructables) Title Image.png

Are you curious about how speed guns measure vehicle velocities or how athletes' sprint speeds are recorded? While advanced sensor technology often plays a role, you can create your speed detector using an Arduino and a pair of infrared (IR) sensors.

By positioning two IR sensors a fixed distance apart, you can accurately calculate the object's speed when the object passes those two IR sensors.

This project has a wide range of applications. You can measure the speed of moving cars, conduct scientific experiments to study motion, acceleration, or friction, and even use the sensor in packaging and sorting systems to monitor object speeds on a conveyor belt.

Looking for even more thrilling projects? Explore a range of exciting ideas such as Arduino IoT Projects | Arduino Robotics Projects | Arduino AI Projects | Arduino Home Automation Projects | Raspberry Pi Projects | ESP32 Projects to take your creativity to the next level!

Supplies

  1. Arduino UNO R3 Development Board
  2. Two IR Sensors
  3. 16x2 LCD Display with builtin I2C Module
  4. 12V DC Power Adaptor with Barrel Jack
  5. Breadboard
  6. Connecting Wires

Let's Understand How IR Sensors Measure Speed of Moving Object

IR SENSOR SCALE.jpg

Eventually IR sensor used for detecting the object presence, but when it used in a pair, we can also able to measure the speed of a moving object.

The first sensor triggers the timer when the object passes, and the second sensor stops the timer once the object passes it. With the known distance between the sensors and time taken by object, speed can be easily calculated using the formula: For more details check on my detailed guide of making DIY Arduino Speed Sensor.

Speed = Distance / Time

When placing IR sensors, we must be aware that the spacing between them is crucial for calculating speed without error. If you want to know how this will affect accuracy and what steps we can take to improve it, feel free to check out my official documentation.

Create Circuit Diagram for Arduino Speed Sensor

Circuit_diagram.PNG

Here is an Breadboard Versioned Circuit Diagram for our Arduino Speed Detector.

Start to Build an Hardware Setup

Parts marking.jpg
How to build a Speed Sensor using Arduino? Measure Speed of Moving Objects

Here is the actual hardware setup developed by using our Arduino sensor circuit diagram as a reference. Here you can see that I am powering this whole setup from the external power adapter through a 12V DC jack.

If you are facing any issues or having an query related to hardware setup, you can reach our here, where I provide a complete details related to hardware setup.

Lets Start to Write Some Code for Arduino

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the I2C LCD with the default address (usually 0x27 or 0x3F)
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define SENSOR_1_PIN 2 // Pin for first IR sensor (INT0)
#define SENSOR_2_PIN 3 // Pin for second IR sensor (INT1)
volatile unsigned long timeSensor1 = 0;
volatile unsigned long timeSensor2 = 0;
volatile bool sensor1Triggered = false;
volatile bool sensor2Triggered = false;
const float distanceBetweenSensors = 0.1; // Distance between sensors in meters
float speed = 0; // Speed in meters per second (m/s)
void setup() {
// Initialize the LCD
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Speed Gun");
delay(2000); // Show the title for 2 seconds
lcd.clear();
pinMode(SENSOR_1_PIN, INPUT);
pinMode(SENSOR_2_PIN, INPUT);
// Attach interrupt for sensor 1 (INT0) and sensor 2 (INT1)
attachInterrupt(digitalPinToInterrupt(SENSOR_1_PIN), sensor1ISR, RISING);
attachInterrupt(digitalPinToInterrupt(SENSOR_2_PIN), sensor2ISR, RISING);
}
void loop() {
if (sensor1Triggered && sensor2Triggered) {
sensor1Triggered = false;
sensor2Triggered = false;
unsigned long timeDifference = abs(timeSensor2 - timeSensor1); // Time in microseconds
lcd.clear();
if (timeDifference > 0) {
speed = distanceBetweenSensors / (timeDifference / 1000000.0); // Convert µs to seconds
lcd.setCursor(0, 0);
lcd.print("Speed:");
lcd.setCursor(0, 1);
lcd.print(speed, 2); // Display speed with 2 decimal places
lcd.print(" m/s");
} else {
lcd.setCursor(0, 0);
lcd.print("Invalid Reading!");
}
}
}
void sensor1ISR() {
if (!sensor1Triggered) { // Ensure only the first trigger is recorded
timeSensor1 = micros(); // Record the time of sensor 1 trigger
sensor1Triggered = true;
}
}
void sensor2ISR() {
if (!sensor2Triggered) { // Ensure only the first trigger is recorded
timeSensor2 = micros(); // Record the time of sensor 2 trigger
sensor2Triggered = true;
}
}

If you feel confused, How this code works? and what algorithm did it follows? For all of yours question, you can get an answer on my original documentation work, where I explained code part by part in easily understandable way.

After understanding the concept behind the code, start to upload the code into Arduino.

Do Experiment on Our Arduino Speed Sensor

Screenshot (38).png

After flashing the code and providing a proper power supply, If everything goes well, you can able to get the result as shown here.

No matter if you're a beginner or an experienced maker, this speed detection system makes learning about sensors and speed measurement both fun and simple. Ready to build your own speedometer? Check out our detailed guide on creating a DIY Speed Detection System with IR Sensors and Arduino to get started!

Want to discover more cool projects? Dive into our collection of Arduino IoT Projects | Arduino Robotics Projects | Arduino AI Projects | Arduino Home Automation Projects | Raspberry Pi Projects | ESP32 Projects to inspire your next build!