-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeraV2.ino
152 lines (118 loc) · 4.08 KB
/
HeraV2.ino
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
#include <ESP8266WiFi.h>
#include<FirebaseArduino.h>
#include <ArduinoJson.h>
//
// Copyright 2015 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// FirebaseDemo_ESP8266 is a sample that demo the different functions
// of the FirebaseArduino API.
static const uint8_t D0 = 2;
static const uint8_t D1 = 4;
static const uint8_t D2 = 3;
static const uint8_t D6 = 7;
static const uint8_t D8 = 8;
#include <ArduinoJson.h>
#include <DHT.h>
#define DHT_PIN D6
#define DHTTYPE DHT11 // Initialize dht type as DHT 11
DHT dht(DHT_PIN, DHTTYPE);
// Set these to run example.
#define FIREBASE_HOST "https://cpi-project-b42b5-default-rtdb.firebaseio.com/"
#define FIREBASE_AUTH "K58KQNBK2d0jyOJy2NQ9Mbdk6V6VVYgwkoDfoeWA"
#define PROJECT_ID "cpi-project-b42b5"
#define WIFI_SSID "INGENIUMS-AP"
#define WIFI_PASSWORD "ingeniums$2022"
float mov;
void setup() {
// Serial.begin(256000);
Serial.begin(115200);
//Serial.begin(9600);
dht.begin();
pinMode(D1, OUTPUT);
pinMode(D0, OUTPUT);
pinMode(D8, INPUT);
pinMode(D2, INPUT);
pinMode(D6, INPUT);
//std::shared_ptr<StaticJsonDocument<FIREBASE_JSONDOCUMENT_SIZE>> buffer_;
// connect to wifi.
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.pushInt("MOVE_SENSOR", 0);
Firebase.pushInt("SON_SENSOR", 0);
}
int n1 = 0;
int n2 = 0;
int n3 = 0;
int n4 = 0;
void loop() {
//==============================*Movement Sensor*====================================================
mov = digitalRead(D2);
if(mov == 1){
Serial.print("Mouvemenet : ");
Serial.println(mov);
digitalWrite(D0, HIGH);
Firebase.pushInt("MOVE_SENSOR", 1);
}
else{
Serial.print("Mouvemenet : ");
Serial.println(mov);
Serial.println("no move");
digitalWrite(D0, LOW);
Firebase.pushInt("MOVE_SENSOR",0);
}
//===========================================================================================
//==============================*Sound Sensor*====================================================
n4 = digitalRead(D8);
if(n4 >=50){
Serial.print("Son : ");
Serial.println(n4);
digitalWrite(D1, HIGH);
Firebase.pushInt("SON_SENSOR", 1);
}
else{
Serial.print("Son : ");
Serial.println(n4);
Serial.println("pas de son");
digitalWrite(D1, LOW);
Firebase.pushInt("SON_SENSOR", 0);
}
//===========================================================================================
//==============================*DHT11 Sensor*====================================================
dht.read(DHT_PIN);
int temperature = dht.readTemperature();
Serial.print("Temperature : ");
Serial.println(temperature);
Firebase.setInt("DHT11_SENSOR", temperature);
Firebase.setInt("DHT11_SENSOR_GRAPH", temperature);
if (temperature >=28){
Serial.println("Temperature notification : on ");
Firebase.setInt("TEMPERATURE_NOTIFY", 1);
delay(1000);
}
else{
Firebase.setInt("TEMPERATURE_NOTIFY", 0);
delay(1000);
}
delay(1000);
//===========================================================================================
}