/* ============================================
code is placed under the MIT license
Copyright (c) 2026 J-M-L
For the Arduino Forum : https://forum.arduino.cc/u/j-m-l
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
===============================================
*/
#include <Wire.h>
#include <hd44780.h> // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
#include <Toggle.h> // https://github.com/Dlloydev/Toggle
#include <OneWire.h>
#include <DallasTemperature.h>
const uint8_t nbCols = 20;
const uint8_t nbRows = 4;
hd44780_I2Cexp lcd;
const byte pinLedHP = 11;
const byte pinLedPC = 12;
const byte pinLedECS = 13;
const byte pinBuzzer = 9;
const byte pinBoutonSilence = 3;
const byte pinLedSilence = 2;
Toggle boutonSilence(pinBoutonSilence);
const byte pinBus = 7;
OneWire busOneWire(pinBus);
DallasTemperature capteurs(&busOneWire);
const uint8_t resolution = 9; // 9, 10, 11 ou 12 bits
uint32_t derniereLecture = 0;
struct Capteur {
const char * nom;
DeviceAddress adresse;
float derniereTemperature;
bool besoinAffichage;
};
// Pour wokwi on a ces adresses
Capteur lesCapteurs[] = {
{"EHP", {0x28, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x7E}, 0.0, true}, // 0 - Eau Haut Poêle
{"EBP", {0x28, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0xDE}, 0.0, true}, // 1 - Eau Bas Poêle
{"HCP", {0x28, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0xBE}, 0.0, true}, // 2 - Haut Cuve Poêle
{"BCP", {0x28, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x87}, 0.0, true}, // 3 - Bas Cuve Poêle
{"PC ", {0x28, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xE7}, 0.0, true}, // 4 - PC
{"ECS", {0x28, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x47}, 0.0, true}, // 5 - ECS
};
constexpr byte nbCapteursTemperature = sizeof lesCapteurs / sizeof * lesCapteurs;
const uint32_t demiPeriodeClignotement = 250;
const float seuilHP = 50.0;
const byte indiceHP = 0;
const float seuilPC = 50.0;
const byte indicePC = 4;
const float seuilECS = 50.0;
const uint8_t indiceECS = 5;
enum : uint8_t {AUCUNE_ALARME = 0, ALARME_HP = 1, ALARME_PC = 2, ALARME_ECS = 4};
uint8_t alarmesEnCours = AUCUNE_ALARME; // les bits définissent les alarmes actives
void animations() {
static bool modeSilence = false;
static uint32_t debutModeSilence = 0;
static const uint32_t dureeModeSilence = 10000ul; // 10 secondes en ms
boutonSilence.poll();
if (boutonSilence.onPress()) {
modeSilence = not modeSilence;
digitalWrite(pinLedSilence, modeSilence ? HIGH : LOW);
if (modeSilence) debutModeSilence = millis();
}
if (modeSilence && millis() - debutModeSilence >= dureeModeSilence) {
modeSilence = false;
digitalWrite(pinLedSilence, LOW);
}
if (lesCapteurs[indiceHP].derniereTemperature >= seuilHP) {
static uint32_t chrono = 0;
if (millis() - chrono >= 100) {
digitalWrite(pinLedHP, digitalRead(pinLedHP) == HIGH ? LOW : HIGH);
chrono = millis();
}
alarmesEnCours |= ALARME_HP;
} else {
digitalWrite(pinLedHP, LOW);
alarmesEnCours &= ~ALARME_HP;
}
if (lesCapteurs[indicePC].derniereTemperature >= seuilPC) {
static uint32_t chrono = 0;
if (millis() - chrono >= 100) {
digitalWrite(pinLedPC, digitalRead(pinLedPC) == HIGH ? LOW : HIGH);
chrono = millis();
}
alarmesEnCours |= ALARME_PC;
} else {
digitalWrite(pinLedPC, LOW);
alarmesEnCours &= ~ALARME_PC;
}
if (lesCapteurs[indiceECS].derniereTemperature >= seuilECS) {
static uint32_t chrono = 0;
if (millis() - chrono >= 100) {
digitalWrite(pinLedECS, digitalRead(pinLedECS) == HIGH ? LOW : HIGH);
chrono = millis();
}
alarmesEnCours |= ALARME_ECS;
} else {
digitalWrite(pinLedECS, LOW);
alarmesEnCours &= ~ALARME_ECS;
}
if (not modeSilence && alarmesEnCours != AUCUNE_ALARME) {
// une alarme au moins est en cours et on n'est pas en mode silence
digitalWrite(pinBuzzer, HIGH);
} else {
digitalWrite(pinBuzzer, LOW);
}
}
void rechercheCapteurs() {
DeviceAddress adresse;
busOneWire.reset_search();
byte idx = 0;
while (busOneWire.search(adresse)) {
Serial.print("Capteur ");
Serial.print(idx);
Serial.print(" adresse = {");
for (byte j = 0; j < sizeof adresse; j++) {
Serial.print("0x");
if (adresse[j] < 16) Serial.print("0");
Serial.print(adresse[j], HEX);
if (j < (sizeof adresse) - 1) Serial.print(", ");
}
Serial.println("}");
idx++;
}
}
bool mettreAJourTemperatures() {
if (millis() - derniereLecture <= capteurs.millisToWaitForConversion(resolution)) return false; // conversion non terminée, on sort
bool modif = false;
for (byte i = 0; i < nbCapteursTemperature; i++) {
float t = capteurs.getTempC(lesCapteurs[i].adresse);
if (!isnan(t) && (isnan(lesCapteurs[i].derniereTemperature) || abs(t - lesCapteurs[i].derniereTemperature) >= 0.1)) {
lesCapteurs[i].derniereTemperature = t;
lesCapteurs[i].besoinAffichage = true;
modif = true;
}
}
capteurs.requestTemperatures(); // relance la prochaine conversion
derniereLecture = millis();
return modif;
}
void setup() {
pinMode (pinLedHP, OUTPUT); digitalWrite(pinLedHP, LOW);
pinMode (pinLedPC, OUTPUT); digitalWrite(pinLedPC, LOW);
pinMode (pinLedECS, OUTPUT); digitalWrite(pinLedECS, LOW);
pinMode (pinBuzzer, OUTPUT); digitalWrite(pinBuzzer, LOW);
pinMode (pinLedSilence, OUTPUT); digitalWrite(pinLedSilence, LOW);
boutonSilence.begin(pinBoutonSilence);
Serial.begin(115200);
int result = lcd.begin(nbCols, nbRows);
if (result) {
Serial.print("LCD initialization failed: ");
Serial.println(result);
hd44780::fatalError(result);
}
lcd.setCursor(0, 0);
lcd.print("GESTION TEMPERATURE");
for (uint8_t n = 0; n < nbCapteursTemperature; n++) {
lcd.setCursor((n < nbRows - 1) ? 0 : nbCols / 2, n % (nbRows - 1) + 1);
lcd.print(lesCapteurs[n].nom);
lcd.write(':');
}
capteurs.begin();
rechercheCapteurs();
capteurs.setResolution(resolution);
capteurs.setWaitForConversion(false);
capteurs.requestTemperatures();
derniereLecture = millis();
Serial.println("PRET");
}
void loop() {
if (mettreAJourTemperatures()) { // retourne vrai si au moins une t° a été mise à jour
for (byte n = 0; n < nbCapteursTemperature; n++) {
if (lesCapteurs[n].besoinAffichage) {
uint8_t col = (n < nbRows - 1) ? 4 : nbCols / 2 + 4;
uint8_t ligne = n % (nbRows - 1) + 1;
lcd.setCursor(col, ligne );
lcd.print(" "); // on efface l'ancienne valeur
lcd.setCursor(col, ligne );
lcd.print(lesCapteurs[n].derniereTemperature, 1);
lesCapteurs[n].besoinAffichage = false;
}
}
}
animations();
}
Loading
ds18b20
ds18b20
Loading
ds18b20
ds18b20
Loading
ds18b20
ds18b20
Loading
ds18b20
ds18b20
Loading
ds18b20
ds18b20
Loading
ds18b20
ds18b20
Eau Haut Poêle
Eau Bas Poêle
Haut Cuve Poêle
Bas Cuve Poêle
PC
ECS
SILENCE
BUZZER