#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
int inputPin = 7; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0;
#define ECHO_PIN 4
#define TRIG_PIN 3
#include "DHT.h"
#include "Servo.h"
#define DHTPIN 2
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
Servo myservo;
int tension;
int buzzerPin= 8;
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
pinMode(13, OUTPUT);
pinMode(buzzerPin, OUTPUT);
dht.begin();
myservo.attach(5);
lcd.init();
lcd.backlight();
// Print something
lcd.setCursor(1, 0);
lcd.print("$$$marhaban$$$");
lcd.setCursor(1, 1);
lcd.print("$$$$projet MP$$$$$");
lcd.setCursor(1, 2);
lcd.print("$$$$$$$M1IST$$$$$$$");
lcd.setCursor(1, 3);
lcd.print("KWN MONITOR ");
pinMode(inputPin, INPUT);
delay(5000);
lcd.clear();
}
void loop() {
// affichage de de la
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
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 {
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;
}
}
tension=analogRead(A0);
tension= map(tension,0,1023,6,22);
Serial.print("la tension de ce patient est: ");
Serial.println(tension);
// activation poseringe
if ((tension>17||tension<8)&&pirState == LOW)
{
myservo.write(90);
delay(500);
myservo.write(0);
Serial.println("le patient non surveillé");
}
// affichage de distance
float distance = readDistanceCM();
if (distance>100)
tone(buzzerPin, 1000, 500);
{
Serial.println("le patient est en risque");
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("le patient");
lcd.setCursor(3, 1);
lcd.print("en risque");
delay(1000);
lcd.clear();
}
Serial.print("Measured distance: ");
Serial.println(readDistanceCM());
// affichage de TH
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
if (isnan(temperature) || isnan(humidity)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// put your main code here, to run repeatedly:
digitalWrite(13, HIGH);
delay(300);
digitalWrite(13, LOW);
delay(300);
digitalWrite(buzzerPin, HIGH);
delay(100);
digitalWrite(buzzerPin,LOW);
delay(100);
Serial.print(F("Humidity: "));
Serial.print(humidity);
Serial.print(F("% Temperature: "));
Serial.print(temperature);
Serial.println(F("°C "));
lcd.setCursor(1, 0);
lcd.print("tension:");
lcd.setCursor(10, 0);
lcd.print(tension);
lcd.setCursor(1, 1);
lcd.print("Distance:");
lcd.setCursor(10, 1);
lcd.print(distance);
lcd.setCursor(1, 2);
lcd.print("Humidity:");
lcd.setCursor(10, 2);
lcd.print(humidity);
lcd.setCursor(1, 3);
lcd.print("Temperature:");
lcd.setCursor(14, 3);
lcd.print(temperature);
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;
}