Hello,
I have made the following temperature meter.
/*
Temperatuurmeter
*/
const int sensorPin = A0;
const float baselineTemp = 21.0;
void setup() {
Serial.begin(9600); // open a serial port
for(int pinNumber = 2; pinNumber < 5; pinNumber++) {
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, LOW);
}
}
void loop() {
int sensorVal = analogRead(sensorPin);
Serial.print("Sensor Value: ");
Serial.print(sensorVal);
// convert the ADC reading to voltage
float voltage = (sensorVal / 1024.0) * 5.0;
Serial.print(" , Volts: ");
Serial.print(voltage);
Serial.print(" , degrees C: ");
// convert the voltage to temperature in degrees
float temperature = (voltage - 0.5) * 100;
Serial.print(temperature);
Serial.println();
if(temperature < baselineTemp) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
} else if(temperature >= baselineTemp + 2 && temperature < baselineTemp +4) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
} else if(temperature >= baselineTemp + 4 && temperature < baselineTemp +6) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
} else if(temperature >= baselineTemp + 6) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}
delay(5000);
}
When I run this program everything works fine when I touch the sensor. More led's will blink by my body head. But when i leave my computer for a time all the led's will blink and if I start the arduino editor with the monitor. Than the led's will turn of right away. In attachment you can see that the first sensor input when I turned the monitor on is way higher. How is this possible? It always happen when I leave my computer for a while.