Arduino Speed Detector IR Sensor

1,504 views

Introduction

People’s lives are in danger due to overspeeding since it might result in accidents. Therefore, traffic police must be equipped with devices that can assist them in identifying the speed of the car so that, in the event that any vehicle is speeding beyond the posted speed limit, they can take the appropriate action against the driver. The technique is laborious since the policeman must physically measure each vehicle’s speed while holding a handgun. Thus, to make it easy, we are presenting you with a project that will make it simple and automated to determine the speed of moving vehicles. Hence, we are going to make an Arduino speed detector in this tutorial.

With increased consistency and precision, this type of device can instantly determine if any vehicles are exceeding the speed limit. This detector makes use of the sensors to measure the speed of the cars as they enter the measuring track.

Hardware Components

You will require the following hardware for the Arduino speed detector.

S.noComponentValueQty
1.Arduino UNO1
2.proximity IR sensor2
3.RGB Diffused Common Cathode1
4.Breadboard1
5.Jumper Wires1

Steps for Making a Speed Detector

For those wishing to gain confidence while learning the fundamentals of Arduino, this project Arduino speed detector is a must-try. The project requires very few electronic components, the list is provided above. Once you have those components, you only need to follow the given steps:

Schematic

Make connections according to the circuit diagram given below.

Wiring / Connections

ArduinoIR sensor 1IR sensor 2RGB Diffused
5VVCC
GNDGNDGND
A0OUT
3.3VVCC
A3OUT
D9GND
D10R
D11G
D12B

Installing Arduino IDE

First, you need to install Arduino IDE Software from its official website Arduino. Here is a simple step-by-step guide on “How to install Arduino IDE“.

Code

Now copy the following code and upload it to Arduino IDE Software.

int sen1=A0;
int sen2=A3;
int ledPin=9;
unsigned long t1=0;
unsigned long t2=0; 
float velocity;
float velocity_real;
float timeFirst;
float timeScnd;
float diff;
float speedConst=7.5;  //in cm.
void setup()
{
  Serial.begin(9600);
  pinMode(sen1,INPUT);
  pinMode(sen2,INPUT);
  analogWrite(11,LOW);
  analogWrite(10,HIGH);
}
  void loop()
  {
    if (analogRead(sen1)<500 && analogRead(sen2)>500)
    {
      timeFirst = millis();
      digitalWrite(ledPin, LOW);
      delay(30);
    }
 
  if (analogRead(sen2)>500 && analogRead(sen1)<500)
  {
    timeScnd = millis();
    diff = timeScnd - timeFirst; 
    velocity = speedConst / diff;
velocity_real = (velocity*360)/100; //milliseconds to hours and centimetres to kilometeres.
    delay(30);
    digitalWrite(ledPin, HIGH);
  Serial.print("\n the velocity is : ");
  Serial.println(velocity_real);
  Serial.print(" km/hr. ");
  delay(500);
  digitalWrite(ledPin,LOW);
  delay(500);
  }
/*else if (analogRead(sen2)500 && analogRead(sen1)500) //uncomment if you want to write it.
  {
      Serial.print("\n Error:404/ the object is tooo big.");
  }*/
 /* else{Serial.print("\n error:404/no object detected ");}     //uncomment if you want to write it.*/
  }

Let’s Test It

It is now time to put the circuit to the test. You can test the speed of various moving items after uploading and turning on the Arduino. Try it out by moving different objects in front of the circuit. Additionally, view the readings on the serial monitor.

Working Explanation

Let’s dive into the coding to better understand how the circuit works:

  • First, we name and define the pins of Arduino that we are using in this project. Then we define some unsigned long and float variables that are being utilized in the code further to store different values.
  • In the void setup, we first initialize the serial monitor, then declare the status as input of two analog pins of Arduino that are connected to the sensors. after that, we make pin 10 as high and pin and pin 11 as low.
  • In the void loop, we give several conditions:
    • If the sensor 1 value is less than 500 and sensor 2 value is greater than 500, the LED will remain low
    • If sensor 2 value is greater than 500 and sensor 1 value is less than 500, the code would measure the velocity, makes LED pin high, print that velocity, then gets paused for a while, and then make LED pin low.
    • If the values of both the sensors are greater than 500 the serial monitor would print Error:404/ the object is tooo big.
    • And, if there’s no event happens that is described above, the serial monitor prints no object detected

Applications

  • To detect the speed of vehicles and automobiles
  • Car speed meters.

Conclusion.

We hope you have found this Arduino speed detector Circuit very useful. If you feel any difficulty in making it feel free to ask anything in the comment section.