voilà un exemple à étudier, finalement il n'y avait pas vraiment besoin de machine à état.
le nom du capteur c'est 3 lettres - je compte la dessus pour l'affichage sur le LCD - qui se présentera comme suit :
comme dans l'autre wokwi, vous pouvez changer les valeurs d'une sonde en cliquant dessus et en faisant bouger son curseur de T°.
N'hésitez pas si vous avez des questions.
les détails
/* ============================================
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", {0x10, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x9B}, 0.0, true}, // 0 - Eau Haut Poêle
{"EBP", {0x10, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x3B}, 0.0, true}, // 1 - Eau Bas Poêle
{"HCP", {0x10, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x5B}, 0.0, true}, // 2 - Haut Cuve Poêle
{"BCP", {0x10, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x62}, 0.0, true}, // 3 - Bas Cuve Poêle
{"PC ", {0x10, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x02}, 0.0, true}, // 4 - PC
{"ECS", {0x10, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0xA2}, 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 unsigned int frequenceBuzzHP = 800; // Hz
const float seuilPC = 50.0;
const byte indicePC = 4;
const unsigned int frequenceBuzzPC = 1000; // Hz
const float seuilECS = 50.0;
const uint8_t indiceECS = 5;
const unsigned int frequenceBuzzECS = 1200; // Hz
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 lastBlink;
if (millis() - lastBlink >= demiPeriodeClignotement) {
digitalWrite(pinLedHP, digitalRead(pinLedHP) == HIGH ? LOW : HIGH);
if (not modeSilence) tone(pinBuzzer, frequenceBuzzHP, demiPeriodeClignotement / 4);
lastBlink = millis();
}
} else {
digitalWrite(pinLedHP, LOW);
noTone(pinBuzzer);
}
if (lesCapteurs[indicePC].derniereTemperature >= seuilPC) {
static uint32_t lastBlink;
if (millis() - lastBlink >= demiPeriodeClignotement) {
digitalWrite(pinLedPC, digitalRead(pinLedPC) == HIGH ? LOW : HIGH);
if (not modeSilence) tone(pinBuzzer, frequenceBuzzPC, demiPeriodeClignotement / 4);
lastBlink = millis();
}
} else {
digitalWrite(pinLedPC, LOW);
noTone(pinBuzzer);
}
if (lesCapteurs[indiceECS].derniereTemperature >= seuilECS) {
static uint32_t lastBlink;
if (millis() - lastBlink >= demiPeriodeClignotement) {
digitalWrite(pinLedECS, digitalRead(pinLedECS) == HIGH ? LOW : HIGH);
if (not modeSilence) tone(pinBuzzer, frequenceBuzzECS, demiPeriodeClignotement / 4);
lastBlink = millis();
}
} else {
digitalWrite(pinLedECS, LOW);
noTone(pinBuzzer);
}
}
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();
}
{
"version": 1,
"author": "Copyright (c) 2026 J-M-L",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-uno", "id": "uno", "top": 221.4, "left": -10.2, "attrs": {} },
{
"type": "board-ds18b20",
"id": "temp4",
"top": -180.48,
"left": 65.47,
"rotate": 270,
"attrs": { "deviceID": "111111111111" }
},
{
"type": "board-ds18b20",
"id": "temp5",
"top": -142.08,
"left": 65.47,
"rotate": 270,
"attrs": { "deviceID": "222222222222" }
},
{
"type": "board-ds18b20",
"id": "temp6",
"top": -103.68,
"left": 65.47,
"rotate": 270,
"attrs": { "deviceID": "333333333333" }
},
{
"type": "board-ds18b20",
"id": "temp7",
"top": -65.28,
"left": 65.47,
"rotate": 270,
"attrs": { "deviceID": "444444444444" }
},
{
"type": "board-ds18b20",
"id": "temp8",
"top": -26.88,
"left": 65.47,
"rotate": 270,
"attrs": { "deviceID": "555555555555" }
},
{
"type": "board-ds18b20",
"id": "temp9",
"top": 11.52,
"left": 65.47,
"rotate": 270,
"attrs": { "deviceID": "666666666666" }
},
{
"type": "wokwi-resistor",
"id": "r1",
"top": 128.75,
"left": 76.8,
"attrs": { "value": "4700" }
},
{ "type": "wokwi-gnd", "id": "gnd1", "top": 57.6, "left": 133.8, "attrs": {} },
{ "type": "wokwi-vcc", "id": "vcc2", "top": -268.04, "left": 124.8, "attrs": {} },
{ "type": "wokwi-gnd", "id": "gnd3", "top": 436.8, "left": 157.8, "attrs": {} },
{ "type": "wokwi-vcc", "id": "vcc4", "top": 96.76, "left": 28.8, "attrs": {} },
{ "type": "wokwi-vcc", "id": "vcc5", "top": 279.16, "left": -57.6, "attrs": {} },
{
"type": "wokwi-lcd2004",
"id": "lcd1",
"top": 438.4,
"left": 322.4,
"attrs": { "pins": "i2c" }
},
{
"type": "wokwi-text",
"id": "txt1",
"top": -163.2,
"left": -76.8,
"attrs": { "text": "Eau Haut Poêle" }
},
{
"type": "wokwi-text",
"id": "txt2",
"top": -124.8,
"left": -76.8,
"attrs": { "text": "Eau Bas Poêle" }
},
{
"type": "wokwi-text",
"id": "txt3",
"top": -86.4,
"left": -76.8,
"attrs": { "text": "Haut Cuve Poêle" }
},
{
"type": "wokwi-text",
"id": "txt4",
"top": -48,
"left": -76.8,
"attrs": { "text": "Bas Cuve Poêle" }
},
{ "type": "wokwi-text", "id": "txt5", "top": -9.6, "left": 0, "attrs": { "text": "PC" } },
{ "type": "wokwi-text", "id": "txt6", "top": 28.8, "left": -9.6, "attrs": { "text": "ECS" } },
{
"type": "wokwi-led",
"id": "led1",
"top": -29.6,
"left": 203,
"rotate": 270,
"attrs": { "color": "red" }
},
{
"type": "wokwi-resistor",
"id": "r2",
"top": -15.25,
"left": 307.2,
"attrs": { "value": "220" }
},
{
"type": "wokwi-led",
"id": "led2",
"top": 8.8,
"left": 203,
"rotate": 270,
"attrs": { "color": "red" }
},
{
"type": "wokwi-resistor",
"id": "r3",
"top": 23.15,
"left": 307.2,
"attrs": { "value": "220" }
},
{
"type": "wokwi-led",
"id": "led3",
"top": -173.6,
"left": 203,
"rotate": 270,
"attrs": { "color": "red" }
},
{
"type": "wokwi-resistor",
"id": "r4",
"top": -159.25,
"left": 307.2,
"attrs": { "value": "220" }
},
{ "type": "wokwi-gnd", "id": "gnd2", "top": 57.6, "left": 229.8, "attrs": {} },
{
"type": "wokwi-buzzer",
"id": "bz1",
"top": 111.2,
"left": -80,
"rotate": 270,
"attrs": { "volume": "0.5" }
},
{
"type": "wokwi-pushbutton",
"id": "btn1",
"top": 307.6,
"left": 292,
"rotate": 90,
"attrs": { "color": "green", "xray": "1" }
},
{
"type": "wokwi-text",
"id": "txt7",
"top": 316.8,
"left": 364.8,
"attrs": { "text": "SILENCE" }
},
{
"type": "wokwi-led",
"id": "led4",
"top": 236.4,
"left": 272.6,
"attrs": { "color": "yellow" }
},
{
"type": "wokwi-resistor",
"id": "r5",
"top": 329.8,
"left": 258.35,
"rotate": 270,
"attrs": { "value": "220" }
}
],
"connections": [
[ "uno:7", "temp4:DQ", "green", [ "v0" ] ],
[ "uno:7", "temp5:DQ", "green", [ "v0" ] ],
[ "uno:7", "temp6:DQ", "green", [ "v0" ] ],
[ "uno:7", "temp7:DQ", "green", [ "v0" ] ],
[ "uno:7", "temp8:DQ", "green", [ "v0" ] ],
[ "uno:7", "temp9:DQ", "green", [ "v0" ] ],
[ "uno:7", "r1:2", "green", [ "v0" ] ],
[ "temp6:VCC", "temp5:VCC", "red", [ "h28.8", "v-48" ] ],
[ "temp5:VCC", "temp4:VCC", "red", [ "h28.8", "v-38.4" ] ],
[ "temp7:VCC", "temp6:VCC", "red", [ "h28.8", "v-48" ] ],
[ "temp4:GND", "gnd1:GND", "black", [ "h0" ] ],
[ "temp5:GND", "gnd1:GND", "black", [ "h0" ] ],
[ "temp6:GND", "gnd1:GND", "black", [ "h0" ] ],
[ "temp7:GND", "gnd1:GND", "black", [ "h0" ] ],
[ "temp4:VCC", "vcc2:VCC", "red", [ "h0" ] ],
[ "uno:GND.3", "gnd3:GND", "black", [ "v0" ] ],
[ "vcc4:VCC", "r1:1", "red", [ "v0" ] ],
[ "uno:5V", "vcc5:VCC", "red", [ "v57.5", "h-197.8" ] ],
[ "temp7:GND", "temp8:GND", "black", [ "h38.4", "v38.4" ] ],
[ "temp8:GND", "temp9:GND", "black", [ "h38.4", "v38.4" ] ],
[ "temp7:VCC", "temp8:VCC", "red", [ "h28.8", "v38.4" ] ],
[ "temp8:VCC", "temp9:VCC", "red", [ "h28.8", "v38.4" ] ],
[ "uno:A5", "lcd1:SCL", "green", [ "v0" ] ],
[ "uno:A4", "lcd1:SDA", "green", [ "v0" ] ],
[ "uno:GND.3", "lcd1:GND", "black", [ "v0" ] ],
[ "uno:5V", "lcd1:VCC", "red", [ "v0" ] ],
[ "led1:A", "r2:1", "green", [ "v0" ] ],
[ "led2:A", "r3:1", "green", [ "v0" ] ],
[ "led3:A", "r4:1", "green", [ "v0" ] ],
[ "gnd2:GND", "led2:C", "black", [ "v0" ] ],
[ "led2:C", "led1:C", "black", [ "h28.8", "v-38.8", "h-9.6" ] ],
[ "led1:C", "led3:C", "black", [ "h28.8", "v-144" ] ],
[ "uno:11", "r4:2", "green", [ "v-57.6", "h375", "v-326.4" ] ],
[ "uno:12", "r2:2", "green", [ "v-48", "h365.3", "v-192" ] ],
[ "uno:13", "r3:2", "green", [ "v-38.4", "h355.6", "v-163.2" ] ],
[ "uno:3", "btn1:1.l", "green", [ "v-28.8", "h167.2" ] ],
[ "uno:GND.3", "btn1:2.r", "black", [ "v28.7", "h148.2" ] ],
[ "uno:GND.1", "bz1:1", "black", [ "v0" ] ],
[ "uno:9", "bz1:2", "green", [ "v0" ] ],
[ "r5:2", "led4:C", "green", [ "h0" ] ],
[ "uno:2", "led4:A", "green", [ "v-19.2", "h100.1", "v57.6" ] ],
[ "uno:GND.3", "r5:1", "black", [ "v28.7", "h119.2" ] ]
],
"dependencies": {}
}