#include <PID_v1.h>
int firing_triacAC_LOAD = 1; // OUTPUT TO CONTROL TRIAC
int zero_in = 2; // INPUT FROM ZERO DETECTION
int pot = A1; Output to //Opto POTENTIOMETERTriac INPUTpin
intdouble adc0set_value = A0; // TERMOCOUPLE INPUT
int value=0;
0;
intdouble temperatureinput = 0;
//Define Variables we'll be connecting to
double Setpoint, Input,output Output;
double= lastupdate;0;
//AGGRESSIVE AND CONSERVATIVE VARIABLES FOR PID CONTROLLER
double aggKp = 4aaa_PID(&input, aggKi = 0.2&output, aggKd = 1;
double consKp =&set_value, 1, consKi = 0.05, consKd = 0.25;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd25, DIRECT);
void setup()
{
aaa_PID.SetMode(AUTOMATIC);
myPIDaaa_PID.SetOutputLimits(0, 220128);
myPID.SetMode
int set_point = analogRead(AUTOMATICA1);
lastupdateset_point = millismap(set_point, 0, 1023, 150, 400);
Setpointset_value = 0;set_point;
pinMode(firing_triacAC_LOAD, OUTPUT); // Set the AC Load pin as output
pinModeattachInterrupt(zero_in0, INPUT);
digitalWrite(zero_inzero_crosss_int, HIGHRISING); // pullChoose up
the zero attachInterrupt(0,cross zero_crosss_int,interrupt RISING);# from the table above
}
//the interrupt function must take no parameters and return nothing
void zero_crosss_int() // function to be fired at the zero crossing to dim the light
{
double newSetpoint// =Firing analogRead(A1);
angle calculation newSetpoint: =1 map(newSetpoint,full 0,50Hz 1023,wave 150,=1/50=20ms 400);
value = map(newSetpoint,150,400,7200,10);
// Firing angleEvery calculationzerocrossing :thus: (50Hz)-> 10ms (1/2 Cycle)
// For 60Hz => 8.33ms (10.000/120)
// 10ms=10000us
// (10000us - 10us) / 255128 = 4075 (Approx) For 60Hz =>65
int set_point = analogRead(A1);
set_point = map(set_point, 0, 1023, 150, 400);
set_value = set_point;
int dimtime = (value75*output); // For 60Hz =>65
delayMicroseconds(dimtime); // OffWait cycletill firing the TRIAC
digitalWrite(firing_triacAC_LOAD, HIGH); // triacFire firingthe TRIAC
delayMicroseconds(10); // triac On propogation delay (for 60Hz use 8.33)
digitalWrite(firing_triacAC_LOAD, LOW); // triac Off
}
void loop()
{
No Inputlonger =trigger 0;
the TRIAC for(int i=0;i<50;i++)
the next Inputzero +=crossing analogRead(A0);
will swith Inputit /=off) 50;TRIAC
Input =}
void maploop(Input, 0, 550, 25, 400);
temperature = Input;{
// doubleint newSetpointset_point = analogRead(A1);
// newSetpointset_point = map(newSetpointset_point, 0, 1023, 150, 400);
//Display setpoint
if (abs(newSetpoint - Setpoint) > 3) {
Setpoint = newSetpoint;
temperature = newSetpoint;
int lastupdateinput = millisanalogRead(A0);
}
double gapinput = abs(Setpoint - Input); //distance away from setpoint
if map(gap < 10)
{ //we're close to setpointinput, use conservative tuning parameters
0, myPID.SetTunings(consKp550, consKi25, consKd400);
}
else
{
//we're far from setpoint, use aggressiveset_value tuning= parametersset_point;
myPIDaaa_PID.SetTuningsCompute(aggKp, aggKi, aggKd);
}
noInterrupts();
myPID.Compute();
interrupts();
//delay(1000);
}