Premier envoie
BIN
0.Image/1.Montage_Arduino_DHT22.jpg
Normal file
|
After Width: | Height: | Size: 219 KiB |
BIN
0.Image/2.Graphique_Arduino_DHT22.png
Normal file
|
After Width: | Height: | Size: 110 KiB |
BIN
0.Image/3.Montage_Arduino_LCD.jpg
Normal file
|
After Width: | Height: | Size: 208 KiB |
BIN
0.Image/4.Montage_ESP32_Deux_DHT22.jpg
Normal file
|
After Width: | Height: | Size: 310 KiB |
BIN
0.Image/5.Montage_test_ventilateur.jpg
Normal file
|
After Width: | Height: | Size: 274 KiB |
BIN
0.Image/6.Montage_Arduino_Ventilateur.jpg
Normal file
|
After Width: | Height: | Size: 190 KiB |
BIN
0.Image/7.Test_web_nombre_visiteur.jpg
Normal file
|
After Width: | Height: | Size: 43 KiB |
BIN
0.Image/8.Montage_ESP32_Tachymetre.jpg
Normal file
|
After Width: | Height: | Size: 206 KiB |
36
1_Code_Arduino_DHT22/1_Code_Arduino_DHT22.ino
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
#include <DHT.h>
|
||||||
|
|
||||||
|
#define brocheDeBranchementDHT 6 // Le DHT22 est branché sur le pin D6
|
||||||
|
#define typeDeDHT DHT22
|
||||||
|
DHT dht(brocheDeBranchementDHT, typeDeDHT);
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
// Moniteur série
|
||||||
|
Serial.begin(9600);
|
||||||
|
dht.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
// Lecture des données
|
||||||
|
float tauxHumidite = dht.readHumidity(); // Lecture du taux d'humidité (en %)
|
||||||
|
float tauxTemperature = dht.readTemperature(); // Lecture de la température (en °C)
|
||||||
|
|
||||||
|
// Vérification des données
|
||||||
|
if (isnan(tauxHumidite) || isnan(tauxTemperature)) {
|
||||||
|
Serial.println("Problème DHT");
|
||||||
|
delay(2000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Affichage sur le moniteur série
|
||||||
|
Serial.print(tauxHumidite);
|
||||||
|
Serial.print(",");
|
||||||
|
Serial.print(tauxTemperature);
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
delay(2000);
|
||||||
|
}
|
||||||
61
2_Code_Arduino_LCD/2_Code_Arduino_LCD.ino
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
#include <DHT.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <LiquidCrystal_I2C.h>
|
||||||
|
|
||||||
|
#define brocheDeBranchementDHT 6 // Le DHT22 est branché sur le pin D6
|
||||||
|
#define typeDeDHT DHT22
|
||||||
|
DHT dht(brocheDeBranchementDHT, typeDeDHT);
|
||||||
|
|
||||||
|
LiquidCrystal_I2C lcd(0x27, 16, 2); // Le LCD peut afficher 16 caractères par ligne sur 2 lignes
|
||||||
|
|
||||||
|
// Définition du caractère "°" sur le LCD (tableau 5x8 en binaire)
|
||||||
|
byte Degres[] = {
|
||||||
|
B00111,
|
||||||
|
B00101,
|
||||||
|
B00111,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
lcd.init();
|
||||||
|
lcd.backlight();
|
||||||
|
lcd.createChar(0, Degres); // Création du caractère degrés
|
||||||
|
lcd.clear();
|
||||||
|
|
||||||
|
// Moniteur série
|
||||||
|
Serial.begin(9600);
|
||||||
|
dht.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
// Lecture des données
|
||||||
|
float tauxHumidite = dht.readHumidity(); // Lecture du taux d'humidité (en %)
|
||||||
|
float tauxTemperature = dht.readTemperature(); // Lecture de la température (en °C)
|
||||||
|
|
||||||
|
// Vérification des données
|
||||||
|
if (isnan(tauxHumidite) || isnan(tauxTemperature)) {
|
||||||
|
Serial.println("Problème dht");
|
||||||
|
delay(2000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Affichage sur le LCD
|
||||||
|
lcd.setCursor(3, 0);
|
||||||
|
lcd.print(tauxHumidite);
|
||||||
|
lcd.print(" %RH");
|
||||||
|
lcd.setCursor(4, 1);
|
||||||
|
lcd.print(tauxTemperature);
|
||||||
|
lcd.print(" ");
|
||||||
|
lcd.write(0);
|
||||||
|
lcd.print("C");
|
||||||
|
|
||||||
|
delay(2000);
|
||||||
|
}
|
||||||
63
3_Code_ESP32_LCD/3_Code_ESP32_LCD.ino
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
#include <DHT.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <LiquidCrystal_I2C.h>
|
||||||
|
|
||||||
|
#define brocheDeBranchementDHT 4 // Le DHT22 est branché sur le pin 4
|
||||||
|
#define typeDeDHT DHT22
|
||||||
|
DHT dht(brocheDeBranchementDHT, typeDeDHT);
|
||||||
|
|
||||||
|
LiquidCrystal_I2C lcd(0x27, 16, 2); // Le LCD peut afficher 16 caractères par ligne sur 2 lignes
|
||||||
|
|
||||||
|
// Définition du caractère "°" sur le LCD (tableau 5x8 en binaire)
|
||||||
|
byte Degres[] = {
|
||||||
|
B00111,
|
||||||
|
B00101,
|
||||||
|
B00111,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
Wire.begin(21, 22); // SDA = 21, SCL = 22 (pins par défaut du LCD sur un ESP32)
|
||||||
|
|
||||||
|
lcd.init();
|
||||||
|
lcd.backlight();
|
||||||
|
lcd.createChar(0, Degres); // Création du caractère degrés
|
||||||
|
lcd.clear();
|
||||||
|
|
||||||
|
// Moniteur série
|
||||||
|
Serial.begin(115200);
|
||||||
|
dht.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
// Lecture des données
|
||||||
|
float tauxHumidite = dht.readHumidity(); // Lecture du taux d'humidité (en %)
|
||||||
|
float tauxTemperature = dht.readTemperature(); // Lecture de la température(en °C)
|
||||||
|
|
||||||
|
// Vérification des données
|
||||||
|
if (isnan(tauxHumidite) || isnan(tauxTemperature)) {
|
||||||
|
Serial.println("Problème DHT");
|
||||||
|
delay(2000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Affichage sur le LCD
|
||||||
|
lcd.setCursor(3, 0);
|
||||||
|
lcd.print(tauxHumidite);
|
||||||
|
lcd.print(" %RH");
|
||||||
|
lcd.setCursor(4, 1);
|
||||||
|
lcd.print(tauxTemperature);
|
||||||
|
lcd.print(" ");
|
||||||
|
lcd.write(0);
|
||||||
|
lcd.print("C");
|
||||||
|
|
||||||
|
delay(2000);
|
||||||
|
}
|
||||||
81
4_Code_ESP32_Deux_DHT22/4_Code_ESP32_Deux_DHT22.ino
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
#include <DHT.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <LiquidCrystal_I2C.h>
|
||||||
|
|
||||||
|
#define DHT1 4 // Le premier DHT22 est branché sur le pin 4
|
||||||
|
#define DHT2 18 // Le deuxième DHT22 est branché sur le pin 18
|
||||||
|
#define typeDeDHT DHT22
|
||||||
|
DHT premierdht(DHT1, typeDeDHT);
|
||||||
|
DHT deuxiemedht(DHT2, typeDeDHT);
|
||||||
|
|
||||||
|
LiquidCrystal_I2C lcd(0x27, 16, 2); // Le LCD peut afficher 16 caractères par ligne sur 2 lignes
|
||||||
|
|
||||||
|
// Définition du caractère "°" sur le LCD (tableau 5x8 en binaire)
|
||||||
|
byte Degres[] = {
|
||||||
|
B00111,
|
||||||
|
B00101,
|
||||||
|
B00111,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
Wire.begin(21, 22); // SDA = 21, SCL = 22 (pins par défaut du LCD sur ESP32)
|
||||||
|
|
||||||
|
lcd.init();
|
||||||
|
lcd.backlight();
|
||||||
|
lcd.createChar(0, Degres); // Création du caractère degrés
|
||||||
|
lcd.clear();
|
||||||
|
|
||||||
|
// Moniteur série
|
||||||
|
Serial.begin(92160);
|
||||||
|
premierdht.begin();
|
||||||
|
deuxiemedht.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
// Lecture des données
|
||||||
|
float tauxHumidite1 = premierdht.readHumidity(); // Lecture du taux d'humidité du premier DHT22 (en %)
|
||||||
|
float tauxTemperature1 = premierdht.readTemperature(); // Lecture de la température du premier DHT22 (en °C)
|
||||||
|
|
||||||
|
delay(200); // Attente de 0.2 seconde car sinon les données des deux capteurs se chevauchent
|
||||||
|
|
||||||
|
float tauxHumidite2 = deuxiemedht.readHumidity(); // Lecture du taux d'humidité du deuxième DHT22 (en %)
|
||||||
|
float tauxTemperature2 = deuxiemedht.readTemperature(); // Lecture de la température du deuxième DHT22 (en °C)
|
||||||
|
|
||||||
|
// Vérification des données du premier DHT
|
||||||
|
if (isnan(tauxHumidite1) || isnan(tauxTemperature1)) {
|
||||||
|
Serial.println("Problème DHT1");
|
||||||
|
delay(3000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérification des données du deuxième DHT
|
||||||
|
if (isnan(tauxHumidite2) || isnan(tauxTemperature2)) {
|
||||||
|
Serial.println("Problème DHT2");
|
||||||
|
delay(3000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Affichage sur le LCD
|
||||||
|
lcd.setCursor(0, 0);
|
||||||
|
lcd.print(tauxHumidite1);
|
||||||
|
lcd.print(";");
|
||||||
|
lcd.print(tauxHumidite2);
|
||||||
|
lcd.print(" %RH");
|
||||||
|
lcd.setCursor(1, 1);
|
||||||
|
lcd.print(tauxTemperature1);
|
||||||
|
lcd.print(";");
|
||||||
|
lcd.print(tauxTemperature2);
|
||||||
|
lcd.write(0);
|
||||||
|
lcd.print("C");
|
||||||
|
|
||||||
|
delay(3000);
|
||||||
|
}
|
||||||
94
5_Code_Arduino_Ventilateur/5_Code_Arduino_Ventilateur.ino
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
#include <DHT.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <LiquidCrystal_I2C.h>
|
||||||
|
|
||||||
|
#define brocheDeBranchementDHT 6 // Le DHT22 est branché sur le pin D6
|
||||||
|
#define typeDeDHT DHT22
|
||||||
|
DHT dht(brocheDeBranchementDHT, typeDeDHT);
|
||||||
|
|
||||||
|
int fanPin = 9; // Le ventilateur est branché sur le pin D9
|
||||||
|
int fanSpeed = 0; // La vitesse du ventilateur est 0 par définition
|
||||||
|
|
||||||
|
LiquidCrystal_I2C lcd(0x27, 16, 2); // Le LCD peut afficher 16 caractères par ligne sur 2 lignes
|
||||||
|
|
||||||
|
// Définition du caractère "°" sur le LCD (tableau 5x8 en binaire)
|
||||||
|
byte Degres[] = {
|
||||||
|
B00111,
|
||||||
|
B00101,
|
||||||
|
B00111,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000
|
||||||
|
};
|
||||||
|
|
||||||
|
// Variables pour gestion du temps
|
||||||
|
unsigned long dernierMajDHT = 0; // dernier moment où le DHT a été lu
|
||||||
|
const unsigned long IntervalleDHT = 2000; // Intervalle de lecture DHT en millisecondes
|
||||||
|
|
||||||
|
unsigned long dernierMajFan = 0; // Dernier moment où la vitesse du ventilateur a été mise à jour
|
||||||
|
const unsigned long IntervalleFan = 1000; // Intervalle de mise à jour du ventilateur en millisecondes
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
pinMode(fanPin, OUTPUT);
|
||||||
|
|
||||||
|
lcd.init();
|
||||||
|
lcd.backlight();
|
||||||
|
lcd.createChar(0, Degres); // Création du caractère degrés
|
||||||
|
lcd.clear();
|
||||||
|
|
||||||
|
// Moniteur série
|
||||||
|
Serial.begin(9600);
|
||||||
|
dht.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
unsigned long millisActuels = millis();
|
||||||
|
|
||||||
|
// Lecture DHT toutes les 2 sec
|
||||||
|
if (millisActuels - dernierMajDHT >= IntervalleDHT) {
|
||||||
|
dernierMajDHT = millisActuels;
|
||||||
|
|
||||||
|
// Lecture des données
|
||||||
|
float tauxHumidite = dht.readHumidity(); // Lecture du taux d'humidité (en %)
|
||||||
|
float tauxTemperature = dht.readTemperature(); // Lecture de la température (en °C)
|
||||||
|
|
||||||
|
// Vérification des données
|
||||||
|
if (isnan(tauxHumidite) || isnan(tauxTemperature)) {
|
||||||
|
Serial.println("Problème DHT");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Affichage sur le LCD
|
||||||
|
lcd.setCursor(3, 0);
|
||||||
|
lcd.print(tauxHumidite);
|
||||||
|
lcd.print(" %RH");
|
||||||
|
lcd.setCursor(4, 1);
|
||||||
|
lcd.print(tauxTemperature);
|
||||||
|
lcd.print(" ");
|
||||||
|
lcd.write(0);
|
||||||
|
lcd.print("C");
|
||||||
|
|
||||||
|
// Gestion ventilateur
|
||||||
|
if (tauxHumidite >= 30) { // Seuil pour activer le ventilateur (30% d'humidité)
|
||||||
|
|
||||||
|
// Augmentation progressive de la vitesse du ventilateur
|
||||||
|
if (millisActuels - dernierMajFan >= IntervalleFan) {
|
||||||
|
dernierMajFan = millisActuels;
|
||||||
|
if (fanSpeed < 255) {
|
||||||
|
fanSpeed += 100; // Augmentation de la vitesse par étapes de 100 (max 255 pour PWM)
|
||||||
|
if (fanSpeed > 255) fanSpeed = 255;
|
||||||
|
analogWrite(fanPin, fanSpeed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fanSpeed = 0; // Humidité < 30%, ventilateur arrêté
|
||||||
|
analogWrite(fanPin, fanSpeed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
94
6_Code_ESP32_Ventilateur/6_Code_ESP32_Ventilateur.ino
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
#include <DHT.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <LiquidCrystal_I2C.h>
|
||||||
|
|
||||||
|
#define brocheDeBranchementDHT 4 // Le DHT22 est branché sur le pin 4
|
||||||
|
#define typeDeDHT DHT22
|
||||||
|
DHT dht(brocheDeBranchementDHT, typeDeDHT);
|
||||||
|
|
||||||
|
int fanPin = 18; // Le ventilateur est branché sur le pin 18
|
||||||
|
int fanSpeed = 0; // La vitesse du ventilateur est 0 par définition
|
||||||
|
|
||||||
|
LiquidCrystal_I2C lcd(0x27, 16, 2); // Le LCD peut afficher 16 caractères par ligne sur 2 lignes
|
||||||
|
|
||||||
|
// Définition du caractère "°" sur le LCD (tableau 5x8 en binaire)
|
||||||
|
byte Degres[] = {
|
||||||
|
B00111,
|
||||||
|
B00101,
|
||||||
|
B00111,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000
|
||||||
|
};
|
||||||
|
|
||||||
|
// Variables pour gestion du temps
|
||||||
|
unsigned long dernierMajDHT = 0; // dernier moment où le DHT a été lu
|
||||||
|
const unsigned long IntervalleDHT = 2000; // Intervalle de lecture DHT en millisecondes
|
||||||
|
|
||||||
|
unsigned long dernierMajFan = 0; // Dernier moment où la vitesse du ventilateur a été mise à jour
|
||||||
|
const unsigned long IntervalleFan = 1000; // Intervalle de mise à jour du ventilateur en millisecondes
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
pinMode(fanPin, OUTPUT);
|
||||||
|
|
||||||
|
Wire.begin(21, 22); // SDA = 21, SCL = 22 (pins par défaut du LCD sur un ESP32)
|
||||||
|
|
||||||
|
lcd.init();
|
||||||
|
lcd.backlight();
|
||||||
|
lcd.createChar(0, Degres); // Création du caractère degrés
|
||||||
|
lcd.clear();
|
||||||
|
|
||||||
|
// Moniteur série
|
||||||
|
Serial.begin(115200);
|
||||||
|
dht.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
unsigned long millisActuels = millis();
|
||||||
|
|
||||||
|
// Lecture DHT toutes les 2 sec
|
||||||
|
if (millisActuels - dernierMajDHT >= IntervalleDHT) {
|
||||||
|
dernierMajDHT = millisActuels;
|
||||||
|
|
||||||
|
// Lecture des données
|
||||||
|
float tauxHumidite = dht.readHumidity(); // Lecture du taux d'humidité (en %)
|
||||||
|
float tauxTemperature = dht.readTemperature(); // Lecture de la température (en °C)
|
||||||
|
|
||||||
|
// Vérification des données
|
||||||
|
if (isnan(tauxHumidite) || isnan(tauxTemperature)) {
|
||||||
|
Serial.println("Problème DHT");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Affichage sur le LCD
|
||||||
|
lcd.setCursor(3, 0);
|
||||||
|
lcd.print(tauxHumidite);
|
||||||
|
lcd.print(" %RH");
|
||||||
|
lcd.setCursor(4, 1);
|
||||||
|
lcd.print(tauxTemperature);
|
||||||
|
lcd.print(" ");
|
||||||
|
lcd.write(0);
|
||||||
|
lcd.print("C");
|
||||||
|
|
||||||
|
// Gestion ventilateur
|
||||||
|
if (tauxHumidite >= 30) { // Seuil pour activer le ventilateur (30% d'humidité)
|
||||||
|
|
||||||
|
// Augmentation progressive de la vitesse du ventilateur
|
||||||
|
if (millisActuels - dernierMajFan >= IntervalleFan) {
|
||||||
|
dernierMajFan = millisActuels;
|
||||||
|
if (fanSpeed < 255) {
|
||||||
|
fanSpeed += 100; // Augmentation de la vitesse par étapes de 100 (max 255 pour PWM)
|
||||||
|
if (fanSpeed > 255) fanSpeed = 255;
|
||||||
|
analogWrite(fanPin, fanSpeed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fanSpeed = 0; // Humidité < 30%, ventilateur arrêté
|
||||||
|
analogWrite(fanPin, fanSpeed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
103
7_Code_ESP32_PID/7_Code_ESP32_PID.ino
Normal file
|
|
@ -0,0 +1,103 @@
|
||||||
|
#include <DHT.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <LiquidCrystal_I2C.h>
|
||||||
|
#include <PID_v1_bc.h>
|
||||||
|
|
||||||
|
#define brocheDeBranchementDHT 4 // Le DHT22 est branché sur le pin 4
|
||||||
|
#define typeDeDHT DHT22
|
||||||
|
DHT dht(brocheDeBranchementDHT, typeDeDHT);
|
||||||
|
|
||||||
|
int fanPin = 18; // Le ventilateur est branché sur le pin 18
|
||||||
|
|
||||||
|
LiquidCrystal_I2C lcd(0x27, 16, 2); // Le LCD peut afficher 16 caractères par ligne sur 2 lignes
|
||||||
|
|
||||||
|
// Définition du caractère "°" sur le LCD (tableau 5x8 en binaire)
|
||||||
|
byte Degres[] = {
|
||||||
|
B00111,
|
||||||
|
B00101,
|
||||||
|
B00111,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000
|
||||||
|
};
|
||||||
|
|
||||||
|
// Variables pour gestion du temps
|
||||||
|
unsigned long dernierMajDHT = 0; // dernier moment où le DHT a été lu
|
||||||
|
const unsigned long IntervalleDHT = 2000; // Intervalle de lecture DHT en millisecondes
|
||||||
|
|
||||||
|
unsigned long dernierMajPID = 0; // dernier moment où le PID a été lu
|
||||||
|
const unsigned long IntervallePID = 300; // Intervalle de lecture PID en millisecondes
|
||||||
|
|
||||||
|
// Variable PID
|
||||||
|
double Setpoint = 50; // Humidité ciblée
|
||||||
|
double Input;
|
||||||
|
double Output;
|
||||||
|
|
||||||
|
double Kp = 2.5; // Proportionnel
|
||||||
|
double Ki = 4.38; // Intégral
|
||||||
|
double Kd = 0.16; // Dérivé
|
||||||
|
|
||||||
|
PID pid(&Input, &Output, &Setpoint, Kp, Ki, Kd, REVERSE);
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
pinMode(fanPin, OUTPUT);
|
||||||
|
|
||||||
|
Wire.begin(21, 22); // SDA = 21, SCL = 22 (pins par défaut du LCD sur un ESP32)
|
||||||
|
|
||||||
|
lcd.init();
|
||||||
|
lcd.backlight();
|
||||||
|
lcd.createChar(0, Degres); // Création du caractère degrés
|
||||||
|
lcd.clear();
|
||||||
|
|
||||||
|
// Moniteur série
|
||||||
|
Serial.begin(115200);
|
||||||
|
dht.begin();
|
||||||
|
|
||||||
|
pid.SetMode(AUTOMATIC);
|
||||||
|
pid.SetOutputLimits(0, 255); // PMW correspond à une valeur entre 0 et 255
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
unsigned long millisActuels = millis();
|
||||||
|
|
||||||
|
// Lecture DHT toutes les 2 sec
|
||||||
|
if (millisActuels - dernierMajDHT >= IntervalleDHT) {
|
||||||
|
dernierMajDHT = millisActuels;
|
||||||
|
|
||||||
|
// Lecture des données
|
||||||
|
float tauxHumidite = dht.readHumidity(); // Lecture du taux d'humidité (en %)
|
||||||
|
float tauxTemperature = dht.readTemperature(); // Lecture de la température (en °C)
|
||||||
|
|
||||||
|
// Vérification des données
|
||||||
|
if (!isnan(tauxHumidite) && !isnan(tauxTemperature)) {
|
||||||
|
Input = tauxHumidite;
|
||||||
|
|
||||||
|
// Affichage sur le LCD
|
||||||
|
lcd.setCursor(3, 0);
|
||||||
|
lcd.print(tauxHumidite);
|
||||||
|
lcd.print(" %RH");
|
||||||
|
lcd.setCursor(4, 1);
|
||||||
|
lcd.print(tauxTemperature);
|
||||||
|
lcd.print(" ");
|
||||||
|
lcd.write(0);
|
||||||
|
lcd.print("C");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lecture PID toutes les 300 ms
|
||||||
|
if (millisActuels - dernierMajPID >= IntervallePID) {
|
||||||
|
dernierMajPID = millisActuels;
|
||||||
|
|
||||||
|
pid.Compute(); // Calcule PID
|
||||||
|
analogWrite(fanPin, (int)Output);
|
||||||
|
|
||||||
|
Serial.print("Vitesse du ventilateur : ");
|
||||||
|
Serial.println(Output);
|
||||||
|
}
|
||||||
|
}
|
||||||
263
8_Code_Arduino_Web/8_Code_Arduino_Web.ino
Normal file
|
|
@ -0,0 +1,263 @@
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <WebServer.h>
|
||||||
|
#include <DHT.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <LiquidCrystal_I2C.h>
|
||||||
|
#include <PID_v1.h>
|
||||||
|
|
||||||
|
// Nom et mot de passe du Wifi
|
||||||
|
const char* ssid = "coh@bit";
|
||||||
|
const char* password = "lewifidecohabit";
|
||||||
|
|
||||||
|
WebServer server(80); // HTML correspond au port 80
|
||||||
|
|
||||||
|
#define brocheDeBranchementDHT 4 // Le DHT22 est branché sur le pin 4
|
||||||
|
#define typeDeDHT DHT22
|
||||||
|
DHT dht(brocheDeBranchementDHT, typeDeDHT);
|
||||||
|
|
||||||
|
float tauxHumidite = 0;
|
||||||
|
float tauxTemperature = 0;
|
||||||
|
float OutputRPM = 0;
|
||||||
|
|
||||||
|
int fanPin = 18; // Le ventilateur est branché sur le pin 18
|
||||||
|
|
||||||
|
LiquidCrystal_I2C lcd(0x27, 16, 2); // Le LCD peut afficher 16 caractères par ligne sur 2 lignes
|
||||||
|
|
||||||
|
// Définition du caractère "°" sur le LCD (tableau 5x8 en binaire)
|
||||||
|
byte Degres[] = {
|
||||||
|
B00111,
|
||||||
|
B00101,
|
||||||
|
B00111,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000
|
||||||
|
};
|
||||||
|
|
||||||
|
// Variables pour gestion du temps
|
||||||
|
unsigned long dernierMajDHT = 0; // dernier moment où le DHT a été lu
|
||||||
|
const unsigned long IntervalleDHT = 2000; // Intervalle de lecture DHT en millisecondes
|
||||||
|
|
||||||
|
unsigned long dernierMajPID = 0; // dernier moment où le PID a été lu
|
||||||
|
const unsigned long IntervallePID = 300; // Intervalle de lecture PID en millisecondes
|
||||||
|
|
||||||
|
// Variables PID
|
||||||
|
double Setpoint = 50; // Humidité ciblée
|
||||||
|
double Input;
|
||||||
|
double Output;
|
||||||
|
|
||||||
|
double Kp = 1.5; // Proportionnel
|
||||||
|
double Ki = 1; // Intégral
|
||||||
|
double Kd = 0.16; // Dérivé
|
||||||
|
|
||||||
|
PID pid(&Input, &Output, &Setpoint, Kp, Ki, Kd, REVERSE);
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
pinMode(fanPin, OUTPUT);
|
||||||
|
|
||||||
|
Wire.begin(21, 22); // SDA = 21, SCL = 22 (pins par défaut du LCD sur un ESP32)
|
||||||
|
|
||||||
|
lcd.init();
|
||||||
|
lcd.backlight();
|
||||||
|
lcd.createChar(0, Degres); // Création du caractère degrés
|
||||||
|
lcd.clear();
|
||||||
|
|
||||||
|
// Moniteur série
|
||||||
|
Serial.begin(921600);
|
||||||
|
dht.begin();
|
||||||
|
|
||||||
|
pid.SetMode(AUTOMATIC);
|
||||||
|
pid.SetOutputLimits(0, 255); // PMW correspond à une valeur entre 0 et 255
|
||||||
|
|
||||||
|
// Connexion au Wifi local
|
||||||
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
|
// Verification de la connexion
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
delay(1000);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
Serial.print("IP de la carte : ");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
|
// Message de communication client/serveur
|
||||||
|
server.on("/", connexion_Serveur);
|
||||||
|
server.on("/dataDHT", donnees_DHT);
|
||||||
|
server.on("/dataRPM", donnees_RPM);
|
||||||
|
server.on("/setHumidity", donnees_Set_Humidite);
|
||||||
|
server.onNotFound(echec_Connexion);
|
||||||
|
|
||||||
|
server.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
server.handleClient();
|
||||||
|
|
||||||
|
OutputRPM = (Output / 255.0) * 4500.0;
|
||||||
|
|
||||||
|
unsigned long millisActuels = millis();
|
||||||
|
|
||||||
|
// Lecture DHT toutes les 2 sec
|
||||||
|
if (millisActuels - dernierMajDHT >= IntervalleDHT) {
|
||||||
|
dernierMajDHT = millisActuels;
|
||||||
|
|
||||||
|
// Lecture des données
|
||||||
|
tauxHumidite = dht.readHumidity(); // Lecture du taux d'humidité (en %)
|
||||||
|
tauxTemperature = dht.readTemperature(); // Lecture de la température (en °C)
|
||||||
|
|
||||||
|
// Vérification des données
|
||||||
|
if (!isnan(tauxHumidite) && !isnan(tauxTemperature)) {
|
||||||
|
Input = tauxHumidite;
|
||||||
|
|
||||||
|
// Affichage sur le LCD
|
||||||
|
lcd.setCursor(3, 0);
|
||||||
|
lcd.print(tauxHumidite);
|
||||||
|
lcd.print(" %RH");
|
||||||
|
lcd.setCursor(4, 1);
|
||||||
|
lcd.print(tauxTemperature);
|
||||||
|
lcd.print(" ");
|
||||||
|
lcd.write(0);
|
||||||
|
lcd.print("C");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lecture PID toutes les 300 ms
|
||||||
|
if (millisActuels - dernierMajPID >= IntervallePID) {
|
||||||
|
dernierMajPID = millisActuels;
|
||||||
|
|
||||||
|
pid.Compute(); // Calcule PID
|
||||||
|
analogWrite(fanPin, (int)Output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Création page HTML
|
||||||
|
void connexion_Serveur() {
|
||||||
|
|
||||||
|
// Style du texte
|
||||||
|
String html = "<!DOCTYPE html><html>";
|
||||||
|
html += "<head><meta charset=\"UTF-8\">";
|
||||||
|
html += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=yes\">";
|
||||||
|
html += "<style>";
|
||||||
|
html += "body {font-family: bauhaus 93, sans-serif; color: #000; text-align: center;}";
|
||||||
|
html += ".title {font-size: 30px; font-weight: bold; margin: 40px 0 30px;}";
|
||||||
|
html += ".temperature, .humidity, .vitesse {font-size: 40px; font-weight: 300; line-height: 1; margin-bottom: 20px;}";
|
||||||
|
html += ".temperature {color: #00b3ff;}";
|
||||||
|
html += ".humidity {color: #ff404d;}";
|
||||||
|
html += ".vitesse {color: #1eff1e;}";
|
||||||
|
html += ".unit {font-size: 20px; vertical-align: top;}";
|
||||||
|
|
||||||
|
// Style du slider et de la valeur
|
||||||
|
html += "#valeurHumidite {";
|
||||||
|
html += "font-size: 20px;";
|
||||||
|
html += "font-weight: bold;";
|
||||||
|
html += "margin-left: 10px;";
|
||||||
|
html += "color: #ff404d;";
|
||||||
|
html += "cursor: pointer;"; // valeur cliquable
|
||||||
|
html += "}";
|
||||||
|
|
||||||
|
html += "#sliderHumidite {";
|
||||||
|
html += "display: none;"; // Le slider est caché par défaut
|
||||||
|
html += "margin-top: 10px;";
|
||||||
|
html += "margin-left: 100px;";
|
||||||
|
html += "}";
|
||||||
|
|
||||||
|
html += "</style>";
|
||||||
|
html += "<script>";
|
||||||
|
|
||||||
|
// Température et humidité toutes les 2s
|
||||||
|
html += "setInterval(function(){";
|
||||||
|
html += "var xhttp = new XMLHttpRequest();";
|
||||||
|
html += "xhttp.onreadystatechange=function(){";
|
||||||
|
html += "if(this.readyState==4 && this.status==200){";
|
||||||
|
html += "document.getElementById('dht-container').innerHTML=this.responseText;";
|
||||||
|
html += "}};";
|
||||||
|
html += "xhttp.open('GET','/dataDHT',true);";
|
||||||
|
html += "xhttp.send();";
|
||||||
|
html += "},2000);";
|
||||||
|
|
||||||
|
// Vitesse ventilateur toutes les 300ms
|
||||||
|
html += "setInterval(function(){";
|
||||||
|
html += "var xhttp = new XMLHttpRequest();";
|
||||||
|
html += "xhttp.onreadystatechange=function(){";
|
||||||
|
html += "if(this.readyState==4 && this.status==200){";
|
||||||
|
html += "document.getElementById('rpm-container').innerHTML=this.responseText;";
|
||||||
|
html += "}};";
|
||||||
|
html += "xhttp.open('GET','/dataRPM',true);";
|
||||||
|
html += "xhttp.send();";
|
||||||
|
html += "},300);";
|
||||||
|
|
||||||
|
// Fonction pour mettre à jour l'humidité via le slider
|
||||||
|
html += "function updateHumidity() {";
|
||||||
|
html += "var humidity = document.getElementById('sliderHumidite').value;";
|
||||||
|
html += "document.getElementById('valeurHumidite').innerText = humidity + '%';"; // Mise à jour instantanée de l'affichage
|
||||||
|
html += "var xhttp = new XMLHttpRequest();";
|
||||||
|
html += "xhttp.open('GET', '/setHumidity?value=' + humidity, true);";
|
||||||
|
html += "xhttp.send();";
|
||||||
|
html += "}";
|
||||||
|
|
||||||
|
// Fonction pour basculer l'affichage du slider
|
||||||
|
html += "function toggleSlider() {";
|
||||||
|
html += "var slider = document.getElementById('sliderHumidite');";
|
||||||
|
html += "if (slider.style.display === 'none') {";
|
||||||
|
html += " slider.style.display = 'block';"; // Afficher le slider
|
||||||
|
html += "} else {";
|
||||||
|
html += " slider.style.display = 'none';"; // Cacher le slider
|
||||||
|
html += "}";
|
||||||
|
html += "}";
|
||||||
|
|
||||||
|
html += "</script>";
|
||||||
|
html += "</head><body>";
|
||||||
|
html += "<h1 class=\"title\">État de l'armoire</h1>";
|
||||||
|
html += "<div id='dht-container'></div>";
|
||||||
|
html += "<div id='rpm-container'></div>";
|
||||||
|
|
||||||
|
// Affichage de la valeur de l'humidité et du slider
|
||||||
|
html += "<div>";
|
||||||
|
html += "<label for='sliderHumidite'>Humidité cible: </label>";
|
||||||
|
html += "<span id='valeurHumidite' onclick='toggleSlider()'>" + String(Setpoint) + "%</span>";
|
||||||
|
html += "<input type='range' id='sliderHumidite' min='0' max='100' value='" + String(Setpoint) + "' oninput='updateHumidity()'>";
|
||||||
|
html += "</div>";
|
||||||
|
|
||||||
|
html += "</body></html>";
|
||||||
|
|
||||||
|
server.send(200, "text/html", html);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Communication données DHT22 client/serveur
|
||||||
|
void donnees_DHT() {
|
||||||
|
|
||||||
|
String data = "<div class=\"temperature\">" + String(tauxTemperature, 1) + "<span class=\"unit\">°C</span></div>";
|
||||||
|
data += "<div class=\"humidity\">" + String(tauxHumidite, 1) + "<span class=\"unit\">%RH</span></div>";
|
||||||
|
server.send(200, "text/html", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Communication données vitesse ventilateur client/serveur
|
||||||
|
void donnees_RPM() {
|
||||||
|
|
||||||
|
String data = "<div class=\"vitesse\">" + String(OutputRPM, 0) + "<span class=\"unit\">RPM</span></div>";
|
||||||
|
server.send(200, "text/html", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Communication données humidité cible client/serveur
|
||||||
|
void donnees_Set_Humidite() {
|
||||||
|
|
||||||
|
if (server.hasArg("value")) {
|
||||||
|
Setpoint = server.arg("value").toDouble();
|
||||||
|
}
|
||||||
|
server.send(200, "text/plain", "Humidité cible mise à jour");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Communication données page non trouvé client/serveur
|
||||||
|
void echec_Connexion() {
|
||||||
|
|
||||||
|
server.send(404, "text/plain", "Not found");
|
||||||
|
}
|
||||||
289
9_Code_Arduino_Tachymetre/9_Code_Arduino_Tachymetre.ino
Normal file
|
|
@ -0,0 +1,289 @@
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <WebServer.h>
|
||||||
|
#include <DHT.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <LiquidCrystal_I2C.h>
|
||||||
|
#include <PID_v1.h>
|
||||||
|
|
||||||
|
// Nom et mot de passe du Wifi
|
||||||
|
const char* ssid = "coh@bit";
|
||||||
|
const char* password = "lewifidecohabit";
|
||||||
|
|
||||||
|
WebServer server(80); // HTML correspond au port 80
|
||||||
|
|
||||||
|
#define brocheDeBranchementDHT 4 // Le DHT22 est branché sur le pin 4
|
||||||
|
#define typeDeDHT DHT22
|
||||||
|
DHT dht(brocheDeBranchementDHT, typeDeDHT);
|
||||||
|
|
||||||
|
float tauxHumidite = 0;
|
||||||
|
float tauxTemperature = 0;
|
||||||
|
float OutputRPM = 0;
|
||||||
|
|
||||||
|
int fanPin = 18; // Le ventilateur est branché sur le pin 18
|
||||||
|
|
||||||
|
LiquidCrystal_I2C lcd(0x27, 16, 2); // Le LCD peut afficher 16 caractères par ligne sur 2 lignes
|
||||||
|
|
||||||
|
// Définition du caractère "°" sur le LCD (tableau 5x8 en binaire)
|
||||||
|
byte Degres[] = {
|
||||||
|
B00111,
|
||||||
|
B00101,
|
||||||
|
B00111,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000,
|
||||||
|
B00000
|
||||||
|
};
|
||||||
|
|
||||||
|
// Variables pour gestion du temps
|
||||||
|
unsigned long dernierMajDHT = 0; // dernier moment où le DHT a été lu
|
||||||
|
const unsigned long IntervalleDHT = 2000; // Intervalle de lecture DHT en millisecondes
|
||||||
|
|
||||||
|
unsigned long dernierMajPID = 0; // dernier moment où le PID a été lu
|
||||||
|
const unsigned long IntervallePID = 300; // Intervalle de lecture PID en millisecondes
|
||||||
|
|
||||||
|
unsigned long dernierMajTach = 0; // dernier moment où le tachymètre a été lu
|
||||||
|
const unsigned long IntervalleTach = 300; // Intervalle de lecture tachymètre en millisecondes
|
||||||
|
|
||||||
|
// Variables PID
|
||||||
|
double Setpoint = 50; // Humidité ciblée
|
||||||
|
double Input;
|
||||||
|
double Output;
|
||||||
|
|
||||||
|
double Kp = 1.5; // Proportionnel
|
||||||
|
double Ki = 1; // Intégral
|
||||||
|
double Kd = 0.16; // Dérivé
|
||||||
|
|
||||||
|
PID pid(&Input, &Output, &Setpoint, Kp, Ki, Kd, REVERSE);
|
||||||
|
|
||||||
|
const int tachPin = 16; // Pin du tachymètre
|
||||||
|
volatile unsigned long compteImpulsionsTach = 0; // Compteur d'impulsions du tachymètre
|
||||||
|
|
||||||
|
double tachRPM = 0; // RPM mesuré par tachymètre
|
||||||
|
|
||||||
|
|
||||||
|
void IRAM_ATTR tachISR() {
|
||||||
|
compteImpulsionsTach++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
pinMode(fanPin, OUTPUT);
|
||||||
|
|
||||||
|
Wire.begin(21, 22); // SDA = 21, SCL = 22 (pins par défaut du LCD sur ESP32)
|
||||||
|
|
||||||
|
lcd.init();
|
||||||
|
lcd.backlight();
|
||||||
|
lcd.createChar(0, Degres); // Création du caractère degrés
|
||||||
|
lcd.clear();
|
||||||
|
|
||||||
|
// Moniteur série
|
||||||
|
Serial.begin(921600);
|
||||||
|
dht.begin();
|
||||||
|
|
||||||
|
pid.SetMode(AUTOMATIC);
|
||||||
|
pid.SetOutputLimits(0, 255); // PWM correspond à une valeur entre 0 et 255
|
||||||
|
|
||||||
|
// Connexion au Wifi local
|
||||||
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
|
// Vérification de la connexion
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
delay(1000);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
Serial.print("IP de la carte : ");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
|
// Message de communication client/serveur
|
||||||
|
server.on("/", connexion_Serveur);
|
||||||
|
server.on("/dataDHT", donnees_DHT);
|
||||||
|
server.on("/dataRPM", donnees_RPM);
|
||||||
|
server.on("/setHumidity", donnees_Set_Humidite);
|
||||||
|
server.onNotFound(echec_Connexion);
|
||||||
|
|
||||||
|
server.begin();
|
||||||
|
|
||||||
|
// Tachymètre
|
||||||
|
pinMode(tachPin, INPUT_PULLUP);
|
||||||
|
attachInterrupt(digitalPinToInterrupt(tachPin), tachISR, FALLING);
|
||||||
|
dernierMajTach = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
server.handleClient();
|
||||||
|
|
||||||
|
OutputRPM = (Output / 255.0) * 4500.0;
|
||||||
|
|
||||||
|
unsigned long millisActuels = millis();
|
||||||
|
|
||||||
|
// Lecture DHT toutes les 2 sec
|
||||||
|
if (millisActuels - dernierMajDHT >= IntervalleDHT) {
|
||||||
|
dernierMajDHT = millisActuels;
|
||||||
|
|
||||||
|
// Lecture des données
|
||||||
|
tauxHumidite = dht.readHumidity(); // Lecture du taux d'humidité (en %)
|
||||||
|
tauxTemperature = dht.readTemperature(); // Lecture de la température (en °C)
|
||||||
|
|
||||||
|
// Vérification des données
|
||||||
|
if (!isnan(tauxHumidite) && !isnan(tauxTemperature)) {
|
||||||
|
Input = tauxHumidite;
|
||||||
|
|
||||||
|
// Affichage sur le LCD
|
||||||
|
lcd.setCursor(3, 0);
|
||||||
|
lcd.print(tauxHumidite);
|
||||||
|
lcd.print(" %RH");
|
||||||
|
lcd.setCursor(4, 1);
|
||||||
|
lcd.print(tauxTemperature);
|
||||||
|
lcd.print(" ");
|
||||||
|
lcd.write(0);
|
||||||
|
lcd.print("C");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lecture PID toutes les 300 ms
|
||||||
|
if (millisActuels - dernierMajPID >= IntervallePID) {
|
||||||
|
dernierMajPID = millisActuels;
|
||||||
|
|
||||||
|
pid.Compute(); // Calcule PID
|
||||||
|
analogWrite(fanPin, (int)Output);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lecture Tachymètre toutes les 300 ms
|
||||||
|
if (millisActuels - dernierMajTach >= IntervalleTach) {
|
||||||
|
tachRPM = (compteImpulsionsTach * 60000UL) / (IntervalleTach * 2); // 2 implusions par révolution
|
||||||
|
compteImpulsionsTach = 0;
|
||||||
|
dernierMajTach = millisActuels;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Création page HTML
|
||||||
|
void connexion_Serveur() {
|
||||||
|
|
||||||
|
// Style du texte
|
||||||
|
String html = "<!DOCTYPE html><html>";
|
||||||
|
html += "<head><meta charset=\"UTF-8\">";
|
||||||
|
html += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=yes\">";
|
||||||
|
html += "<style>";
|
||||||
|
html += "body {font-family: bauhaus 93, sans-serif; color: #000; text-align: center;}";
|
||||||
|
html += ".title {font-size: 30px; font-weight: bold; margin: 40px 0 30px;}";
|
||||||
|
html += ".temperature, .humidity, .vitesse {font-size: 40px; font-weight: 300; line-height: 1; margin-bottom: 20px;}";
|
||||||
|
html += ".temperature {color: #00b3ff;}";
|
||||||
|
html += ".humidity {color: #ff404d;}";
|
||||||
|
html += ".vitesse {color: #1eff1e;}";
|
||||||
|
html += ".unit {font-size: 20px; vertical-align: top;}";
|
||||||
|
|
||||||
|
// Style du slider et de la valeur
|
||||||
|
html += "#valeurHumidite {";
|
||||||
|
html += "font-size: 20px;";
|
||||||
|
html += "font-weight: bold;";
|
||||||
|
html += "margin-left: 10px;";
|
||||||
|
html += "color: #ff404d;";
|
||||||
|
html += "cursor: pointer;"; // valeur cliquable
|
||||||
|
html += "}";
|
||||||
|
|
||||||
|
html += "#sliderHumidite {";
|
||||||
|
html += "display: none;"; // Le slider est caché par défaut
|
||||||
|
html += "margin-top: 10px;";
|
||||||
|
html += "margin-left: 100px;";
|
||||||
|
html += "}";
|
||||||
|
|
||||||
|
html += "</style>";
|
||||||
|
html += "<script>";
|
||||||
|
|
||||||
|
// Température et humidité toutes les 2s
|
||||||
|
html += "setInterval(function(){";
|
||||||
|
html += "var xhttp = new XMLHttpRequest();";
|
||||||
|
html += "xhttp.onreadystatechange=function(){";
|
||||||
|
html += "if(this.readyState==4 && this.status==200){";
|
||||||
|
html += "document.getElementById('dht-container').innerHTML=this.responseText;";
|
||||||
|
html += "}};";
|
||||||
|
html += "xhttp.open('GET','/dataDHT',true);";
|
||||||
|
html += "xhttp.send();";
|
||||||
|
html += "},2000);";
|
||||||
|
|
||||||
|
// Vitesse ventilateur toutes les 300ms
|
||||||
|
html += "setInterval(function(){";
|
||||||
|
html += "var xhttp = new XMLHttpRequest();";
|
||||||
|
html += "xhttp.onreadystatechange=function(){";
|
||||||
|
html += "if(this.readyState==4 && this.status==200){";
|
||||||
|
html += "document.getElementById('rpm-container').innerHTML=this.responseText;";
|
||||||
|
html += "}};";
|
||||||
|
html += "xhttp.open('GET','/dataRPM',true);";
|
||||||
|
html += "xhttp.send();";
|
||||||
|
html += "},300);";
|
||||||
|
|
||||||
|
// Fonction pour mettre à jour l'humidité via le slider
|
||||||
|
html += "function updateHumidity() {";
|
||||||
|
html += "var humidity = document.getElementById('sliderHumidite').value;";
|
||||||
|
html += "document.getElementById('valeurHumidite').innerText = humidity + '%';"; // Mise à jour instantanée de l'affichage
|
||||||
|
html += "var xhttp = new XMLHttpRequest();";
|
||||||
|
html += "xhttp.open('GET', '/setHumidity?value=' + humidity, true);";
|
||||||
|
html += "xhttp.send();";
|
||||||
|
html += "}";
|
||||||
|
|
||||||
|
// Fonction pour basculer l'affichage du slider
|
||||||
|
html += "function toggleSlider() {";
|
||||||
|
html += "var slider = document.getElementById('sliderHumidite');";
|
||||||
|
html += "if (slider.style.display === 'none') {";
|
||||||
|
html += " slider.style.display = 'block';"; // Afficher le slider
|
||||||
|
html += "} else {";
|
||||||
|
html += " slider.style.display = 'none';"; // Cacher le slider
|
||||||
|
html += "}";
|
||||||
|
html += "}";
|
||||||
|
|
||||||
|
html += "</script>";
|
||||||
|
html += "</head><body>";
|
||||||
|
html += "<h1 class=\"title\">État de l'armoire</h1>";
|
||||||
|
html += "<div id='dht-container'></div>";
|
||||||
|
html += "<div id='rpm-container'></div>";
|
||||||
|
|
||||||
|
// Affichage de la valeur de l'humidité et du slider
|
||||||
|
html += "<div>";
|
||||||
|
html += "<label for='sliderHumidite'>Humidité cible: </label>";
|
||||||
|
html += "<span id='valeurHumidite' onclick='toggleSlider()'>" + String(Setpoint) + "%</span>";
|
||||||
|
html += "<input type='range' id='sliderHumidite' min='0' max='100' value='" + String(Setpoint) + "' oninput='updateHumidity()'>";
|
||||||
|
html += "</div>";
|
||||||
|
|
||||||
|
html += "</body></html>";
|
||||||
|
|
||||||
|
server.send(200, "text/html", html);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Communication données DHT22 client/serveur
|
||||||
|
void donnees_DHT() {
|
||||||
|
|
||||||
|
String data = "<div class=\"temperature\">" + String(tauxTemperature, 1) + "<span class=\"unit\">°C</span></div>";
|
||||||
|
data += "<div class=\"humidity\">" + String(tauxHumidite, 1) + "<span class=\"unit\">%RH</span></div>";
|
||||||
|
server.send(200, "text/html", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Communication données vitesse ventilateur client/serveur
|
||||||
|
void donnees_RPM() {
|
||||||
|
|
||||||
|
String data = "<div class=\"vitesse\">" + String(tachRPM, 0) + "<span class=\"unit\">RPM</span></div>";
|
||||||
|
data += "<div style='font-size:16px;color:#000;'>Vitesse cible: <span style='font-size:20px;color:#1eff1e;'>" + String(OutputRPM,0) + " RPM</span></div>";
|
||||||
|
server.send(200, "text/html", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Communication données humidité cible client/serveur
|
||||||
|
void donnees_Set_Humidite() {
|
||||||
|
|
||||||
|
if (server.hasArg("value")) {
|
||||||
|
Setpoint = server.arg("value").toDouble();
|
||||||
|
}
|
||||||
|
server.send(200, "text/plain", "Humidité cible mise à jour");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Communication données page non trouvée client/serveur
|
||||||
|
void echec_Connexion() {
|
||||||
|
|
||||||
|
server.send(404, "text/plain", "Not found");
|
||||||
|
}
|
||||||
71
Test_Serveur_Web_ESP32/Test_Serveur_Web_ESP32.ino
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <WebServer.h>
|
||||||
|
|
||||||
|
// Nom et mot de passe du Wifi
|
||||||
|
const char* ssid = "coh@bit";
|
||||||
|
const char* password = "lewifidecohabit";
|
||||||
|
|
||||||
|
WebServer server(80); // HTML correspond au port 80
|
||||||
|
|
||||||
|
int nombre_visite = 0;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
Serial.println("Connexion à ");
|
||||||
|
Serial.println(ssid);
|
||||||
|
|
||||||
|
// Connexion au Wifi local
|
||||||
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
|
// Verification si le Wifi est connecté à internet
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
delay(1000);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
Serial.println("");
|
||||||
|
Serial.println("Wifi Connecté");
|
||||||
|
Serial.print("IP : ");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
|
server.on("/", handle_OnConnect);
|
||||||
|
server.onNotFound(handle_NotFound);
|
||||||
|
|
||||||
|
server.begin();
|
||||||
|
Serial.println("Server HTTP en marche");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
server.handleClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle_OnConnect() {
|
||||||
|
nombre_visite++;
|
||||||
|
server.send(200, "text/html", createHTML());
|
||||||
|
}
|
||||||
|
|
||||||
|
//Création page d'erreur
|
||||||
|
void handle_NotFound() {
|
||||||
|
server.send(404, "text/plain", "Not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Création page HTML
|
||||||
|
String createHTML() {
|
||||||
|
String html = "<!DOCTYPE html> <html>";
|
||||||
|
html += "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=yes\">";
|
||||||
|
html += "<style>";
|
||||||
|
html += "body {font-family: Arial, sans-serif; color: #444; text-align: center;}";
|
||||||
|
html += ".title {font-size: 30px; font-weight: bold; letter-spacing: 2px; margin: 80px 0 55px;}";
|
||||||
|
html += ".nombre_visite {font-size: 80px; font-weight: 300; line-height: 1; margin: 0px; color: #4285f4;}";
|
||||||
|
html += "</style>";
|
||||||
|
html += "</head>";
|
||||||
|
html += "<body>";
|
||||||
|
html += "<h1 class=\"title\">NOMBRE DE VISITEUR</h1>";
|
||||||
|
html += "<div class=\"nombre_visite\">";
|
||||||
|
html += nombre_visite;
|
||||||
|
html += "</div>";
|
||||||
|
html += "</body>";
|
||||||
|
html += "</html>";
|
||||||
|
return html;
|
||||||
|
}
|
||||||
26
Teste_ventilateur/Teste_ventilateur.ino
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
int fanPin = 9; // Le ventilateur est branché sur le pin D9
|
||||||
|
|
||||||
|
// Définition du pin D9 comme sortie
|
||||||
|
void setup() {
|
||||||
|
pinMode(fanPin, OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Le ventilateur fonctionne en boucle
|
||||||
|
void loop() {
|
||||||
|
for (int i = 0; i <= 255; i++) { // 0 correspond à aucun signal et 255 au maximum
|
||||||
|
analogWrite(fanPin, 10);
|
||||||
|
delay(1000);
|
||||||
|
analogWrite(fanPin, 100);
|
||||||
|
delay(1000);
|
||||||
|
analogWrite(fanPin, 175);
|
||||||
|
delay(1000);
|
||||||
|
analogWrite(fanPin, 255);
|
||||||
|
delay(2000);
|
||||||
|
analogWrite(fanPin, 175);
|
||||||
|
delay(1000);
|
||||||
|
analogWrite(fanPin, 100);
|
||||||
|
delay(1000);
|
||||||
|
analogWrite(fanPin, 10);
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||