Hello dear forum,
Me and my lab partner have to do a school project: an LCD monitor should show the measured values of a temperatur sensor. A Piezo Speaker should turn on if the temp. is over 25 Celcius.
The Problem is the following: we tried it with
if (temperatur > 25)
{ digitalWrite(Speaker_PIN, HIGH);} . The Piezo Speaker however remains on even under 25 Celcius. Can sb. help?
Here is the code:
#include <LiquidCrystal.h>
int TMP36 = A0;
int sensorwert;
int SPEAKER_PIN = 7;
int temperatur = 0;
int TEMPERATURE_THRESHOLD = 25;
int t = 500;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
float celsius;
int temp = A1;
void setup() {
Serial.begin(3600);
pinMode(temp, INPUT);
pinMode(SPEAKER_PIN, OUTPUT);
lcd.print(" ISIRONA");
delay(3000);
}
void loop() {
celsius = analogRead(temp) * 0.004882814;
celsius = (celsius - 0.5) * 100.0;
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(celsius);
lcd.print(" C");
delay(1000);
lcd.clear();
sensorwert = analogRead(TMP36);
temperatur = map(sensorwert, 0, 410, -50, 150);
delay(t);
Serial.print(temperatur);
Serial.println("Grad Celcius");
if (temperatur > TEMPERATURE_THRESHOLD) {
digitalWrite(SPEAKER_PIN, HIGH);
} else {
digitalWrite(SPEAKER_PIN, LOW);
}
}