hi
I get wrong temperature status on my code.
feks:
Here is now 24 Celsius
But my code say it is 43
What is wrong? I like to get Celsius
#include <LiquidCrystal_I2C.h>
#include <Wire.h> // Comes with Arduino IDE
// CaddyCamping v2
// Styring til kjølleskap
//declare variables
const int relayPin1 = 7; //Relepin for 12V kjøleskapp
const float fanOffTemp = 42.0; // Kjøleskappet slår seg av på 5C Rele går High
const float baseTemp = 43.0;
const float fanOnTemp = 44.0; // Kjøleskappet slår seg på 10c rele går low
float tempC = 0; // variable for holding Celcius temp (floating for decimal points precision)
int tempPin = 0; // Declaring the Analog input to be 0 (A0) of Arduino board.
float samples[8]; // array to hold 8 samples for Average temp calculation
float maxi = 0, mini = 100; // max/min temperature variables with initial values. LM35 in simple setup only measures Temp above 0.
int i;
//int val;
// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //
void setup() {
Serial.begin(9600); //opens serial port, sets data rate to 9600 bps
pinMode(relayPin1, OUTPUT);
digitalWrite(relayPin1, HIGH);// ** USE Normaly Open on relay
lcd.begin(20, 4); // set up the LCD's number of columns and rows
lcd.setCursor(0, 0); // set LCD cursor position (column, row)
lcd.print("Kjøllesystem V2.0"); // print text to LCD
lcd.setCursor(0, 1);
lcd.print("Kjølleskap");
delay(2000); // wait 2000ms
lcd.clear(); // clear LCD display}
}
void loop() {
Serial.println(analogRead(tempPin)); // Displays on serial monitor the sampled value before conversion to real Temperature reading
// Start of calculations FOR loop.
for (i = 0; i <= 7; i++) { // gets 8 samples of temperature
samples[i] = ( 1.5 * analogRead(tempPin) * 100.0) / 1024.0; // conversion math of LM35 sample to readable temperature and stores result to samples array. 1024 is the Bit depth (quantization) of Arduino.
// 5 is the supply volts of LM35. Change appropriatelly to have correct measurement. My case is 4.4Volts.
// Serial.println(samples[i]);
Serial.print("."); // print a dot for every sample at serial monitor
// Display Current Celcius Temp to LCD
// ( LCD note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 0); // set LCD cursor position
lcd.print("Tempratur: "); // print to LCD
lcd.setCursor(12, 0);
lcd.print(samples[i]); // print current Temp sample to LCD
tempC = tempC + samples[i]; // do the addition for average temperature
delay(800); // wait 800ms
}
// END of FOR loop
//Statren
// if (digitalRead(button) == LOW)
{
//Her er coden
}
// Slutten
// Max temp og min Temp
Serial.println(""); // Like and CR at serial monitor
Serial.println("");
tempC = tempC/8.0; // calculated the averare of 8 samples in Celcius
if(tempC > maxi) {maxi = tempC;} // set max temperature
if(tempC < mini) {mini = tempC;} // set min temperature
// Send Results to Serial Monitor
Serial.println("New measurement");
Serial.print(" Average Temperature in Celcius is " );
Serial.println(tempC-2);
Serial.print(" MAX Temperature in Celcius is " );
Serial.println(maxi);
Serial.print(" MIN Temperature in Celcius is " );
Serial.println(mini);
// Send results to LCD.
lcd.setCursor(0, 0);
lcd.print("Av.T Max Min");
lcd.setCursor(0, 1);
// print the measured temp average
lcd.print(tempC-2);
lcd.setCursor(6, 1);
// print the maximum temp
lcd.print(maxi);
lcd.setCursor(12, 1);
// print the minimum temp
lcd.print(mini);
delay (1000);
if (tempC - 2 <= baseTemp && tempC - 2 < fanOnTemp) {
digitalWrite(relayPin1, HIGH);
lcd.setCursor(0, 2);
lcd.print("ON ");
delay(500);
} else if (tempC - 2 >= fanOnTemp) {
digitalWrite(relayPin1, LOW);
lcd.setCursor(0, 2);
lcd.print("OFF");
delay (3000);
} else if (tempC - 2 <= fanOffTemp) {
digitalWrite(relayPin1, HIGH);
lcd.setCursor(0, 2);
lcd.print("");
lcd.print("ON----");
delay (500);
delay(3000); // Wait about 3 seconds to display the results to LCD screen befor starting the loop again
tempC = 0; // Set tempC to 0 so calculations can be done again
}
}
Code is from him: Arduino LCD Display Temperature Sensor Plus Relay - YouTube