Hi all i am using a different temp probe to the one the code is written for, i tried but i keep getting errors.
original code
#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7);
int tempPin = A1; // the output pin of LM35
int fan = 11; // the pin where fan is
int led = 8; // led pin
int temp;
int tempMin = 30; // the temperature to start the fan
int tempMax = 40; // the maximum temperature when fan is at 100%
int fanSpeed;
int fanLCD;
void setup() {
pinMode(fan, OUTPUT);
pinMode(led, OUTPUT);
pinMode(tempPin, INPUT);
lcd.begin(16,2);
}
void loop() {
temp = readTemp(); // get the 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, 35, 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(led, HIGH); // turn on led
} else { // else turn of led
digitalWrite(led, LOW);
}
lcd.print("TEMPERATURE: ");
lcd.print(temp); // display the temperature
lcd.print("C ");
lcd.setCursor(0,1); // move cursor to next line
lcd.print("FAN SPEED: ");
lcd.print(fanLCD); // display the fan speed
lcd.print("%");
delay(200);
lcd.clear();
}
int readTemp() { // get the temperature and convert it to celsius
temp = analogRead(tempPin);
return temp * 0.48828123;
}
code for new temp probe
#include <math.h>
double Thermister(int RawADC) {
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15; // Convert Kelvin to Celcius
return Temp;
}
void setup() {
Serial.begin(9600);
}
void loop()
{ Serial.println(Thermister(analogRead(0))); // display Fahrenheit Serial.println("c");
delay(500); }
What temperature probe are you using? Data sheet?
Read the how to use this forum-please read stickies to see how to post code and errors. Post the entire error message(s). Also some advice on how to ask a good question.
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Whatever you are using this looks really nasty. What are all those "magic" numbers and where did they come from ?
This code works no problem but i would like to use a different type of probe.
Please find code for new tempo probe below this code.
#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7);
int tempPin = A1; // the output pin of LM35
int fan = 11; // the pin where fan is
int led = 8; // led pin
int temp;
int tempMin = 30; // the temperature to start the fan
int tempMax = 40; // the maximum temperature when fan is at 100%
int fanSpeed;
int fanLCD;
void setup() {
pinMode(fan, OUTPUT);
pinMode(led, OUTPUT);
pinMode(tempPin, INPUT);
lcd.begin(16,2);
}
void loop() {
temp = readTemp(); // get the 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, 35, 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(led, HIGH); // turn on led
} else { // else turn of led
digitalWrite(led, LOW);
}
lcd.print("TEMPERATURE: ");
lcd.print(temp); // display the temperature
lcd.print("C ");
lcd.setCursor(0,1); // move cursor to next line
lcd.print("FAN SPEED: ");
lcd.print(fanLCD); // display the fan speed
lcd.print("%");
delay(200);
lcd.clear();
}
int readTemp() { // get the temperature and convert it to celsius
temp = analogRead(tempPin);
return temp * 0.48828123;
}
code for new temp probe (supplied by jaycar electronics)
#include <math.h>
double Thermister(int RawADC) {
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15; // Convert Kelvin to Celcius
return Temp;
}
void setup() {
Serial.begin(9600);
}
void loop()
{ Serial.println(Thermister(analogRead(0))); // display Fahrenheit Serial.println("c");
delay(500); }
Use code tags when posting code.
See "How to use this forum".
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Whatever you are using this looks really nasty. What are all those "magic" numbers and where did they come from ?
That is the standard polynomial used in the Steinhart-Hart approximation of a thermistor response curve.
The numbers are obtained from test data, using a "thermistor calibration calculator", like this one.
We still do not know what the problem is.
Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "Arduino/Genuino Uno"
C:\Users\Paul Cooper\Dropbox\Arduino\fan_pwm_test_v2\fan_pwm_test_v2.ino: In function 'double Thermister(int)':
fan_pwm_test_v2:14:14: error: a function-definition is not allowed here before '{' token
void setup() {
^
fan_pwm_test_v2:21:13: error: a function-definition is not allowed here before '{' token
void loop() {
^
fan_pwm_test_v2:52:1: error: expected '}' at end of input
}
^
Multiple libraries were found for "LiquidCrystal.h"
Used: C:\Users\Paul Cooper\Documents\Arduino\libraries\LiquidCrystal
Not used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\libraries\LiquidCrystal
exit status 1
a function-definition is not allowed here before '{' token
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
#include <math.h>
double Thermister(int RawADC) {
double temp;
#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7);
int tempPin = A1; // the output pin of LM35
int fan = 11; // the pin where fan is
int led = 8; // led pin
int tempMin = 30; // the temperature to start the fan
int tempMax = 40; // the maximum temperature when fan is at 100%
int fanSpeed;
int fanLCD;
void setup() {
pinMode(fan, OUTPUT);
pinMode(led, OUTPUT);
pinMode(tempPin, INPUT);
lcd.begin(16,2);
}
void loop() {
temp = readTemp(); // get the 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, 35, 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(led, HIGH); // turn on led
} else { // else turn of led
digitalWrite(led, LOW);
}
lcd.print("TEMPERATURE: ");
lcd.print(temp); // display the temperature
lcd.print("C ");
lcd.setCursor(0,1); // move cursor to next line
lcd.print("FAN SPEED: ");
lcd.print(fanLCD); // display the fan speed
lcd.print("%");
delay(200);
lcd.clear();
}
temp = log(((10240000/RawADC) - 10000));
temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * temp * temp ))* temp );
temp = temp - 273.15; // Convert Kelvin to Celcius
return temp;
}
Hi airtune!
I think you need to change the line "double Thermister(int RawADC) {" to "double Thermister(int RawADC);"
and change this:
lcd.print("TEMPERATURE: ");
lcd.print(temp); // display the temperature
lcd.print("C ");
lcd.setCursor(0,1); // move cursor to next line
lcd.print("FAN SPEED: ");
lcd.print(fanLCD); // display the fan speed
lcd.print("%");
delay(200);
lcd.clear();
}
to this:
lcd.print("TEMPERATURE: ");
lcd.print(temp); // display the temperature
lcd.print("C ");
lcd.setCursor(0,1); // move cursor to next line
lcd.print("FAN SPEED: ");
lcd.print(fanLCD); // display the fan speed
lcd.print("%");
delay(200);
lcd.clear();
The difference is that I have deleted the close bracket after the command "lcd.clear".
Try making these changes and let us know how you get on!
Zeb
Thanks for your help here is the error message now
Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "Arduino/Genuino Uno"
C:\Users\Paul Cooper\Dropbox\Arduino\fan_pwm_test_v2\fan_pwm_test_v2.ino: In function 'void loop()':
fan_pwm_test_v2:22:20: error: 'readTemp' was not declared in this scope
temp = readTemp(); // get the temperature
^
C:\Users\Paul Cooper\Dropbox\Arduino\fan_pwm_test_v2\fan_pwm_test_v2.ino: At global scope:
fan_pwm_test_v2:48:1: error: 'temp' does not name a type
temp = log(((10240000/RawADC) - 10000));
^
fan_pwm_test_v2:49:1: error: 'temp' does not name a type
temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * temp * temp ))* temp );
^
fan_pwm_test_v2:50:1: error: 'temp' does not name a type
temp = temp - 273.15; // Convert Kelvin to Celcius
^
fan_pwm_test_v2:51:1: error: expected unqualified-id before 'return'
return temp;
^
fan_pwm_test_v2:52:1: error: expected declaration before '}' token
}
^
Multiple libraries were found for "LiquidCrystal.h"
Used: C:\Users\Paul Cooper\Documents\Arduino\libraries\LiquidCrystal
Not used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\libraries\LiquidCrystal
exit status 1
'readTemp' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Thanks for your help here is the error message now
For what code?
Can't you get it through your head that we need to see the FULL CODE, EVERY TIME YOU CHANGE IT, posted with code tags, in order to fix YOUR problems for you?
Hi airtune,
I would suggest Having a look at the code in the manual, it might give you a clue. https://www.jaycar.com.au/medias/sys_master/images/9264557817886/XC4494-manualMain.pdf
Do you want to measure the temperature in Fahrenheit or Celsius?
Thanks
Zeb
P.S. It would be great if you could use code tags and provide the full code each time as jremington said
i would like to measure in Celsius
Sorry jremington hopefully i have done it correctly this time.
[#include <math.h>
double Thermister(int RawADC);
double temp;
#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7);
int tempPin = A1; // the output pin of LM35
int fan = 11; // the pin where fan is
int led = 8; // led pin
int tempMin = 30; // the temperature to start the fan
int tempMax = 40; // the maximum temperature when fan is at 100%
int fanSpeed;
int fanLCD;
void setup() {
pinMode(fan, OUTPUT);
pinMode(led, OUTPUT);
pinMode(tempPin, INPUT);
lcd.begin(16,2);
}
void loop() {
temp = readTemp(); // get the 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, 35, 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(led, HIGH); // turn on led
} else { // else turn of led
digitalWrite(led, LOW);
}
lcd.print("TEMPERATURE: ");
lcd.print(temp); // display the temperature
lcd.print("C ");
lcd.setCursor(0,1); // move cursor to next line
lcd.print("FAN SPEED: ");
lcd.print(fanLCD); // display the fan speed
lcd.print("%");
delay(200);
lcd.clear();
}
temp = log(((10240000/RawADC) - 10000));
temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * temp * temp ))* temp );
temp = temp - 273.15; // Convert Kelvin to Celcius
return temp;
}/code]
Hi airtune,
Have you tried running the code from the manual?
#include <math.h>
double Thermister(int RawADC) {
double Temp;
Temp = log(((10240000/RawADC) -10000));Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp -273.15; // Convert Kelvinto Celciusreturn Temp;
}
void setup() {
Serial.begin(9600);
}
void loop(){
Serial.println(Thermister(analogRead(0))); // display Fahrenheit Serial.println("c");delay(500);
}
Thanks
Zeb
Basically the original code works fine but i would like to use the jaycar temp probe, i have tried to implement that into the code with no luck, i will try and get the probe to work with the supplied code first, thanks for your help.
.......Really sorry airtune I have put you crook!
Looking at the manual you DO need the line "double Thermister(int RawADC) {", the problem was bracket placement so sorry!
You could try something like this:
#include <math.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7);
int tempPin = A1; // the output pin of LM35
int fan = 11; // the pin where fan is
int led = 8; // led pin
int tempMin = 30; // the temperature to start the fan
int tempMax = 40; // the maximum temperature when fan is at 100%
int fanSpeed;
int fanLCD;
double Thermistor(int RawADC) {
double Temp;
Temp = log(10000.0*((1024.0/RawADC-1)));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15; // Convert Kelvin to Celcius
return Temp;
}
Thanks very much
Zeb
'readTemp' was not declared in this scope
#include <math.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int tempPin = A1; // the output pin of LM35
int fan = 11; // the pin where fan is
int led = 8;// led pin
int temp;
int tempMin = 30; // the temperature to start the fan
int tempMax = 40; // the maximum temperature when fan is at 100%
int fanSpeed;
int fanLCD;
void setup() {
pinMode(fan, OUTPUT);
pinMode(led, OUTPUT);
pinMode(tempPin, INPUT);
lcd.begin(16, 2);
}
void loop() {
temp = readTemp(); // get the 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, 35, 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(led, HIGH); // turn on led
} else { // else turn of led
digitalWrite(led, LOW);
}
lcd.print("TEMPERATURE: ");
lcd.print(temp); // display the temperature
lcd.print("C ");
lcd.setCursor(0, 1); // move cursor to next line
lcd.print("FAN SPEED: ");
lcd.print(fanLCD); // display the fan speed
lcd.print("%");
delay(200);
lcd.clear();
double Thermistor(int RawADC) {
double temp;
temp = log(10000.0 * ((1024.0 / RawADC - 1)));
temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * temp * temp )) * temp );
temp = temp - 273.15; // Convert Kelvin to Celcius
return temp;
}
Hi again,
I have written some code that I am hoping will fix your problem. It compiles successfully on my laptop but of course I can't upload it.
The code does not use the "double Thermistor(int RawADC) {".
#include <math.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7);
int tempPin = A1; // the output pin of LM35
int temp;
int fan = 11; // the pin where fan is
int led = 8; // led pin
int tempMin = 30; // the temperature to start the fan
int tempMax = 40; // the maximum temperature when fan is at 100%
int fanSpeed;
int fanLCD;
void setup() {
pinMode(fan, OUTPUT);
pinMode(led, OUTPUT);
pinMode(tempPin, INPUT);
lcd.begin(16,2);
}
void loop() {
temp = readTemp(); // get the 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, 35, 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(led, HIGH); // turn on led
} else { // else turn of led
digitalWrite(led, LOW);
}
lcd.print("TEMPERATURE: ");
lcd.print(temp); // display the temperature
lcd.print("C ");
lcd.setCursor(0,1); // move cursor to next line
lcd.print("FAN SPEED: ");
lcd.print(fanLCD); // display the fan speed
lcd.print("%");
delay(200);
lcd.clear();
}
int readTemp() {
temp = analogRead(tempPin);
return temp * 0.48828123; //not sure if this will convert to Celsius?
}
Please let me know if this is what you are after and how it goes!
Zeb