====== Réaliser un thermomètre (tmp 36) avec affichage LCD====== ===== Le code ===== #include // Décl des pins const int sensorPin = A0; const int switchPin = 13 ; int previousTmpSensorVal = 0 ; float voltage = 0.0; float temperatureC = 0.0; int switchState = 0 ; // Constantes du LCD const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; LiquidCrystal lcd(rs, en, d4, d5, d6, d7); void setup() { pinMode(13, INPUT); lcd.begin(16,2); lcd.print("Affichage"); lcd.setCursor(0,1); lcd.print("Temperature"); delay(1000); // Reinitialisation LCD lcd.clear(); } void loop() { // Lecture de la valeur du capteur int tmpSensorVal = analogRead(sensorPin); // Lecture de l'interrupteur switchState = digitalRead(switchPin); lcd.setCursor(15,1); lcd.print(switchState); // Valeurx Fixes du LCD lcd.setCursor(8,0); lcd.print("V:"); lcd.setCursor(0,1); lcd.print("Temp.:"); lcd.setCursor(12,1); lcd.print("C"); // Si changement capteur, on (re)calcule la temperature if (tmpSensorVal != previousTmpSensorVal ) { // Calcul du volatge et conversion en degré Celsius voltage = tmpSensorVal * 5.0; voltage /= 1024.0; temperatureC = (voltage - 0.5) * 100 ; previousTmpSensorVal = tmpSensorVal ; } // Affichage sur demande (appui switch) if (switchState == 1) { // Affichage LCD lcd.display(); lcd.setCursor(0,0); lcd.print(tmpSensorVal); lcd.setCursor(10,0); lcd.print(voltage); lcd.setCursor(7,1); lcd.print(temperatureC); delay(10000); } else { // On éteint le LCD lcd.noDisplay(); } delay(500); } ===== Le schéma ===== {{ :arduiro:lcd-temperature2-fritzing_bb.png?direct&400 |}}