Devices & Components
Arduino Nano
12VDC Heater
Power MOSFET IRF740
Thermistor NTC 10K
Project description
Code
Code - GUI Interface
Used for controlling the Heating device by an user-interface.
Arduino Sketch
c_cpp
Uses Thermistor Library and PID_v1
1/*/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 UNIVERSIDADE FEDERAL DE PERNAMBUCO - PHYSICS DEPARTMENT - NANO-OPTICS LABORATORY 3 HEATING DEVICE - PID CONTROLLER 4 Allison Pessoa 5 6 Recife, Pernambuco - Brazil 7 September 2020 8 allisonpessoa@hotmail.com 9 10This heating device acts to hold at a constant temperature (user-defined setpoint) a thermal blancket by using a PID controller. 11A thermistor is used for temperature sensing (input), and a silicone mat for heating (PWM output). The User Interface can receive the temperature data 12and/or send the P,I,D,Setpoint parameters using Serial Communication. 13 14Commands: 15 16-> 'SETPT(value)' : Sets the temperature in which the temperature must be held constant. 17-> 'UPDSETT(val1,val2,val3)' : Redefines the PID constants. val1 = P; val2 = I, val3 = D 18 19**The User-Interface must avoid invalid values. 20 21Pins Interface: 22 23-> Pin D5 -> Thermal Blancket (Heater) | PWM 0-5V, 980 Hz, Output 24-> Pin A1 -> Thermistor | Analog Input (0-5V) 25 26 27under GNU GPLv3 License 28 29////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ 30#include "thermistor.h" 31#include <PID_v1.h> 32 33#ifdef VERBOSE_SENSOR_ENABLED // undefine a macro from thermistor library 34 #undef VERBOSE_SENSOR_ENABLED // so it do not print other things than the temperature value 35#endif 36 37#define NTC_PIN_INPUT A1 //Pin to NTC input 38#define PWM_PIN_OUTPUT 5 //Pin to PWM output 39 40THERMISTOR thermistor(NTC_PIN_INPUT, // Analog pin 41 10000, // Nominal resistance at 25 C 42 3950, // thermistor's beta coefficient 43 10000); // Value of the series resistor 44 45// User Interface releated 46double control_P = 100; 47double control_I = 10; 48double control_D = 1; 49 50double setPoint = 20; 51double temp; //PID Input 52double duty; //PID Output 53 54PID PID_control(&temp, &duty, &setPoint, control_P, control_I, control_D, DIRECT); 55 56// Communication through USB 57typedef struct { 58 String content; 59 volatile uint32_t value[3]; // three parameters function, maximum 60}Command; 61 62Command ReadCommand() { 63//Indetifies the command, splits letters and numbers, saves the numbers as arguments 64 Command aux; 65 char number[10]; 66 char *eprt; 67 int ascii; 68 int i=0, j=0, l=0; 69 70 while(Serial.available()>0) { 71 ascii=Serial.peek(); 72 if(ascii != 13) {//if it is not \\enter (CR) 73 if (ascii > 47 && ascii < 58) {//numbers 74 delay(10); 75 do { 76 number[i]= Serial.read(); 77 ascii = Serial.peek(); 78 i++; 79 } while (ascii > 47 && ascii < 58); 80 81 i=0; 82 long int var = strtol(number,&eprt,10); 83 aux.value[j] = var; 84 85 for (int k=0; k<10;k++){ 86 number[k]=0; 87 } 88 j++; 89 } 90 else {//letters 91 char charac = Serial.read(); 92 if (charac > 96 && charac < 123){ 93 charac -= 32;//only uppercase letters 94 } 95 aux.content.concat(charac); 96 } 97 } 98 delay(10); 99 } 100 return aux; 101} 102 103 104void setup(){ 105 pinMode(PWM_PIN_OUTPUT, OUTPUT); //PWM Output 106 Serial.begin(9600); 107 PID_control.SetMode(AUTOMATIC); 108 109 //First measurement 110 temp = float(thermistor.read())/10; 111 Serial.print("A"); 112 Serial.println(temp); 113} 114 115void loop (){ 116 Command rec; 117 if (Serial.available()){ 118 rec = ReadCommand(); 119 120 if (rec.content == "SETPT()"){ //if you whish to control directly throught Serial Monitor, use "SETPT()\ 121" instead (at least, for Ubuntu users. Arduino 1.8.12). 122 setPoint = float(rec.value[0])/10; //Receive temperature in x10 C 123 } 124 125 if (rec.content == "UPDSETT(,,)"){//The user interface must avoid invalid values 126 control_P = rec.value[0]; 127 control_I = rec.value[1]; 128 control_D = rec.value[2]; 129 } 130 } 131 132 for(int i=0; i<10; i++){ 133 temp = float(thermistor.read())/10; //Receive temperature in x10 C 134 if ((temp - setPoint) < 0.5) { //Setting adaptive tunings 135 temp = float(thermistor.read())/10; 136 PID_control.Compute(); 137 analogWrite(PWM_PIN_OUTPUT, duty);//980 Hz (predefined), at this pin 138 delay(10); 139 } 140 else{ 141 digitalWrite(PWM_PIN_OUTPUT, 0); 142 delay(10); 143 } 144 } 145 146 Serial.print("A"); 147 Serial.println(temp); 148} 149
Code - GUI Interface
Used for controlling the Heating device by an user-interface.
Downloadable files
Circuit Schematic
Circuit Schematic
Circuit Schematic
Circuit Schematic
Comments
Only logged in users can leave comments