/* Read multiple DS18B20 1-Wire digital temperature sensors by address.
More info: https://www.makerguides.com */
// Include the required Arduino libraries:
#include "OneWire.h"
#include "DallasTemperature.h"
// Define to which pin of the Arduino the 1-Wire bus is connected:
#define ONE_WIRE_BUS 2
// Create a new instance of the oneWire class to communicate with any OneWire device:
OneWire oneWire(ONE_WIRE_BUS);
// Pass the oneWire reference to DallasTemperature library:
DallasTemperature sensors(&oneWire);
// Addresses of DS18B20 sensors connected to the 1-Wire bus
// adresse reelle materiel
//byte sensor1[8] = {0x28, 0xBB, 0x22, 0xBB, 0x00, 0x00, 0x00, 0x9F};
//byte sensor2[8] = {0x28, 0xDB, 0x5E, 0xBF, 0x00, 0x00, 0x00, 0x1E};
// adresse pour test avec json
byte sensor1[8] = {0x28, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x7E};
byte sensor2[8] = {0x28, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0xDE};
void setup() {
// Begin serial communication at a baud rate of 9600:
Serial.begin(9600);
// Start up the library:
sensors.begin();
// Set the resolution for all devices to 9, 10, 11, or 12 bits:
// 9-bit précision 0.5 °C temps de conversion 93.75 ms
// sensors.setResolution(9); // résolution 9 bits pour les 2 sondes
}
void loop() {
// Send the command for all devices on the bus to perform a temperature conversion:
sensors.requestTemperatures();
Serial.print("Sonde 1: ");
printTemperature(sensor1); // call the printTemperature function with the address of sensor1 as input
Serial.print("Sonde 2: ");
printTemperature(sensor2); // call the printTemperature function with the address of sensor2 as input
Serial.println(); // prints an empty line
delay(1000);
}
void printTemperature(DeviceAddress address) {
// Fetch the temperature in degrees Celsius for device address:
float tempC = sensors.getTempC(address);
Serial.print(tempC);
Serial.print(" \xC2\xB0"); // shows degree symbol
Serial.print("C | ");
}