Saturday, November 23, 2024

Arduino IDE

Arduino Code Viewer with Project Details

Arduino Speed Detection System

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); //Enter your address of your I2C Module it will be different for you

int timer1;
int timer2;

float Time;

int flag1 = 0;
int flag2 = 0;

float distance = 5.0;
float speed;

int ir_s1 = 34;
int ir_s2 = 35;

int buzzer = 13;

void setup(){
  Serial.begin(115200);  
  pinMode(ir_s1, INPUT);
  pinMode(ir_s2, INPUT);
  pinMode(buzzer, OUTPUT);
  
  lcd.begin();
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(" Welcome To ");
  lcd.setCursor(0,1);
  lcd.print("Harshan  Project");
  delay(2000);
  lcd.clear();
}

void loop() {

if(digitalRead (ir_s1) == LOW && flag1==0){timer1 = millis(); flag1=1;}

if(digitalRead (ir_s2) == LOW && flag2==0){timer2 = millis(); flag2=1;}

if (flag1==1 && flag2==1){
     if(timer1 > timer2){Time = timer1 - timer2;}
else if(timer2 > timer1){Time = timer2 - timer1;}
 Time=Time/1000;//convert millisecond to second
 speed=(distance/Time);//v=d/t
 speed=speed*3600;//multiply by seconds per hr
 speed=speed/1000;//division by meters per Km 
 
}

if(speed==0){ 
lcd.setCursor(0, 1); 
if(flag1==0 && flag2==0){lcd.print("No car  detected");}
                    else{lcd.print("Searching...    ");} 
}
else{
    lcd.clear(); 
    lcd.setCursor(0, 0); 
    lcd.print("Speed:");
    lcd.print(speed,1);
    lcd.print("Km/Hr  ");
    lcd.setCursor(0, 1); 
  if(speed > 50){lcd.print("  Over Speeding  "); digitalWrite(buzzer, HIGH);}
            else{lcd.print("  Normal Speed   "); }    
    delay(3000);
    digitalWrite(buzzer, LOW);
    speed = 0;
    flag1 = 0;
    flag2 = 0;    
 }
}
    

Project Details

Project Title: Speed Detection System with LCD Display and Buzzer
Overview: This project detects the speed of an object (like a vehicle) using two infrared sensors. The time between sensor interruptions is used to calculate the speed, which is displayed on an LCD screen. If the speed exceeds 50 km/h, a buzzer is triggered to alert the user.
Hardware Required:
If you want to purchase the Required items, use the below links to purchase via Amazon.com
Key Concepts: The system uses infrared sensors to measure the time taken by an object to pass between them, then calculates its speed using the formula: Speed = Distance / Time. The result is displayed on the LCD, and a buzzer is triggered if the object exceeds a threshold speed.

Watch the Project Video