Help with Thermal Cycler Program

I've built a thermal cycler (a biology hardware tool) using my arduino, but I'm having some trouble writing an appropriate program for it. Basically, I need the arduino to know what temperature it's at (which I have done) but it needs to cycle through three set temperatures in s set fashion.

It should go: HIGH, LOW, MED, HIGH, LOW, MED etc. and pause on MED for about 1 minute. The problem is that if I write "while temp < HIGH, turn on heat" it doesn't exit the while loop for some reason.

This is the code I have currently:

// Arduino code to run a pcr machine with a heating element, a cooling element and a thermistor

const int thermpin = A0;
const int heatpin = 3;
const int coolpin = 9;

const int hot = 95;
const int tm = 50;
const int elongtemp = 72;

const int elongtime = 60000;

int cyclesdonecount;

void setup(){
pinMode(thermpin, INPUT);
pinMode(heatpin, OUTPUT);
pinMode(coolpin, OUTPUT);
analogReference(EXTERNAL);
}

void loop(){

int temp = analogRead(thermpin);

do {
//Begin PCR Reaction by heating to 95 degrees;
digitalWrite(heatpin, HIGH);
int temp = analogRead(thermpin);

} while (temp < hot);

digitalWrite(heatpin, LOW);
delay(20000);

do {
digitalWrite(coolpin, HIGH);
int temp = analogRead(thermpin);
} while (temp > tm);

digitalWrite(coolpin, LOW);
delay(20000);

do{
digitalWrite(heatpin, HIGH);
int temp = analogRead(thermpin);
} while (temp < elongtemp);

digitalWrite(heatpin, LOW);
delay(elongtime);
//strobe bulb to maintain elongtemp?

cyclesdonecount++;

//digitalWrite(cyclespin, cyclesdonecount);

}

I also tried it using WHILE loops, but the same problem occurred where it doesn't exit the first loop - even when temp is above 95. I started Serial.print on the temp variable and it will be 100 while still heating.

Any suggestions would be helpful!

here's your problem

int temp = analogRead(thermpin);

do {
 //Begin PCR Reaction by heating to 95 degrees;
 digitalWrite(heatpin, HIGH);
 [glow]int[/glow] temp = analogRead(thermpin);
 
} while (temp < hot);

note that you've declared temp in two places. What happens is the { } declares one scope that the while statement can't see. So the variable named temp that while (temp<hot) sees is different then the temp that analogRead sets

In general I always advise new programmers to never declare variables inside loops for this reason (it happens a lot with students!). There is technically nothing wrong but it causes this mistake a lot. Remove the highlighted portion and you should get temp to update properly.

Also are you sure you are calculating temp correctly? analog read just returns a number from 0-1023 it does not know about temperature or any other units.

That's it! The script runs perfectly now.

I still need to calibrate the Voltage values to corresponding temperatures and then I'll probably set the three temperature benchmarks to the analog read values from 0-1023, or map it to a range in degrees celsius.