Help declaring a variable for temperature in thermistor--relay circuit


hello!

i have spent past few weeks reading lot relay control arduino.  i'm not electrician study learning basic coding , circuit building has been fun adventure.

my first "eureka!" moment when able take temperature measurements thermistor.

my second "eureka!" moment when able modify "blink" example code turn relay on , off using transistor, , today after diode arrived, turned led on when relay closed.

my ultimate goal replace led 120v 60w light bulb, going in close proximity thermistor, want use turn lightbulb on , off.

this simple code borrowed arduino thermistor page, , threw in "if else" statements hoping might make sense.

basically, it's saying "temp" not declared in if/else statements, , i'm not sure wether replace temp analogread0 or what...

i'd analog0 input (after has been converted celsius) control relay on/off switch speak.  i've put fritzing schematic @ bottom if helps, thank help!!

quote

#include <math.h>
int relayhot = 4;
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 celcius
return temp;
}

void setup() {
serial.begin(115200); // begin serial monitor
pinmode(relayhot, output); //set pin 4 (known relayhot - output)
}

void loop() {
serial.println(int(thermister(analogread(0))));  // print celcius temp reading in serial monitor
delay(5000);  // wait 5 seconds before sampling temperature again

if (temp < 28) digitalwrite(relayhot, high);  //if temperature less 28c, turn on relay turn on light , increase temperature
else if (temp > 28) digitalwrite(relayhot, low);  //if temperature greater 28c, turn bulb off because hot enough

}


take line:-
code: [select]
double temp;
and place after line:-
code: [select]
#include <math.h>

this make temp global variable accessible functions.

when posting code use # icon not quote one.


Arduino Forum > Using Arduino > Programming Questions > Help declaring a variable for temperature in thermistor--relay circuit


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial