0% found this document useful (0 votes)
82 views4 pages

IR Speed Sensor Arduino Project

Uploaded by

djizzy13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views4 pages

IR Speed Sensor Arduino Project

Uploaded by

djizzy13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

instructables

IR Speed Sensor - Arduino Project

by IEEE BITS Pilani

A speed gun is a simple application device used to nd out speeding cars in the real world. A small-scale prototype
version based on IR sensors is presented in this project. Using buzzers, it will also alert the user if the speed is beyond a
certain threshold.
The concept is rudimentary: The IR sensors capture the time di erence at which they capture the moving object and nd
the velocity using the formula v=s/t.

This project is for beginners who want to explore what can be done using an Arduino. It helps integrate the basic
functions of an input device: IR sensor and output devices: LCD and Buzzer.
Supplies:

Arduino UNO Board


2 x IR Sensors
I2C LCD
Buzzer
Jumper Wires
Breadboard

[Link]

Step 1: Circuit Diagram

IR Sensors :
Sensor 1 Output Pin -> D2
Sensor 1 GND Pin -> GND
Sensor 1 VCC Pin -> 5V
Sensor 2 Output Pin -> D3
Sensor 2 GND Pin -> GND
Sensor 2 VCC Pin -> 5V
LCD (With I2C) :
IR Speed Sensor - Arduino Project: Page 1
SDA Pin -> A4 Pin
SCL Pin -> A5 Pin
VCC Pin -> 5V
GND Pin -> GND
Buzzer :
Positive Pin -> D5
Negative Pin -> GND

Step 2: Code

After making the connections, open up the Arduino IDE:


Download
Web Editor

Download the following libraries if doing on your local machine:


Wire.h
I2C LCD

Copy-paste the code. You can understand this by reading the comments and see how the algorithm is working.

IR Speed Sensor - Arduino Project: Page 2


#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define sensorPin1 2
#define sensorPin2 3
#define buzzerPin 5

const float dist = 0.07;


bool sensor1State = false;
bool sensor2State = false;
unsigned long interval = 0;
unsigned long startTime = 0;
double speed = 0;
const int timeout = 3000;

LiquidCrystal_I2C lcd(0x27, 20, 4);


void setup() {
pinMode(sensorPin1, INPUT);
pinMode(sensorPin2, INPUT);
pinMode(buzzerPin, OUTPUT);

[Link](9600);

[Link]();
[Link]();
[Link](0, 0);
[Link]("Speed (kmph):");

void loop() {
// put your main code here, to run repeatedly:
sensor1State = digitalRead(sensorPin1);
digitalWrite(buzzerPin, LOW);
startTime = 0;
if(!sensor1State){
startTime = millis();
while (digitalRead(sensorPin2)){
if(millis()-startTime > timeout){
[Link](0, 1);
[Link]("Timeout");
return;
}
delay(3);
}
interval = millis() - startTime;
if(interval > 3){
[Link]("Speed in kmph = ");
speed = ((dist)/(interval/1000.0)) * (18/5.0);
[Link](speed);
[Link](0, 1);
[Link](speed);
[Link](" ");
if(speed > 1){
digitalWrite(buzzerPin, HIGH);
}

}
delay(1000);
}

//[Link](digitalRead(sensorPin1));
}

IR Speed Sensor - Arduino Project: Page 3


Step 3: Explanation

1. The code starts by including the required libraries for the project. The Wire.h library is used for
communication with the I2C LCD and the LiquidCrystal_I2C.h library allows for easy interfacing with the
I2C LCD.
2. The pin numbers for the sensors and buzzer are de ned using #de ne. Then, variables are declared for
the state, capturing time from the hardware clock as well as the distance between the sensors, the speed
of the vehicle and the speed limit.
3. The LiquidCrystal_I2C object is created with the I2C address of the LCD (0x27), the number of columns
(20) and the number of rows (4). The setup() function is then called, where the pins are initialised as input
or output pins, and the LCD is initialised.
4. In the loop() function, the state of sensor 1 and sensor 2 is checked using digitalRead(). If a sensor is
triggered (i.e. the state is HIGH), the corresponding time is noted. The millis function gives the time on the
clock.
5. Once both sensors have been triggered, the time taken by the vehicle is calculated and multiplied by
0.001 (to convert to seconds). The speed of the vehicle is then calculated by dividing the distance
between the sensors by the time taken, and multiplying by 3.6 (to convert to km/h).
6. The speed is then printed to the LCD using [Link]() and [Link](). Finally, if the speed exceeds the
speed limit, the buzzer is turned on using digitalWrite(). Otherwise, the buzzer is turned o .
7. Along with this, A timeout is added to ensure that if the object doesn’t pass through the other sensor
within the threshold limit, the state of sensor is reset.

Overall, this project is a simple yet e ective way to measure the speed of an object using two IR sensors and an I2C LCD.

IR Speed Sensor - Arduino Project: Page 4

You might also like