#include "DHT.h"
#include "Servo.h"
#include <LiquidCrystal_I2C.h>
int ledPin = 13; // choose the pin for the LED
int inputPin = 5; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
#define ECHO_PIN 4
#define TRIG_PIN 3
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
Servo myservo;
String etat;
#define DHTPIN 2
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
int bpm=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println(F("DHT22 example!"));
myservo.attach(8);
myservo.write (0);
dht.begin();
pinMode(8, OUTPUT);
lcd.init();
lcd.backlight();
// Print something
lcd.setCursor(7, 0);
lcd.print("Welcome");
lcd.setCursor(8, 1);
lcd.print("M1IST");
lcd.setCursor(2, 2);
lcd.print("MULTIPARA MONITOR");
lcd.setCursor(6, 3);
lcd.print("SNL INNOV");
delay(10000);
lcd.clear();
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
}
void loop() {
// put your main code here, to run repeatedly:
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// Check if any reads failed and exit early (to try again).
if (isnan(temperature) || isnan(humidity)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
delay(2000);
// display the above for two seconds
}
humidity = dht.readHumidity();
temperature= dht.readTemperature();
Serial.print(F("Humidity: "));
Serial.print(humidity);
Serial.print(F("% Temperature: "));
Serial.print(temperature);
Serial.println(F("°C "));
float distance = readDistanceCM();
Serial.print("Measured distance: ");
Serial.println(readDistanceCM());
bpm=analogRead(A0);
bpm=map(bpm,0,1023,6,22);
Serial.println(bpm);
if (bpm>17)
{
etat="critique";
myservo.write(90);
delay(100);
myservo.write(0);}
else{
etat="normal";
}
lcd.setCursor(0, 0);
lcd.print("T:");
lcd.setCursor(2, 0);
lcd.print(temperature);
lcd.setCursor(9, 0);
lcd.print("D:");
lcd.setCursor(11, 0);
lcd.print(distance);
lcd.setCursor(1, 1);
lcd.print("Hum:");
lcd.setCursor(7, 1);
lcd.print(humidity);
lcd.setCursor(1, 2);
lcd.print("Tension:");
lcd.setCursor(9, 2);
lcd.print(bpm);
lcd.setCursor(1, 3);
lcd.print("etat:");
lcd.setCursor(7, 3);
lcd.print(etat);
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH) {
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}}
delay(1000);
}
float readDistanceCM() {
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
int duration = pulseIn(ECHO_PIN, HIGH);
return duration * 0.034 / 2;
}