-
Notifications
You must be signed in to change notification settings - Fork 0
/
Infant-incubator.ino
243 lines (192 loc) · 6.1 KB
/
Infant-incubator.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
const char DEVICE_LOGIN_NAME[] = "b82b11fb-cbf4-4848-bfc6-376fee48c3d5";
const char SSID[] = "POCO PHONE"; // Network SSID (name)
const char PASS[] = "Prince@61299"; // Network password (use for WPA, or use as key for WEP)
const char DEVICE_KEY[] = "5F6KMYELMHBV0BIGENKJ"; // Secret device password
//variable decleration
CloudHeartRate heartrate;
CloudTemperatureSensor temperature;
CloudTemperatureSensor bodyTemp;
int CO2;
CloudRelativeHumidity humidity;
void initProperties() {
ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
ArduinoCloud.addProperty(heartrate, READ, ON_CHANGE, NULL);
ArduinoCloud.addProperty(temperature, READ, ON_CHANGE, NULL);
ArduinoCloud.addProperty(bodyTemp, READ, ON_CHANGE, NULL);
ArduinoCloud.addProperty(CO2, READ, ON_CHANGE, NULL);
ArduinoCloud.addProperty(humidity, READ, ON_CHANGE, NULL);
}
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
//LCD library
#include <Wire.h> // include the Wire library for I2C communication
#include <LiquidCrystal_I2C.h> // include the LiquidCrystal_I2C library for LCD screen
// Define the I2C address for the LCD screen
#define LCD_ADDRESS 0x27
// Define the number of columns and rows for the LCD screen
#define LCD_COLUMNS 16
#define LCD_ROWS 4
// Create an instance of the LiquidCrystal_I2C class
LiquidCrystal_I2C lcd(LCD_ADDRESS, LCD_COLUMNS, LCD_ROWS);
//bodyTemp library
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 4 // Data pin connected to the DS18B20 sensor with GPIO4 of esp32
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
//include DHT library
#include "DHT.h"
#define DHTPIN 15 //Connect DHT!! data pin with the D15 of the ESP32
#define DHTTYPE DHT11
//Pulse Rate pin
const int PULSE_SENSOR_PIN = 36; // Connect the Signal pin with VP (GPIO 36) with ESP32
//MQ135 sensor pin out
const int GAS_SENSOR_PIN = 39; // connect the A0 pin of MQ135 with the VN (GPIO 39) with ESP32
//define the LEDs pin
const int redLEDPin = 18;
const int greenLEDPin = 5;
const int buzzerPin = 19;
//DHT11 Temperate sensor object
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
pinMode(redLEDPin, OUTPUT);
pinMode(greenLEDPin, OUTPUT);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500); //1500 milisecond
// Initialize the I2C communication
Wire.begin();
// Initialize the LCD screen
lcd.init();
// Turn on the backlight of the LCD screen
lcd.backlight();
// Print a message on the LCD screen
lcd.setCursor(0, 0);
lcd.print("Major Project 2023");
lcd.setCursor(0, 1);
lcd.print("------------------------");
lcd.setCursor(0, 2);
lcd.print("Guided By:");
lcd.setCursor(0, 3);
lcd.print("Dr. Sharmila");
delay(3000); //delay for 3 sec
lcd.clear(); //to clear lcd
lcd.setCursor(0, 1);
lcd.print(" IoT Based");
lcd.setCursor(0, 2);
lcd.print(" Infant Incubator ");
delay(3000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("1. Aditya Verma");
lcd.setCursor(0, 1);
lcd.print("2. Mitanshi Gaur");
lcd.setCursor(0, 2);
lcd.print("3. Pintu Kumar");
lcd.setCursor(0, 3);
lcd.print("4. Prince Kushwaha");
delay(3000);
lcd.clear();
//................................................
dht.begin(); //to start dht11 sensor
sensors.begin(); //to start bodyTemp sensor
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
LCD_MESSAGE();
CO2_SENSOR_READ();
DHT_SENSOR_READ();
PULSE_RATE_READ();
BODYTEMP_SENSOR_VALUE();
ALERT_SENSOR_VALUE();
}
// code for temp and humidity
void DHT_SENSOR_READ() {
float h = dht.readHumidity();
//read temperature as Celsius
float t = dht.readTemperature();
temperature = t;
humidity = h;
Serial.print("Temperature: ");
Serial.println(t);
Serial.print("Humidity: ");
Serial.println(h);
}
//code for heart rate
void PULSE_RATE_READ() {
int pulse_value = analogRead(PULSE_SENSOR_PIN); // Read the pulse sensor value
int p = pulse_value / 25; //to calibrate
heartrate = p;
Serial.print("Pulse Rate: ");
Serial.println(p); // Print the pulse sensor value to the serial monitor
}
//code for MQ135 sensor (co2 detection)
void CO2_SENSOR_READ() {
int sensorValue = analogRead(GAS_SENSOR_PIN);
int c = sensorValue / 5; //to calibrate
CO2 = c;
Serial.print("CO2 Contn.: ");
Serial.print(c);
Serial.println(" PPM");
}
//body temp
void BODYTEMP_SENSOR_VALUE() {
sensors.requestTemperatures();
float tempC = sensors.getTempCByIndex(0);
float tempF = (tempC * 9.0 / 5.0) + 32.0;
bodyTemp = tempF;
Serial.print("Temperature in Celsius: ");
Serial.print(tempC);
Serial.print(" °C, Temperature in Fahrenheit: ");
Serial.print(tempF);
Serial.println(" °F");
}
//To ptint the values on LCD
void LCD_MESSAGE() {
//print values on LCD
lcd.setCursor(0, 0);
lcd.print("Temperature: ");
lcd.print(temperature);
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(humidity);
lcd.print(" %");
lcd.setCursor(0, 2);
lcd.print("CO2 Conctn: ");
lcd.print(CO2);
lcd.print(" PPM");
delay(2000); //delay for 2 second
lcd.clear(); //to clear the lcd
lcd.setCursor(0, 1);
lcd.print("Body Temp: ");
lcd.print(bodyTemp);
lcd.print(" F");
lcd.setCursor(0, 2);
lcd.print("Pulse Rate ");
lcd.print(heartrate);
delay(2000); //delay for 2 second
lcd.clear(); //to clear the lcd
}
//alert code
void ALERT_SENSOR_VALUE() {
if (bodyTemp >= 100 || CO2 >= 700 || temperature >= 50 || heartrate > 180) {
digitalWrite(redLEDPin, HIGH);
digitalWrite(buzzerPin, HIGH);
digitalWrite(greenLEDPin, LOW);
} else {
digitalWrite(greenLEDPin, HIGH);
digitalWrite(redLEDPin, LOW);
digitalWrite(buzzerPin, LOW);
}
}