I'm making a control system for the heating of a plate using a PID control.
the goal is to regulate the temperature of the plate by changing the power dissipated by the resistance. By using a sensor I read the temperature of the plate and is then used as the input in the PID control. I programmed also a signal wave square for the PWM.
but the thing I don't understand is what I'm exactly supposed to do with the output signal I receive. and I cannot connect between the PWM and the PID.
Code of the square signal:
void setup()
{
pinMode(9, OUTPUT);
}
void loop()
{
// phase haute
digitalWrite(9,HIGH);
delay(30);
// phase basse
digitalWrite(9,LOW);
delay(70);
//ton+toff = 0.1;
// ton = 0.1*Output;
}
Code of PID and the sensor
/********************************************************
* PID Basic Example
* Reading analog input 0 to control analog PWM output 3
********************************************************/
#include <PID_v1.h>
int val;
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);
void setup()
{
Serial.begin(9600);
//initialize the variables we're linked to
Input = analogRead(1);
Setpoint = 37; //temperature a reguler
//turn the PID on
myPID.SetMode(AUTOMATIC);
}
void loop()
{
val = analogRead(1);
float mv = ( val/1024.0)*5000;
float Input = mv/10;
myPID.Compute();
analogWrite(3,Output);
Serial.print("input temperature is :");
Serial.println(Input);
delay (1000);
// delay(1000);
Serial.print("output is :");
Serial.println(Output);
delay(1000);
}
Thank you in advance
analogWrite(pin,Output)
, as in your code, but maybe add anpinMode(3,OUTPUT);
or you could use the fraction to control a slower frequency like in your first chunk of code.delay(Output);...delay(255-Output);
– Dave X May 9 '16 at 15:22