1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
| //Librairies & paramètres DS18B20 (sonde de température d'eau)
#include "OneWire.h"
#include "DallasTemperature.h"
#define ONE_WIRE_PIN A0
#define TEMPERATURE_PRECISION 9
OneWire oneWire(ONE_WIRE_PIN);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer, outsideThermometer;
//Librairies & paramètres DHT 11 (sonde de température d'air)
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
//Librairies & paramètres DCF77 (Horloge atomique)
#include <Arduino.h>
#include "decodeurDCF77.h"
const uint8_t PIN_DCF77 = 3;
//Le paramétrage de démarrage
void setup()
{
//On initialise la connexion série
Serial.begin(9600);
//On paramètre les variables
pinMode(PIN_DCF77, INPUT);
//On active les librairies
sensors.begin();
dht.begin();
//Localisation des sondes de température
Serial.print("Locating devices...");
Serial.print("Found ");
Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(" devices.");
//report parasite power requirements
Serial.print("Parasite power is: ");
if (sensors.isParasitePowerMode()) Serial.println("ON");
else Serial.println("OFF");
// method 1: by index
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1");
// show the addresses we found on the bus
Serial.print("Device 0 Address: ");
printAddress(insideThermometer);
Serial.println();
Serial.print("Device 1 Address: ");
printAddress(outsideThermometer);
Serial.println();
// set the resolution to 9 bit per device
sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);
Serial.print("Device 0 Resolution: ");
Serial.print(sensors.getResolution(insideThermometer), DEC);
Serial.println();
Serial.print("Device 1 Resolution: ");
Serial.print(sensors.getResolution(outsideThermometer), DEC);
Serial.println();
}
//Le programe principal
void loop()
{
//Temporisation de 2 secondes
delay(2000);
//Récupération de l'heure
static uint8_t longueur = 0;
bool trame_decodee = decodeurDCF77.traiterSignal(digitalRead(PIN_DCF77), millis());
if (trame_decodee) {
Serial.print(' ');
Serial_printDCF77();
}
if (longueur > decodeurDCF77.longueur_trame_en_cours()) {
longueur = 0;
Serial.println();
}
while (longueur < decodeurDCF77.longueur_trame_en_cours()) {
Serial.print(decodeurDCF77.bit_trame(longueur++));
}
//Relevé des
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
// On récupère la température de la sonde
sensors.requestTemperatures();
double dTempWater = sensors.getTempCByIndex(0);
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
// On imprime la température de l'eau
Serial.print("Température de l'eau: ");
Serial.print(dTempWater);
Serial.println("°C");
double dTempAir = sensors.getTempCByIndex(1);
// On imprime la température de l'air
Serial.print("Température de l'air: ");
Serial.print(dTempAir);
Serial.println("°C");
// On attends 5 secondes
delay(5000);
}
//Les fonctions
//Fonction pour imprimer une adresse de périphérique
void printAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++)
{
// zero pad the address if necessary
if (deviceAddress[i] < 16) Serial.print("0");
Serial.print(deviceAddress[i], HEX);
}
}
//Fonction pour imprimer la température d'une sonde
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if(tempC == DEVICE_DISCONNECTED_C)
{
Serial.println("Error: Could not read temperature data");
return;
}
Serial.print("Temp C: ");
Serial.print(tempC);
Serial.print(" Temp F: ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}
//Fonction pour imprimer la "résolution" (?) d'un appareil
void printResolution(DeviceAddress deviceAddress)
{
Serial.print("Resolution: ");
Serial.print(sensors.getResolution(deviceAddress));
Serial.println();
}
//Fonction principale pour imprimer des informations sur un périphérique
void printData(DeviceAddress deviceAddress)
{
Serial.print("Device Address: ");
printAddress(deviceAddress);
Serial.print(" ");
printTemperature(deviceAddress);
Serial.println();
}
void Serial_printDCF77() {
switch (decodeurDCF77.joursem()) {
case 0 : Serial.println("(vide)"); return;
case 1 : Serial.print("Lundi"); break;
case 2 : Serial.print("Mardi"); break;
case 3 : Serial.print("Mercredi"); break;
case 4 : Serial.print("Jeudi"); break;
case 5 : Serial.print("Vendredi"); break;
case 6 : Serial.print("Samedi"); break;
case 7 : Serial.print("Dimanche"); break;
}
Serial.print(' ');
Serial_print99(decodeurDCF77.jour());
Serial.print('/');
Serial_print99(decodeurDCF77.mois());
Serial.print("/20");
Serial_print99(decodeurDCF77.annee());
Serial.print(' ');
Serial_print99(decodeurDCF77.heure());
Serial.print(':');
Serial_print99(decodeurDCF77.minute());
Serial.print(' ');
if (decodeurDCF77.heure_ete()) {
Serial.print("(heure d'ete)");
} else {
Serial.print("(heure d'hiver)");
}
}
void Serial_print99(uint8_t nombre) {
if (nombre < 10) Serial.print('0');
Serial.print(nombre);
} |
Partager