Mesurer une température avec Arduino chauffage automatique avec Arduino
Après avoir vu comment capter une température, voyons comment utiliser cette information pour déclencher une action, ici une led symbolisant un système de chauffage.
const int analogInPin0 = A0; // Analog input pin
int sensorValue0 = 0;
int consigne = 46;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog pin
sensorValue0 = analogRead(analogInPin0);
delay(4);
// print the results to the serial monitor:
Serial.print("sensorValue0 = " );
Serial.println(sensorValue0);
Serial.print("consigne = " );
Serial.println(consigne);
//action conditionnelle
if (sensorValue0 < consigne) {
digitalWrite(9,HIGH);
}
if (sensorValue0 > consigne) {
digitalWrite(9,LOW);
}
delay(2000);
// wait 3 seconds before the next readings
delay(3000-4);
}