Measurement of Motor Speed and Displacement of Vehicle using IR Module with
ARDUINO UNO
***THEORY
IR SENSOR
An infrared sensor circuit is one of the basic and popular sensor module in an electronic device. This
sensor is analogous to human’s visionary senses, which can be used to detect obstacles and it is one of the
common applications in real time.This circuit comprises of the following components
IR LED
There are different types of infrared transmitters depending on their wavelengths, output power and
response time.
A simple infrared transmitter can be constructed using an infrared LED, a current limiting resistor and a
power supply.
IR Transmitter
When operated at a supply of 5V, the IR transmitter consumes about 3 to 5 mA of current. Infrared
transmitters can be modulated to produce a particular frequency of infrared light. The most commonly
used modulation is OOK (ON – OFF – KEYING) modulation.
IR transmitters can be found in several applications. Some applications require infrared heat and the best
infrared source is infrared transmitter. When infrared emitters are used with Quartz, solar cells can be
made.
IR Receiver
Infrared receivers are also called as infrared sensors as they detect the radiation from an IR transmitter. IR
receivers come in the form of photodiodes and phototransistors. Infrared Photodiodes are different from
normal photo diodes as they detect only infrared radiation. The picture of a typical IR receiver or a
photodiode is shown below.
Principle of Working
The principle of an IR sensor working as an Object Detection Sensor can be explained using the
following figure. An IR sensor consists of an IR LED and an IR Photodiode; together they are called as
Photo – Coupler or Opto – Coupler.
Working principle of IR sensor
When the IR transmitter emits radiation, it reaches the object and some of the radiation reflects back to
the IR receiver. Based on the intensity of the reception by the IR receiver, the output of the sensor is
defined.
STEPS:
I.
I.Count time elapsed for passing of one slot
I.I. Store current value of millis()** in p if object detected i.e. digitalRead(2)==0
I.II. Wait for full slot to pass i.e. digitalRead(2)==1 by using do-while loop
I.III. Time elapsed=current time-p
II. Calculate RPM from time elapsed
II.I. (1/10)rev -> Time elapsed
1 rev -> 10*Time elapsed
II.II. 10*Time elapsed -> 1rev
1min=60000ms -> RPM
RPM=60000/(10*time elapsed)
III. Calculate average of RPM for 1sec
IV. Calculate distance covered in every 1sec
IV.I. RPS=RPM/60
IV.II. Dist(in 1sec)=RPS*circumference
Dist(in 1sec)=aa=RPM*2*3.14*r/60
Calculate total distance by
Distance =Distance+aa(i.e. dist. In 1 sec)
V. Display Distance and RPM on LCD
**millis() is a function that returns the amount of milliseconds that have passed since program start.
CODE:
#include <Wire.h> //library for I2C /TWI communication
#include <LiquidCrystal_I2C.h> //library for controlling LCDs
LiquidCrystal_I2C lcd(0x27, 20, 4); //set the LCD to address 0x27
void setup() {
pinMode(2, INPUT); //pin 2 receiving i/p from ir sensor
Serial.begin(9600);
lcd.init(); //initializing LCD display
lcd.backlight();
}
int x = 0; //variable declaration
long p, q, time_elapsed, rpm, rpmsum, actualrpm, distance, aa;
void loop() {
x = 0;
rpmsum = 0;
q = millis();
do {
rpmsum = rpmsum + getrpm(); //adding RPMs for 1sec
++x; //No. Of times RPMs added
} while (millis() <= q + 1000); //execution of do-while loop for 1sec
actualrpm = rpmsum / x; //taking average of RPMs
aa = 2 * 3.14 * 4 * actualrpm / 60; //distance covered in one sec
distance = distance + aa; //total distance covered
lcd.clear(); //LCD display statements
lcd.setCursor(0, 0);
lcd.print("RPM=");
lcd.print(actualrpm);
lcd.setCursor(0, 1);
lcd.print("DISP=");
lcd.print(distance);
}
long getrpm() //function to calculate instantaneous RPM
{
if (digitalRead(2) == 0) //object detected
{ p = millis();
do {
time_elapsed = millis() - p;
if (time_elapsed > 1000) //de accleration
return 0;
} while (digitalRead(2) == 0); //again object
}
else //object not detected
{
p = millis();
do {
time_elapsed = millis() - p;
if (time_elapsed > 1000) //de accleration
return 0;
} while (digitalRead(2) == 1); //object not detected
}
rpm = 60000 / (time_elapsed * 10); //instantaneous RPM calculation
return rpm;
}
ARDUINO UNO
***THEORY
IR SENSOR
An infrared sensor circuit is one of the basic and popular sensor module in an electronic device. This
sensor is analogous to human’s visionary senses, which can be used to detect obstacles and it is one of the
common applications in real time.This circuit comprises of the following components
IR LED
There are different types of infrared transmitters depending on their wavelengths, output power and
response time.
A simple infrared transmitter can be constructed using an infrared LED, a current limiting resistor and a
power supply.
IR Transmitter
When operated at a supply of 5V, the IR transmitter consumes about 3 to 5 mA of current. Infrared
transmitters can be modulated to produce a particular frequency of infrared light. The most commonly
used modulation is OOK (ON – OFF – KEYING) modulation.
IR transmitters can be found in several applications. Some applications require infrared heat and the best
infrared source is infrared transmitter. When infrared emitters are used with Quartz, solar cells can be
made.
IR Receiver
Infrared receivers are also called as infrared sensors as they detect the radiation from an IR transmitter. IR
receivers come in the form of photodiodes and phototransistors. Infrared Photodiodes are different from
normal photo diodes as they detect only infrared radiation. The picture of a typical IR receiver or a
photodiode is shown below.
Principle of Working
The principle of an IR sensor working as an Object Detection Sensor can be explained using the
following figure. An IR sensor consists of an IR LED and an IR Photodiode; together they are called as
Photo – Coupler or Opto – Coupler.
Working principle of IR sensor
When the IR transmitter emits radiation, it reaches the object and some of the radiation reflects back to
the IR receiver. Based on the intensity of the reception by the IR receiver, the output of the sensor is
defined.
STEPS:
I.
I.Count time elapsed for passing of one slot
I.I. Store current value of millis()** in p if object detected i.e. digitalRead(2)==0
I.II. Wait for full slot to pass i.e. digitalRead(2)==1 by using do-while loop
I.III. Time elapsed=current time-p
II. Calculate RPM from time elapsed
II.I. (1/10)rev -> Time elapsed
1 rev -> 10*Time elapsed
II.II. 10*Time elapsed -> 1rev
1min=60000ms -> RPM
RPM=60000/(10*time elapsed)
III. Calculate average of RPM for 1sec
IV. Calculate distance covered in every 1sec
IV.I. RPS=RPM/60
IV.II. Dist(in 1sec)=RPS*circumference
Dist(in 1sec)=aa=RPM*2*3.14*r/60
Calculate total distance by
Distance =Distance+aa(i.e. dist. In 1 sec)
V. Display Distance and RPM on LCD
**millis() is a function that returns the amount of milliseconds that have passed since program start.
CODE:
#include <Wire.h> //library for I2C /TWI communication
#include <LiquidCrystal_I2C.h> //library for controlling LCDs
LiquidCrystal_I2C lcd(0x27, 20, 4); //set the LCD to address 0x27
void setup() {
pinMode(2, INPUT); //pin 2 receiving i/p from ir sensor
Serial.begin(9600);
lcd.init(); //initializing LCD display
lcd.backlight();
}
int x = 0; //variable declaration
long p, q, time_elapsed, rpm, rpmsum, actualrpm, distance, aa;
void loop() {
x = 0;
rpmsum = 0;
q = millis();
do {
rpmsum = rpmsum + getrpm(); //adding RPMs for 1sec
++x; //No. Of times RPMs added
} while (millis() <= q + 1000); //execution of do-while loop for 1sec
actualrpm = rpmsum / x; //taking average of RPMs
aa = 2 * 3.14 * 4 * actualrpm / 60; //distance covered in one sec
distance = distance + aa; //total distance covered
lcd.clear(); //LCD display statements
lcd.setCursor(0, 0);
lcd.print("RPM=");
lcd.print(actualrpm);
lcd.setCursor(0, 1);
lcd.print("DISP=");
lcd.print(distance);
}
long getrpm() //function to calculate instantaneous RPM
{
if (digitalRead(2) == 0) //object detected
{ p = millis();
do {
time_elapsed = millis() - p;
if (time_elapsed > 1000) //de accleration
return 0;
} while (digitalRead(2) == 0); //again object
}
else //object not detected
{
p = millis();
do {
time_elapsed = millis() - p;
if (time_elapsed > 1000) //de accleration
return 0;
} while (digitalRead(2) == 1); //object not detected
}
rpm = 60000 / (time_elapsed * 10); //instantaneous RPM calculation
return rpm;
}