-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVelocityMeasurementSystem.ino
More file actions
99 lines (77 loc) · 1.58 KB
/
VelocityMeasurementSystem.ino
File metadata and controls
99 lines (77 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//Developed by Edgar Mendonca
//Set distance between the two sensors: 50mm
#include<Wire.h> //I2C Communication library
#include <LiquidCrystal_I2C.h> //LCD with I2C library
LiquidCrystal_I2C lcd(0x27,16,2);
int S1 = A2; //Analog Pin 2
int S2 = A3; //Analog Pin3
int val1; //Value Store fn1
int val2; //value Store fn2
int threshold;
unsigned long time1, time2;
float Time, Speed;
byte customChar[] = {
B00000,
B00100,
B01010,
B10001,
B10001,
B10001,
B11111,
B00000
};
void setup()
{
Serial.begin(9600);
pinMode (S1, INPUT);
pinMode (S2, INPUT);
val1 = digitalRead(S1);
val2 = digitalRead(S2);
threshold = (((val1+val2)/2)+45);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.clear();
lcd.createChar(0, customChar);
lcd.home();
lcd.write(0);
lcd.setCursor(1,0);
lcd.print("t=");
lcd.setCursor(0, 1);
lcd.print("V =");
}
void loop()
{
val1 = analogRead(S1);
val2 = analogRead(S2);
while(val1<=threshold)
{
val1 = analogRead(S1);
}
while(val1>threshold)
{
time1 = micros();
val1 = analogRead(S1);
}
while(val2<=threshold)
{
val2 = analogRead(S2);
}
while(val2>threshold)
{
time2 = micros();
val2 = analogRead(S2);
}
Time = time2 - time1;
Speed = (50000/Time); //50mm - Distance between two sensors
Serial.print(Time);
Serial.println(Speed);
lcd.setCursor(3,0);
lcd.print(Time);
lcd.setCursor(12,0);
lcd.print("us");
lcd.setCursor(3,1);
lcd.print(Speed);
lcd.setCursor(8,1);
lcd.print("m/s");
}