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!