-
Notifications
You must be signed in to change notification settings - Fork 0
/
Counter.c
174 lines (156 loc) · 5.98 KB
/
Counter.c
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include <SoftwareSerial.h>
SoftwareSerial s(4,7);
int ldr_min_val = 400;
int sensor1= 0;
int sensor2= 0;
int sensor3= 0;
int sensor4= 0;
int step_old= 10;
int steps = 10;
int step_old1= 10;
int steps1 = 10;
int pulse_count1 = 0;
int person_count = 0;
int pulse_count = 0;
int person_count1 = 0;
int total_person = 0;
int ldr1 = A0;
int ldr2 = A1;
int ldr3 = A2;
int ldr4 = A3;
int ldr1_value = 0;
int ldr2_value = 0;
int ldr3_value = 0;
int ldr4_value = 0;
void setup()
{
Serial.begin(9600);
s.begin(9600);
pinMode(ldr1,INPUT);
pinMode(ldr2,INPUT);
pinMode(ldr3,INPUT);
pinMode(ldr4,INPUT);
}
void loop()
{
ldr1_value = analogRead(ldr1);
ldr2_value = analogRead(ldr2);
ldr3_value = analogRead(ldr3);
ldr4_value = analogRead(ldr4);
Serial.println(ldr1_value);
Serial.println(ldr2_value);
Serial.println(ldr3_value);
Serial.println(ldr4_value);
if(ldr1_value < ldr_min_val)
{
sensor1 = 1;
}
else{
sensor1 = 0;
}
if(ldr2_value < ldr_min_val)
{ sensor2 = 1; }
else{
sensor2 = 0;
}
if(ldr3_value < ldr_min_val)
{ sensor3 = 1;
}else{
sensor3 = 0;
}
if(ldr4_value < ldr_min_val)
{ sensor4 = 1;
}
else{
sensor4 = 0;
}
if(sensor1 == 1 && sensor2 == 1){
steps = 0;
if(step_old == 1){
pulse_count-- ;
}
if(step_old == 3){
pulse_count++;
}
step_old = 0;
}
if(sensor1 == 0 && sensor2 == 1){
steps = 1;
if(step_old == 2){
pulse_count--;
}
if(step_old == 0){
pulse_count++;
}
step_old = 1;
}
if(sensor1 == 0 && sensor2 == 0){
steps = 2;
if(step_old == 3){
pulse_count--;
}
if(step_old == 1){
pulse_count++;
}
step_old = 2;
}
if(sensor1 == 1 && sensor2 == 0){
steps = 3;
if(step_old == 0){
pulse_count--;
}
if(step_old == 2){
pulse_count++;
}
step_old = 3;
}
if(sensor3 == 1 && sensor4 == 1){
steps1 = 0;
if(step_old1 == 1){
pulse_count1-- ;
}if(step_old1 == 3){
pulse_count1++;
}step_old1 = 0;
} if(sensor3 == 0 && sensor4 == 1){
steps1 = 1;
if(step_old1 == 2){
pulse_count1--;}
if(step_old1 == 0){
pulse_count1++;
}step_old1 = 1;
}if(sensor3 == 0 && sensor4 == 0){
steps1 = 2;
if(step_old1 == 3){
pulse_count1--;}
if(step_old1 == 1){
pulse_count1++;}
step_old1 = 2;
}if(sensor3 == 1 && sensor4 == 0){
steps1 = 3;
if(step_old1 == 0){
pulse_count1--;}
if(step_old1 == 2){
pulse_count1++;}
step_old1 = 3;}
if(pulse_count<0){
if(pulse_count1<= 0){
pulse_count = 0;
}
}
if(pulse_count1<0){
if(pulse_count<= 0){
pulse_count1 = 0;
}
}
person_count = pulse_count/4;
person_count1 = pulse_count1/4;
total_person = 0 ;
total_person= person_count + person_count1;
Serial.print(" number of people in the bus");
Serial.println(total_person);
if(s.available()>0)
{
s.write(total_person);
delayMicroseconds(200);
}
}