Hey guys, I really need some help.
So over all I want to control temperature fairly accurately. Two Pots, one for plate one for iron. These are both resistance type thermo-couplers. I have tried doing pull up resistor and a relay to control but wow these heat up way to fast. I think Ill need a PID control. No if you guys know of a easier way I am all ears. I suck at coding so please lame-ins terms if you can. I'm okay to buy one if there cheap but would like to make it if it simple. I found this PID code that doesn't pull errors for me so I think its a good start. If someone can add on to this if its easy for you of tell me hoe to that would be greatly appreciated. Thanks.
// (Really Simple) PID Class by Ivan Seidel
// GitHub.com/ivanseidel
// Use as you want. Leave credits
int Time = 0;
int old = 0;
class PID{
public:
double error;
double sample;
double lastSample;
double kP, kI, kD;
double P, I, D;
double pid;
double setPoint;
long lastProcess;
PID(double _kP, double _kI, double _kD){
kP = _kP;
kI = _kI;
kD = _kD;
}
void addNewSample(double _sample){
sample = _sample;
}
void setSetPoint(double _setPoint){
setPoint = _setPoint;
}
double process(){
// Implementação P ID
error = setPoint - sample;
float deltaTime = (millis() - lastProcess) / 1000.0;
lastProcess = millis();
//P
P = error * kP;
//I
I = I + (error * kI) * deltaTime;
//D
D = (lastSample - sample) * kD / deltaTime;
lastSample = sample;
// Soma tudo
pid = P + I + D;
return pid;
}
};
int adjust = A2;
int pSENSOR = A1;
int pCONTROLE = 3;
PID meuPid(1.0, 0, 0);
void setup() {
Serial.begin(9600);
pinMode(pSENSOR, INPUT);
pinMode(pCONTROLE, OUTPUT);
}
int controlePwm = 50;
void loop() {
Time = millis();
// Lê temperatura
double temperature = map(analogRead(pSENSOR), 0, 1023, 0, 100);
// Manda pro objeto PID!
meuPid.addNewSample(temperature);
// Converte para controle
controlePwm = (meuPid.process() + 50);
// Saída do controle
analogWrite(pCONTROLE, controlePwm);
if (Time - old >= 3000){
Serial.print("CONTROL");
Serial.println(pCONTROLE);
Serial.print(SENSOR);
Serial.println(pSENSOR);
old = Time;
}
}