#include <OneWire.h>
#include <DallasTemperature.h>
const int pinAnalogique = A0;
const int ledPin = 2;
// DS18B20
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// Pont diviseur
const float R1 = 22000.0;
const float R2 = 6800.0;
float correction = 1.000;
void setup() {
Serial.begin(9600);
sensors.begin();
Serial.println("-------------------------------------------");
Serial.println(" ** Capteur T° et V par F8ASB ** V1.00");
Serial.println(" T= valeur temperature et V=valeur tension ");
Serial.println("-------------------------------------------");
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
}
void loop() {
if (Serial.available()) {
char c = Serial.read();
// Allume la LED pour un clignotement uniforme
digitalWrite(ledPin, HIGH);
// --- TENSION ---
if (c == 'V') {
int brut = analogRead(pinAnalogique);
float vA0 = brut * (5.0 / 1023.0);
float vIn = vA0 * ((R1 + R2) / R2) * correction;
Serial.print("V=");
Serial.print(vIn, 1); // 1 chiffre après la virgule
Serial.println(" V");
}
// --- TEMPERATURE ---
if (c == 'T') {
sensors.requestTemperatures();
float tempC = sensors.getTempCByIndex(0);
Serial.print("T=");
Serial.print(tempC, 1); // 1 chiffre après la virgule
Serial.println(" C");
}
// Clignotement uniforme : 100 ms
delay(100);
// Éteint la LED
digitalWrite(ledPin, LOW);
}
}
Loading
ds18b20
ds18b20