Advertisement
Guest User

Arduino PID soldering station

a guest
Apr 2nd, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. //Soldering station Software using PID
  2. //Thank you Alex from https://geektimes.ru/ for help with led array function
  3. //AllAboutCircuits.com
  4. //epilepsynerd.wordpress.com
  5.  
  6. #include <PID_v1.h>
  7. #include <PCD8544.h>
  8.  
  9. PCD8544 lcd;
  10.  
  11. unsigned long updaterate = 500; //Change how fast the display updates. No lower than 500
  12. unsigned long lastupdate;
  13.  
  14. int temperature = 0;
  15.  
  16. //Define Variables we'll be connecting to
  17. double Setpoint, Input, Output;
  18.  
  19. //Define the aggressive and conservative Tuning Parameters
  20. double aggKp = 4, aggKi = 0.2, aggKd = 1;
  21. double consKp = 1, consKi = 0.05, consKd = 0.25;
  22.  
  23. //Specify the links and initial tuning parameters
  24. PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT);
  25.  
  26. void setup()
  27. {
  28. lcd.begin(84, 48);
  29.  
  30. //We do not want to drive the soldering iron at 100% because it may burn, so we set it to about 85% (220/255)
  31. myPID.SetOutputLimits(0, 220);
  32. myPID.SetMode(AUTOMATIC);
  33. lastupdate = millis();
  34. Setpoint = 0;
  35. }
  36.  
  37.  
  38. void loop() {
  39. lcd.clear();
  40. //Read temperature
  41. Input = analogRead(0);
  42. //Transform the 10bit reading into degrees celsius
  43. Input = map(Input, 0, 450, 25, 350);
  44. //Display temperature
  45. if (millis() - lastupdate > updaterate) {
  46. lastupdate = millis();
  47. temperature = Input;
  48. }
  49. //Read setpoint and transform it into degrees celsius(minimum 150, maximum 350)
  50. double newSetpoint = analogRead(1);
  51. newSetpoint = map(newSetpoint, 0, 1023, 150, 350);
  52. //Display setpoint
  53. if (abs(newSetpoint - Setpoint) > 3) {
  54. Setpoint = newSetpoint;
  55. temperature = newSetpoint;
  56. lastupdate = millis();
  57. }
  58.  
  59. double gap = abs(Setpoint - Input); //distance away from setpoint
  60.  
  61. if (gap < 10)
  62. { //we're close to setpoint, use conservative tuning parameters
  63. myPID.SetTunings(consKp, consKi, consKd);
  64. }
  65. else
  66. {
  67. //we're far from setpoint, use aggressive tuning parameters
  68. myPID.SetTunings(aggKp, aggKi, aggKd);
  69. }
  70.  
  71. myPID.Compute();
  72. //Drive the output
  73. analogWrite(11, Output);
  74. //Display the temperature
  75. show(temperature, newSetpoint);
  76. }
  77.  
  78. void show(int value, int newspnt) {
  79.  
  80. lcd.setCursor(0, 0);
  81. lcd.print("READ TEMP");
  82. lcd.setCursor(0, 1);
  83. lcd.print(value);
  84. lcd.setCursor(0, 2);
  85. lcd.print("SET TEMP");
  86. lcd.setCursor(0, 3);
  87. lcd.print(newspnt);
  88.  
  89. delay(200);
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement