Hi,
I need help. I am trying to read in a thermocouple that is connected to a wood stove. I am simply converting the voltage to a temperature (in Fahrenheit) and displaying the temperature to three 7 segment LEDs (that are latched with D FF's). It rings a piezoelectric buzzer if the temperature gets above a certain value. My problem is that when I read in voltages on any Analog pin (I've tried pins A5 and A0), it will work fine for awhile then it changes to some other value. See my serial read below.
0.76
0.75
0.76
0.74
0.74
0.77
0.73
0.79
0.36
0.36
0.36
0.36
0.36
0.36
0.36
0.36
0.36
0.36
0.37
0.36
0.36
0.36
0.36
0.68
0.46
0.74
0.76
0.74
I am hooking my thermocouple to an AD620 instrumentation op amp and my output is connected directly into the arduino A/D pin. The actual voltage that I read from my voltmeter is around 0.54V and stays constant. I don't care if it's off a little, but I can't have it going from 0.76V to 0.36.
Here is my code (but I think its a hardware issue) . . .
/*Brad Johnson - 2/12/12
This prgram inputs in an amplified thermocouple signal and outputs the temperature (in Fahrenheit) on three 7Seg LEDs. It also rings a buzzer if the temperature gets greater than some value.
I could not get an interrupt working that would hush the alarm if the user hits a button.
*/
int temperature = 0; //Temperature from thermocouple
//int hushPin = 2; //Shuts up the alarm
int buzzerPin = 10; //Alarm
int hiLEDpin = 11; //Hi 7 Seg Enable
int midLEDpin = 12; //Mid 7 Seg Enable
int loLEDpin = 13; //Lo 7 Seg Enable
//unsigned long time = 0; //Reads the time for when the alarm has been hushed.
//boolean BuzzerOnFlag = true; //Allows buzzer to Ring
//boolean readTimeFlag = false; //Reads the time one time when hush button is pressed.
void setup() //Sets up pins and interrups
{
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
// attachInterrupt(0, delayBuzzer, RISING);
Serial.begin(9600);
}
void loop()
{
// detachInterrupt(0);
temperature = analogRead(5); //Read in the thermocouple (amplified value)
Serial.println((float)temperature/10245);
temperature = 1.049temperature + 65.77; //Convert A/D reading (0 to 1023) to Fahrenheit
decimalToThree7Segs(temperature); //Display temperature (F) to Three 7Segs
if(temperature > 550) {
digitalWrite(buzzerPin,HIGH); //Sound Alarm!!!
delay(250);
digitalWrite(buzzerPin,LOW); //Turn off alarm momentarily so it's not annoying.
delay(15000);
}
else
delay(1500); //Don't want to bog down CPU
// if(BuzzerOnFlag == false) { //If user presses "hush" button, then BuzzerOnFlag = LOW and readTime = high
// // detachInterrupt(0);
// // attachInterrupt(0,delayBuzzer,RISING);
// if(readTimeFlag == true) { //Read the current time
// time = millis(); // only once
// readTimeFlag =
// false;
// }
// Serial.println(millis()-time);
// if(millis()-time > 20000UL) BuzzerOnFlag == true; //Once 10 min. has passed, return to normal operation
// }
// attachInterrupt(0,delayBuzzer,RISING);
}
//void delayBuzzer() //INTERRUPT - Enabled when user hits the hush button.
//{
// Serial.println("detached interrupt");
// BuzzerOnFlag = LOW;
// readTimeFlag = HIGH;
// Serial.println("attached interrupt");
// detachInterrupt(0);
//}
void write7Seg(int num) //Writes to one 7Seg LED
{
num = convertTo7Seg(num); //Decodes decimal to 7Seg LED value
digitalWrite(3,bitRead(num,0));
digitalWrite(4,bitRead(num,1));
digitalWrite(5,bitRead(num,2));
digitalWrite(6,bitRead(num,3));
digitalWrite(7,bitRead(num,4));
digitalWrite(8,bitRead(num,5));
digitalWrite(9,bitRead(num,6));
}
int convertTo7Seg(int number) //Decodes decimal to 7SegLED value
{
int sevenSeg;
switch (number)
{
case 0:
sevenSeg = 0x3f;
break;
case 1:
sevenSeg = 0x09;
break;
case 2:
sevenSeg = 0x5e;
break;
case 3:
sevenSeg = 0x5b;
break;
case 4:
sevenSeg = 0x69;
break;
case 5:
sevenSeg = 0x73;
break;
case 6:
sevenSeg = 0x77;
break;
case 7:
sevenSeg = 0x19;
break;
case 8:
sevenSeg = 0x7f;
break;
case 9:
sevenSeg = 0x79;
break;
default:
sevenSeg = 0x40;
}
return sevenSeg;
}
void decimalToThree7Segs(int AtoDvalue) //Takes a 3 digit decimal value(e.g. 143) and writes to the three 7Segs
{
int hiValue; //hi 7Seg
int midValue; //mid 7Seg
int loValue; //lo 7Seg
loValue = AtoDvalue % 10; //Grabs the unit's digit
AtoDvalue = AtoDvalue - loValue;
midValue = (AtoDvalue % 100)/10; //Grabs the ten's digit
AtoDvalue = AtoDvalue - (10*midValue);
hiValue = (AtoDvalue % 1000)/100; //Grabs the hundred's digit
write7Seg(hiValue); //writes out to hi 7Seg
digitalWrite(hiLEDpin, HIGH);
digitalWrite(hiLEDpin,LOW);
write7Seg(midValue); //writes out to lo 7Seg
digitalWrite(midLEDpin,HIGH);
digitalWrite(midLEDpin,LOW);
write7Seg(loValue); //writes out to lo 7Seg
digitalWrite(loLEDpin,HIGH);
digitalWrite(loLEDpin,LOW);
}
Any help would be greatly appreciated.
-Brad