mercredi 29 janvier 2020

How to go up to a specific value, then go down and up again?

I'm a biologist and I'm building an incubator for cell cultures for an hypothesis that we want to test. We have already built the incubator, but I'm having trouble with the code. I want the incubator to go up to 21.5C, then go down to 20.5C and go up again to 21.5C, over and over.

I'm using an arduino, a temp sensor and a relay to detect the temperature and turn of and turn on the heating element.

The way I have my code, when I turn on the incubator, the relay turns on the heating element until the temp sensor detects 21.5C and then the realy turns off the heating element, but as soon as the temp goes down, it turns on the heating element again, so it stays at 21.5C all the time. I don't know how to make it cool down to 20.5C and go up to 21.5C again. Could you help me or point me to the right direction?

This is my code:

#include <math.h>
int pinOut = 10;
double Thermistor(int RawADC) {
double Temp;
Temp = log(10000.0*((1024.0/RawADC-1)));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15;
return Temp;
}
void setup() {
pinMode(10, OUTPUT);
Serial.begin(9600);
}
void loop() {
int val;
double temp;
val=analogRead(0);
temp=Thermistor(val);
Serial.print("Temperature = ");
Serial.print(temp);
Serial.println(" C");
if (temp >= 21.5){
digitalWrite(pinOut, HIGH);
}
else {
digitalWrite(pinOut, LOW);
}
delay(1000);
}

Aucun commentaire:

Enregistrer un commentaire