yashastronomy
Published

Arduino speed detector

Super easy project using an arduino uno to detect speed of various moving objects with the help of a pair of IR sensors and get the speed.

BeginnerFull instructions provided26,848
Arduino speed detector

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
preferable to use with resistors.
×1
IR proximity sensor
go to the link to buy.
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

here is the circuit schematic

the wires are a bit jumbled. And use the IR sensors whose link is given in the components section and not the one in the CAD.

Test_Video

A Video showcasing a test run of the project. the speed gets printed in the serial monitor.

Code

speed_detection101

Arduino
here's the code for the speed detector.just upload to arduino after doing the circuitry. sen1 is the first sensors .sen2 is the second.led pin is the pin to the RGB led.The seperation between my sensors was 7.5 cms. you can adjust the speedconst variable for the same.
//code by YaSh.

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.*/
  }

Credits

yashastronomy

yashastronomy

0 projects • 16 followers

Comments