-
Notifications
You must be signed in to change notification settings - Fork 1
/
Pre-final code
127 lines (113 loc) · 2.8 KB
/
Pre-final code
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
#include <DHT.h>
#include <NewPing.h>
#define DHTPIN 12
#define DHTTYPE DHT11 // DHT 11 sensor
#define TRIGGER_PIN_IN 6
#define ECHO_PIN_IN 7
#define MAX_DISTANCE_IN 200
#define TRIGGER_PIN_OUT 8
#define ECHO_PIN_OUT 9
#define MAX_DISTANCE_OUT 200
NewPing sonar_in(TRIGGER_PIN_IN, ECHO_PIN_IN, MAX_DISTANCE_IN);
NewPing sonar_out(TRIGGER_PIN_OUT, ECHO_PIN_OUT, MAX_DISTANCE_OUT);
DHT dht(DHTPIN, DHTTYPE);
int count=0;
const int buttonPin = 2; // the number of the pushbutton pin and it Works as a resetter of the counter, will be put in the door's lock
const int ledPin = 13; // the number of the LED pin
void IN()
{
if(digitalRead(buttonPin) == LOW) //funcitons based off of button pulling input pin LOW
{
digitalWrite(ledPin, HIGH);
}
else {
count++;
Serial.print("Person In Room:");
Serial.print(" \t");
Serial.println(count);
if ( count < 0 ) {
count = 0;
}
}
delay(500);
}
void OUT()
{
if(digitalRead(buttonPin) == LOW) //funcitons based off of button pulling input pin LOW
{
digitalWrite(ledPin, HIGH);
}
else {
count--;
Serial.print("Person In Room:");
Serial.print(" \t");
Serial.println(count);
Serial.print('\n');
if ( count < 0 ) {
count = 0;
}
}
delay(500);
}
void setup()
{
pinMode(buttonPin, INPUT); // work as a resetter
pinMode(ledPin, OUTPUT);
Serial.begin(115200);
Serial.println("Number Of People Counter - Measurements Campaign Project_IDP");
Serial.print('\n');
Serial.print('\n');
Serial.print('\n');
delay(1000);
if(digitalRead(buttonPin) == LOW) //funcitons based off of button pulling input pin LOW
{
digitalWrite(ledPin, HIGH);
}
else {
Serial.print("Person In Room:");
Serial.println(count);
if ( count < 0 ) {
count = 0;
}
Serial.print('\n');
}
}
void loop () {
inout ();
temphumidity();
}
void inout()
{
unsigned int uS1 = sonar_in.ping();
int distance1 = uS1 / US_ROUNDTRIP_CM;
if(distance1 != 0 && distance1 <=13){
IN();
}
delay(500);
unsigned int uS2 = sonar_out.ping();
int distance2 = uS2 / US_ROUNDTRIP_CM;
if(distance2 != 0 && distance2 <=13){
OUT();
}
}
void temphumidity () {
if(digitalRead(buttonPin) == LOW) //funcitons based off of button pulling input pin LOW
{
digitalWrite(ledPin, HIGH);
}
else {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print('\n');
delay (500);
}
}