Hello all
I've tried a few times searching for ways and help in this small project i'm doing just to get use to the whole programming of the arduino (Uno R3 in my case) right now i have used the sketch from electroschematics.com as my base line and have modified it a little to have a Low Temp LED along with a High temp LED.
At this time i felt to see if i can change the tempmax to be a variable number based on a Potentionmeter (10K) that's hooked up to the UNO's Ground and 5Volt and into A1, then remapped the signal from that to a 28 - 40 range. and got it to enter into the tempmax value?
The problem seems to be that the program seems to compile correctly, uploads correctly, but when it's running the values for Temp seem to change around when i turn the Pot and also the tempmax seems to vary up and down too. basically nothing is stable?
// include the library
#include <LiquidCrystal.h>
// Pin Orientation
int tempPin = A0; // the output pin of LM35
int tempset = A1; // Input of Variable Resistor
int fan = 10; // the pin where fan is (TIP122)
int Highled = 12; // High temp LED pin
int Lowled = 11; // Low temp LED pin
int tempMin = 24; // the temperature to start the fan
int tempMax = 0; // the maximum temperature when fan is at 100%
int tempset2;
int fanSpeed;
int fanLCD;
int temp;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins
void setup() {
pinMode(fan, OUTPUT);
pinMode(Highled, OUTPUT);
pinMode(Lowled, OUTPUT);
pinMode(tempPin, INPUT);
pinMode(tempset, INPUT);
lcd.begin(16, 2);
}
void loop() {
temp = readTemp(); // get the temperature
tempMax = getmax(); //Get Max temperature
if (temp < tempMin) { // if temp is lower than minimum temp
fanSpeed = 0; // fan is not spinning
digitalWrite(fan, LOW);
}
if ((temp >= tempMin) && (temp <= tempMax)) { // if temperature is higher than minimum temp
fanSpeed = map(temp, tempMin, tempMax, 0, 255); // the actual speed of fan
fanLCD = map(temp, tempMin, tempMax, 0, 100); // speed of fan to display on LCD
analogWrite(fan, fanSpeed); // spin the fan at the fanSpeed speed
}
if (temp > tempMax) { // if temp is higher than tempMax
digitalWrite(Highled, HIGH); // turn on led
analogWrite(fan, 255);
fanLCD = 100;
} else { // else turn off led
digitalWrite(Highled, LOW);
}
if (temp < tempMin) { // if temp is lower then tempMin
digitalWrite(Lowled, HIGH); //turn on led
} else {
digitalWrite(Lowled, LOW); //turn off led
}
lcd.print("TEMP: ");
lcd.print(temp); // display the temperature
lcd.print("C");
lcd.print(" Min:");
lcd.print(tempMin); // Display Min set temperature
lcd.setCursor(0, 1); // move cursor to next line
lcd.print("FAN: ");
lcd.print(fanLCD); // display the fan speed
lcd.print("%");
lcd.print(" Max:");
lcd.print(tempMax); // Display Max set temperature
delay(1000);
lcd.clear();
}
int readTemp() { // get the temperature and convert it to celsius
temp = analogRead(tempPin);
return temp * 0.48828125;
}
int getmax(){ // Get to the Max setting and converted to temperature range
tempset2 = analogRead (tempset);
return tempMax = map(tempset2, 0, 1023, 28, 40);
}
hopefully someone can point me in the ways of my errors on implementing this adjustment, so i can see what it'll take to change the tempmin setting aswhile (which then i want to see about have tempMax's range start @5-10 degrees higher then what tempmin is at)
and thank you for your time,
Kevin