Skip to main content
Notice removed Authoritative reference needed by beard999
Bounty Ended with Juraj's answer chosen by beard999
updated the code
Source Link
#include <PID_v1.h>

int AC_LOAD = 1;    // Output to Opto Triac pin
double set_value = 0;
double input = 0;
double output = 0;

PID aaa_PID(&input, &output, &set_value, 1, 0.05, 0.25, DIRECT);

void setup()
{
  aaa_PID.SetMode(AUTOMATIC);
  aaa_PID.SetOutputLimits(0, 128);
  
  int set_point = analogRead(A1); // read the pot value
  set_point = mapaaa_PID.SetMode(set_point, 0, 1023, 150, 400AUTOMATIC);  // map the pot value
  set_value = set_point;
  pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
  attachInterrupt(0, zero_crosss_int, RISING);  // Choose the zero cross interrupt # 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
{
  // Firing angle calculation : 1 full 50Hz wave =1/50=20ms 
  // Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle) 
  // For 60Hz => 8.33ms (10.000/120)
  // 10ms=10000us
  // (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65
 
  int set_point = analogRead(A1);
  set_point = map(set_point, 0, 1023, 150, 400);
  set_value = set_point;

  int dimtime = (75*output);    // For 60Hz =>65    
  delayMicroseconds(dimtime);    // Wait till firing the TRIAC
  digitalWrite(AC_LOAD, HIGH);   // Fire the TRIAC
  delayMicroseconds(10);         // triac On propogation delay (for 60Hz use 8.33)
  digitalWrite(AC_LOAD, LOW);    // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}

void loop()  {
//  int set_point = analogRead(A1);  // read the pot value
//  set_point = map(set_point, 0, 1023, 150, 400);  // map the pot value
  int inputin = analogRead(A0);  // read the sensor value (output of the LM358)
  input = map(inputin, 0, 550, 25, 400);
//  set_value = set_point;
  aaa_PID.Compute(); // compute the output value of the PID
         
}
#include <PID_v1.h>

int AC_LOAD = 1;    // Output to Opto Triac pin
double set_value = 0;
double input = 0;
double output = 0;

PID aaa_PID(&input, &output, &set_value, 1, 0.05, 0.25, DIRECT);

void setup()
{
  aaa_PID.SetMode(AUTOMATIC);
  aaa_PID.SetOutputLimits(0, 128);
  
  int set_point = analogRead(A1); // read the pot value
  set_point = map(set_point, 0, 1023, 150, 400);  // map the pot value
  set_value = set_point;
  pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
  attachInterrupt(0, zero_crosss_int, RISING);  // Choose the zero cross interrupt # 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
{
  // Firing angle calculation : 1 full 50Hz wave =1/50=20ms 
  // Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle) 
  // For 60Hz => 8.33ms (10.000/120)
  // 10ms=10000us
  // (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65
 
  int set_point = analogRead(A1);
  set_point = map(set_point, 0, 1023, 150, 400);
  set_value = set_point;

  int dimtime = (75*output);    // For 60Hz =>65    
  delayMicroseconds(dimtime);    // Wait till firing the TRIAC
  digitalWrite(AC_LOAD, HIGH);   // Fire the TRIAC
  delayMicroseconds(10);         // triac On propogation delay (for 60Hz use 8.33)
  digitalWrite(AC_LOAD, LOW);    // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}

void loop()  {
//  int set_point = analogRead(A1);  // read the pot value
//  set_point = map(set_point, 0, 1023, 150, 400);  // map the pot value
  int input = analogRead(A0);  // read the sensor value (output of the LM358)
  input = map(input, 0, 550, 25, 400);
//  set_value = set_point;
  aaa_PID.Compute(); // compute the output value of the PID
         
}
#include <PID_v1.h>

int AC_LOAD = 1;    // Output to Opto Triac pin
double set_value = 0;
double input = 0;
double output = 0;

PID aaa_PID(&input, &output, &set_value, 1, 0.05, 0.25, DIRECT);

void setup()
{
  aaa_PID.SetOutputLimits(0, 128);
  aaa_PID.SetMode(AUTOMATIC);
  pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
  attachInterrupt(0, zero_crosss_int, RISING);  // Choose the zero cross interrupt # 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
{
  // Firing angle calculation : 1 full 50Hz wave =1/50=20ms 
  // Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle) 
  // For 60Hz => 8.33ms (10.000/120)
  // 10ms=10000us
  // (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65
  int dimtime = (75*output);    // For 60Hz =>65    
  delayMicroseconds(dimtime);    // Wait till firing the TRIAC
  digitalWrite(AC_LOAD, HIGH);   // Fire the TRIAC
  delayMicroseconds(10);         // triac On propogation delay (for 60Hz use 8.33)
  digitalWrite(AC_LOAD, LOW);    // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}

void loop()  {
  int set_point = analogRead(A1);
  set_point = map(set_point, 0, 1023, 150, 400);
  int in = analogRead(A0);
  input = map(in, 0, 550, 25, 400);
  set_value = set_point;
  aaa_PID.Compute();
         
}
Notice added Authoritative reference needed by beard999
Bounty Started worth 50 reputation by beard999
added 176 characters in body
Source Link

I started to make some research and I designed a few steps of the soldering station. I will use a 24Vac/100VA toroidal transformer. I will use a 24V/50W soldering iron with K type thermocouple. For the thermocouple I will use a LM358 amplifier. Please have a look at the attached schematic and code. The code is not ready yet and I need some help in making the connection between the PID library and output in the code. The voltage on the soldering iron looks like: https://ibb.co/CMF1gQ0 If I rotate the pot, nothing happens on the screen of the scope.

#include <PID_v1.h>

int AC_LOAD = 1;    // Output to Opto Triac pin
double set_value = 0;
double input = 0;
double output = 0;

PID aaa_PID(&input, &output, &set_value, 1, 0.05, 0.25, DIRECT);

void setup()
{
  aaa_PID.SetMode(AUTOMATIC);
  aaa_PID.SetOutputLimits(0, 128);
  
  int set_point = analogRead(A1); // read the pot value
  set_point = map(set_point, 0, 1023, 150, 400);  // map the pot value
  set_value = set_point;
  pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
  attachInterrupt(0, zero_crosss_int, RISING);  // Choose the zero cross interrupt # 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
{
  // Firing angle calculation : 1 full 50Hz wave =1/50=20ms 
  // Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle) 
  // For 60Hz => 8.33ms (10.000/120)
  // 10ms=10000us
  // (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65

  int set_point = analogRead(A1);
  set_point = map(set_point, 0, 1023, 150, 400);
  set_value = set_point;

  int dimtime = (75*output);    // For 60Hz =>65    
  delayMicroseconds(dimtime);    // Wait till firing the TRIAC
  digitalWrite(AC_LOAD, HIGH);   // Fire the TRIAC
  delayMicroseconds(10);         // triac On propogation delay (for 60Hz use 8.33)
  digitalWrite(AC_LOAD, LOW);    // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}

void loop()  {
//  int set_point = analogRead(A1);  // read the pot value
//  set_point = map(set_point, 0, 1023, 150, 400);  // map the pot value
  int input = analogRead(A0);  // read the sensor value (output of the LM358)
  input = map(input, 0, 550, 25, 400);
//  set_value = set_point;
  aaa_PID.Compute(); // compute the output value of the PID
         
}

I started to make some research and I designed a few steps of the soldering station. I will use a 24Vac/100VA toroidal transformer. I will use a 24V/50W soldering iron with K type thermocouple. For the thermocouple I will use a LM358 amplifier. Please have a look at the attached schematic and code. The code is not ready yet and I need some help in making the connection between the PID library and output in the code.

#include <PID_v1.h>

int AC_LOAD = 1;    // Output to Opto Triac pin
double set_value = 0;
double input = 0;
double output = 0;

PID aaa_PID(&input, &output, &set_value, 1, 0.05, 0.25, DIRECT);

void setup()
{
  aaa_PID.SetMode(AUTOMATIC);
  aaa_PID.SetOutputLimits(0, 128);
  
  int set_point = analogRead(A1);
  set_point = map(set_point, 0, 1023, 150, 400);
  set_value = set_point;
  pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
  attachInterrupt(0, zero_crosss_int, RISING);  // Choose the zero cross interrupt # 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
{
  // Firing angle calculation : 1 full 50Hz wave =1/50=20ms 
  // Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle) 
  // For 60Hz => 8.33ms (10.000/120)
  // 10ms=10000us
  // (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65

  int set_point = analogRead(A1);
  set_point = map(set_point, 0, 1023, 150, 400);
  set_value = set_point;

  int dimtime = (75*output);    // For 60Hz =>65    
  delayMicroseconds(dimtime);    // Wait till firing the TRIAC
  digitalWrite(AC_LOAD, HIGH);   // Fire the TRIAC
  delayMicroseconds(10);         // triac On propogation delay (for 60Hz use 8.33)
  digitalWrite(AC_LOAD, LOW);    // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}

void loop()  {
//  int set_point = analogRead(A1);
//  set_point = map(set_point, 0, 1023, 150, 400);
  int input = analogRead(A0);
  input = map(input, 0, 550, 25, 400);
//  set_value = set_point;
  aaa_PID.Compute();
         
}

I started to make some research and I designed a few steps of the soldering station. I will use a 24Vac/100VA toroidal transformer. I will use a 24V/50W soldering iron with K type thermocouple. For the thermocouple I will use a LM358 amplifier. Please have a look at the attached schematic and code. The code is not ready yet and I need some help in making the connection between the PID library and output in the code. The voltage on the soldering iron looks like: https://ibb.co/CMF1gQ0 If I rotate the pot, nothing happens on the screen of the scope.

#include <PID_v1.h>

int AC_LOAD = 1;    // Output to Opto Triac pin
double set_value = 0;
double input = 0;
double output = 0;

PID aaa_PID(&input, &output, &set_value, 1, 0.05, 0.25, DIRECT);

void setup()
{
  aaa_PID.SetMode(AUTOMATIC);
  aaa_PID.SetOutputLimits(0, 128);
  
  int set_point = analogRead(A1); // read the pot value
  set_point = map(set_point, 0, 1023, 150, 400);  // map the pot value
  set_value = set_point;
  pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
  attachInterrupt(0, zero_crosss_int, RISING);  // Choose the zero cross interrupt # 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
{
  // Firing angle calculation : 1 full 50Hz wave =1/50=20ms 
  // Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle) 
  // For 60Hz => 8.33ms (10.000/120)
  // 10ms=10000us
  // (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65

  int set_point = analogRead(A1);
  set_point = map(set_point, 0, 1023, 150, 400);
  set_value = set_point;

  int dimtime = (75*output);    // For 60Hz =>65    
  delayMicroseconds(dimtime);    // Wait till firing the TRIAC
  digitalWrite(AC_LOAD, HIGH);   // Fire the TRIAC
  delayMicroseconds(10);         // triac On propogation delay (for 60Hz use 8.33)
  digitalWrite(AC_LOAD, LOW);    // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}

void loop()  {
//  int set_point = analogRead(A1);  // read the pot value
//  set_point = map(set_point, 0, 1023, 150, 400);  // map the pot value
  int input = analogRead(A0);  // read the sensor value (output of the LM358)
  input = map(input, 0, 550, 25, 400);
//  set_value = set_point;
  aaa_PID.Compute(); // compute the output value of the PID
         
}
deleted 662 characters in body
Source Link
#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);
  
}
#include <PID_v1.h>

int firing_triac = 1;    // OUTPUT TO CONTROL TRIAC
int zero_in = 2; // INPUT FROM ZERO DETECTION   
int pot = A1;   // POTENTIOMETER INPUT
int adc0 = A0; // TERMOCOUPLE INPUT
int value=0;


int temperature = 0;
 
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
double lastupdate;

//AGGRESSIVE AND CONSERVATIVE VARIABLES FOR PID CONTROLLER
double aggKp = 4, aggKi = 0.2, aggKd = 1;
double consKp = 1, consKi = 0.05, consKd = 0.25;

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT);

void setup()
{
 
  myPID.SetOutputLimits(0, 220);
  myPID.SetMode(AUTOMATIC);
  lastupdate = millis();
  Setpoint = 0;
  pinMode(firing_triac, OUTPUT); // Set the AC Load as output
  pinMode(zero_in, INPUT);
  digitalWrite(zero_in, HIGH); // pull up
  attachInterrupt(0, zero_crosss_int, RISING);
}

void zero_crosss_int()  // function to be fired at the zero crossing to dim the light
{
  double newSetpoint = analogRead(A1);
  newSetpoint = map(newSetpoint, 0, 1023, 150, 400);
  value = map(newSetpoint,150,400,7200,10);
  // Firing angle calculation :: 50Hz-> 10ms (1/2 Cycle)
  // (10000us - 10us) / 255 = 40 (Approx)
  int dimtime = (value);     
  delayMicroseconds(dimtime);    // Off cycle
  digitalWrite(firing_triac, HIGH);   // triac firing
  delayMicroseconds(10);         // triac On propogation delay
  digitalWrite(firing_triac, LOW);    // triac Off
}

void loop()
{
  
  Input = 0;
  for(int i=0;i<50;i++)
  Input += analogRead(A0);
  Input /= 50;
  Input = map(Input, 0, 550, 25, 400);
  temperature = Input;
  double newSetpoint = analogRead(A1);
  newSetpoint = map(newSetpoint, 0, 1023, 150, 400);
  //Display setpoint
  if (abs(newSetpoint - Setpoint) > 3) {
    Setpoint = newSetpoint;
    temperature = newSetpoint;
    lastupdate = millis();
  }
  double gap = abs(Setpoint - Input); //distance away from setpoint

  if (gap < 10)
  { //we're close to setpoint, use conservative tuning parameters
    myPID.SetTunings(consKp, consKi, consKd);
  }
  else
  {
    //we're far from setpoint, use aggressive tuning parameters
    myPID.SetTunings(aggKp, aggKi, aggKd);
  }
  noInterrupts();
  myPID.Compute();
  interrupts();
  //delay(1000);
  
}
#include <PID_v1.h>

int AC_LOAD = 1;    // Output to Opto Triac pin
double set_value = 0;
double input = 0;
double output = 0;

PID aaa_PID(&input, &output, &set_value, 1, 0.05, 0.25, DIRECT);

void setup()
{
  aaa_PID.SetMode(AUTOMATIC);
  aaa_PID.SetOutputLimits(0, 128);
  
  int set_point = analogRead(A1);
  set_point = map(set_point, 0, 1023, 150, 400);
  set_value = set_point;
  pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
  attachInterrupt(0, zero_crosss_int, RISING);  // Choose the zero cross interrupt # 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
{
  // Firing angle calculation : 1 full 50Hz wave =1/50=20ms 
  // Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle) 
  // For 60Hz => 8.33ms (10.000/120)
  // 10ms=10000us
  // (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65

  int set_point = analogRead(A1);
  set_point = map(set_point, 0, 1023, 150, 400);
  set_value = set_point;

  int dimtime = (75*output);    // For 60Hz =>65    
  delayMicroseconds(dimtime);    // Wait till firing the TRIAC
  digitalWrite(AC_LOAD, HIGH);   // Fire the TRIAC
  delayMicroseconds(10);         // triac On propogation delay (for 60Hz use 8.33)
  digitalWrite(AC_LOAD, LOW);    // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}

void loop()  {
//  int set_point = analogRead(A1);
//  set_point = map(set_point, 0, 1023, 150, 400);
  int input = analogRead(A0);
  input = map(input, 0, 550, 25, 400);
//  set_value = set_point;
  aaa_PID.Compute();
         
}
added 109 characters in body
Source Link
Loading
added 67 characters in body
Source Link
Loading
added 116 characters in body
Source Link
Loading
added 154 characters in body
Source Link
Loading
Source Link
Loading