Skip to content

Instantly share code, notes, and snippets.

@elktros
Created December 27, 2018 05:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elktros/4e02e271299016f7cd0fa823dc7ec7d4 to your computer and use it in GitHub Desktop.
Save elktros/4e02e271299016f7cd0fa823dc7ec7d4 to your computer and use it in GitHub Desktop.
Code for Arduino Car Speed Detector Project.
#include <LiquidCrystal.h>
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int sen1=11;
int sen2=12;
unsigned long t1=0;
unsigned long t2=0;
float velocity;
void setup()
{
lcd.begin(16, 2);
pinMode(sen1,INPUT);
pinMode(sen2,INPUT);
Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print(" Speed Detector ");
}
void loop()
{
while(digitalRead(sen1));
while(digitalRead(sen1)==0);
t1=millis();
while(digitalRead(sen2));
t2=millis();
velocity=t2-t1;
velocity=velocity/1000;//convert millisecond to second
velocity=(5.0/velocity);//v=d/t
velocity=velocity*3600;//multiply by seconds per hr
velocity=velocity/1000;//division by meters per Km
for(int i=5;i>0;i
{
lcd.setCursor(3,1);
lcd.print(velocity);
lcd.print(" Km/hr ");
delay(500);
lcd.setCursor(3,1);
lcd.print(" ");
delay(500);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment