-
Notifications
You must be signed in to change notification settings - Fork 1
/
FINAAAAL Code
119 lines (105 loc) · 2.17 KB
/
FINAAAAL 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
#include <DHT.h>
#define DHTPIN 8
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
#include <NewPing.h>
#define TRIGGER_PIN_IN 9
#define ECHO_PIN_IN 10
#define MAX_DISTANCE_IN 200
#define TRIGGER_PIN_OUT 11
#define ECHO_PIN_OUT 12
#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);
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
int count = 0;
int piezoelectric = 1;
void IN()
{
if ( piezoelectric = 1) {
count++;
lcd.setCursor(0, 0);
lcd.print("N:");
lcd.setCursor(4, 0);
lcd.print(count);
lcd.setCursor(7, 0);
lcd.print("Persons");
}
if ( count < 0 ) {
count = 0;
lcd.clear();
}
delay(1000);
}
void OUT()
{
if ( piezoelectric = 1) {
count--;
lcd.setCursor(0, 0);
lcd.print("N:");
lcd.setCursor(4, 0);
lcd.print(count);
lcd.setCursor(7, 0);
lcd.print("Persons");
}
if ( count < 0 ) {
count = 0;
lcd.clear();
}
delay(1000);
}
void setup()
{
if ( piezoelectric = 1) {
Serial.print(9600);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("N:");
lcd.setCursor(4, 0);
lcd.print(count);
lcd.setCursor(7, 0);
lcd.print("Persons");
}
if ( count < 0 ) {
count = 0;
lcd.clear();
}
delay(250);
}
void loop () {
inout ();
temphumid();
}
void inout () {
unsigned int uS1 = sonar_in.ping();
int distance1 = uS1 / US_ROUNDTRIP_CM;
if(distance1 != 0 && distance1 <=40){
IN();
}
unsigned int uS2 = sonar_out.ping();
int distance2 = uS2 / US_ROUNDTRIP_CM;
if(distance2 != 0 && distance2 <=40){
OUT();
}
}
// Start of reading temperature and humidity
void temphumid ()
{
int h = dht.readHumidity();
// Read temperature as Celsius (the default)
int t = dht.readTemperature();
lcd.setCursor(0, 1);
lcd.print("H:");
lcd.setCursor(3, 1);
lcd.print(h);
lcd.setCursor(5, 1);
lcd.print("%");
lcd.setCursor(8, 1);
lcd.print("T:");
lcd.setCursor(11, 1);
lcd.print(t);
lcd.setCursor(14, 1);
lcd.print("*C");
delay (500);
}