-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIntegrated sensors - SEMI
81 lines (68 loc) · 1.54 KB
/
Integrated sensors - SEMI
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
#include <DHT.h>
#define DHTPIN 12
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
#include <NewPing.h>
#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);
int count=0;
void IN()
{
count++;
Serial.print("Person In Room:");
Serial.println(count);
delay(1000);
}
void OUT()
{
count--;
Serial.print("Person In Room:");
Serial.println(count);
delay(1000);
}
void setup()
{
Serial.begin(115200);
Serial.println("Visitor Counter");
delay(2000);
Serial.print("Person In Room:");
Serial.println(count);
}
void loop () {
inout ();
temphumidity();
}
void inout()
{
unsigned int uS1 = sonar_in.ping();
int distance1 = uS1 / US_ROUNDTRIP_CM;
if(distance1 != 0 && distance1 <=13){
IN();
}
unsigned int uS2 = sonar_out.ping();
int distance2 = uS2 / US_ROUNDTRIP_CM;
if(distance2 != 0 && distance2 <=13){
OUT();
}
}
void temphumidity () {
// Reading temperature or humidity takes about 250 milliseconds!
float h = dht.readHumidity();
// Read temperature as Celsius
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');
// Making a delay time for reducing show speed on Serial monitor
delay (500);
}