I posted this to another thread from a while back, but since it may no longer be followed I'm posting it as a fresh thread
I'm going to be using the AD595 with a type K thermocouple for a kiln controller.
so far I'm just trying to get a value to show on an LCD that is the analog value converted to degrees F
the AD595 puts out a linear 0 - 5v for the input from the thermocouple. that said, I plan to use a pot for test purposes, the formula for converting the voltage to degrees F is as follows.
Temp(F) = (355.2823 * Volts) - 16.7674
now I need to convert the analog input from 0-1023 back to volts
so I'm figuring I'll be dividing 5 by 1024 giving me an awkward decimal for the constant
in other words I'll be multipyling the input value 0-1023 by 5/1024
multiplying that by 355.2823
and subtracting 16.7674
to render the temperature in degrees F
that's where it gets hazy for me
for one thing I don't see any reason to include the entire math library if I'm only going to be using a single function, and I'm not even sure that is in there. I see other examples where they do use math.h but memory is going to be precious in this application so I'm looking to keep it as lean as possible.
can I just define a constant as the fraction 5/1024
the following is what I have with some things I know to be incorrect such as how to define the constant and the math function converting the volts to the temperature value in degrees F
I also know I could simplify it by multiplying 5*355.2823 and dividing that by 1024 (giving me 1.7348 for the constant - constVolt in the example below) then I only need to multiply it by the sensorValue and subtract 16.7674
in other words (constVolt*sensorValue)-16.7674
with constVolt now defined as 1.7348
So here is what I have so far
thanks for any input and Advice,
Carl
/*
Analog input from T/C amp displayed as value on LCD
*Varied 0-5Vdc to analog input 0
*LCD RS pin to digital pin 12
*LCD Enable pin to digital pin 11
*LCD D4 to digital pin 5
*LCD D5 to digital pin 4
*LCD D6 to digital pin 3
*LCD D7 to digital pin 2
*LCD R/W pin to GND
*LCD V0 Pin to 0-5V for contrast*/
// include library code
#include <LiquidCrystal.h>// initialize with the numbers of interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);int sensorPin =A0; //select input pin for thermocouple amplifier
int sensorValue =0; //variable to store the value coming from the sensor
float temp =0; //variable to store calculated temp#define constVolt 5/1024 //constant converting analog value 0-1023 to 0-5v
void setup() {
//setup the LCD's number of columns and rows
lcd.begin(20, 4);
}void loop() {
// read value from T/C:
sensorValue = analogRead(sensorPin);
// convert to degrees F
temp = (constVolt)(sensorValue)(355.2823)-16.7674
//set the cursor to column 0, line 1
lcd.setCursor(0,1);
// print temp value
lcd.print(temp);