1
2
3
4
5
6
7
8
9#include <LiquidCrystal_I2C.h>
10#include <OnewireKeypad.h>
11
12char KEYS[] = {
13 '1', '2', '3',
14 '4', '5', '6',
15 '7', '8', '9',
16 '*', '0', '#'};
17
18#include <SPI.h>
19#include <Thermocouple.h>
20#define csTC1 9
21#define csTC2 10
22#include <PID_v1.h>
23#include <Wire.h>
24Thermocouple tc1 = Thermocouple(csTC1);
25Thermocouple tc2 = Thermocouple(csTC2);
26OnewireKeypad <Print, 12 > Keypad(Serial, KEYS, 4, 3, A0, 4700, 1000 );
27
28LiquidCrystal_I2C lcd(0x3F, 16, 2);
29double Input;
30double Input2;
31double Input3;
32double InputAve;
33int RelayPin = 8;
34int alert = 7;
35const int tempMax = 320;
36double tempSmoke = 0;
37int tempMeat = 0;
38int tempMeat1 = 0;
39int tempMeat2 = 0;
40int tempMeatAve = 0;
41int keypress = 0;
42int keypress1 = 0;
43int keypress2 = 0;
44double Setpoint;
45int SetMeatTemp;
46char Stop=0;
47char Str1[15] = "CYCLE COMPLETE";
48char Str2[15] = "ENJOY DINNER!!";
49double Output;
50int Input1=Input;
51int Setpoint1=Setpoint;
52PID myPID(&InputAve, &Output, &Setpoint,150,1,1, DIRECT);
53int WindowSize = 3500;
54unsigned long windowStartTime;
55
56
57void setup ()
58{
59
60 Serial.begin(9600);
61 windowStartTime = millis();
62
63 myPID.SetOutputLimits(0, WindowSize);
64
65 myPID.SetMode(AUTOMATIC);
66 pinMode(RelayPin, OUTPUT);
67 lcd.init();
68 lcd.backlight();
69 Wire.begin();
70 Keypad.SetHoldTime(100);
71 Keypad.Getkey();
72 lcd.begin(16, 2);
73 lcd.clear();
74 pinMode(alert, OUTPUT);
75 lcd.print("SMOKE TEMP?");
76
77 delay(100);
78}
79void loop()
80{
81
82
83
84
85 while (Stop == 0) {
86 if ((Keypad.Key_State() == 3))
87 {
88 lcd.setCursor(13, 0);
89
90 keypress = Keypad.Getkey();
91 while ((Keypad.Key_State())) {}
92 keypress = keypress - '0';
93 lcd.print(keypress);
94 Stop = 1;
95 }
96 }
97
98
99 while (Stop == 1) {
100 if ((Keypad.Key_State() == 3))
101 {
102 lcd.setCursor(14, 0);
103 keypress1 = Keypad.Getkey();
104 while ((Keypad.Key_State())) {}
105 keypress1 = keypress1 - '0';
106 lcd.print(keypress1);
107 Stop = 2;
108 }
109 }
110
111 while (Stop == 2) {
112 if ((Keypad.Key_State() == 3))
113 {
114 lcd.setCursor(15, 0);
115 keypress2 = Keypad.Getkey();
116 while ((Keypad.Key_State())) {}
117 keypress2 = keypress2 - '0';
118 lcd.print(keypress2);
119 Stop = 3;
120 }
121 }
122
123 while (Stop == 3) {
124 Setpoint = 100 * keypress + 10 * keypress1 + keypress2;
125
126 lcd.setCursor(0, 1);
127 delay(10);
128 lcd.print("MEAT TEMP?");
129 Stop = 4;
130 }
131
132 while (Stop == 4) {
133
134 if ((Keypad.Key_State() == 3))
135 {
136 lcd.setCursor(13, 1);
137 keypress = Keypad.Getkey();
138 while ((Keypad.Key_State())) {}
139 keypress = keypress - '0';
140 lcd.print(keypress);
141 Stop = 5;
142 }
143 }
144
145 while (Stop == 5) {
146 if ((Keypad.Key_State() == 3))
147 {
148 lcd.setCursor(14, 1);
149 keypress1 = Keypad.Getkey();
150 while ((Keypad.Key_State())) {}
151 keypress1 = keypress1 - '0';
152 lcd.print(keypress1);
153 Stop = 6;
154 }
155 }
156
157
158 while (Stop == 6) {
159 if ((Keypad.Key_State() == 3))
160 {
161 lcd.setCursor(15, 1);
162 keypress2 = Keypad.Getkey();
163 while ((Keypad.Key_State())) {}
164 keypress2 = keypress2 - '0';
165 SetMeatTemp = 100 * keypress + 10 * keypress1 + keypress2;
166 lcd.print(keypress2);
167 Stop = 7;
168 }
169 }
170
171 delay(50);
172
173 Input = (tc1.readF()-19);
174 delay(350);
175
176 Input2=(tc1.readF()-19);
177 delay(350);
178
179 Input3=(tc1.readF()-19);
180 delay(350);
181
182 InputAve=(Input+Input2+Input3)/3;
183
184 if (InputAve>335){InputAve=225;}
185
186 delay(350);
187 tempMeat = (tc2.readF());
188
189 delay(350);
190 tempMeat1 = (tc2.readF());
191
192 delay(350);
193 tempMeat2 = (tc2.readF());
194
195 delay(350);
196 if(tempMeat>tempMeat1+5||tempMeat<tempMeat1-5){tempMeat=100;tempMeat1=100;Serial.print("flier1 ");}
197 if(tempMeat>tempMeat2+5||tempMeat<tempMeat2-5){tempMeat=100;tempMeat2=100;Serial.print("flier2");}
198 tempMeatAve = (tempMeat+tempMeat1+tempMeat2)/3;
199
200 if(tempMeatAve>SetMeatTemp+10){tempMeatAve=150;Serial.print("flier3");}
201
202
203
204
205 myPID.Compute();
206
207 unsigned long now = millis();
208
209 if(now - windowStartTime>WindowSize)
210 {
211 windowStartTime += WindowSize;
212 }
213 if(Output > (now - windowStartTime)){
214 digitalWrite(RelayPin, HIGH);Serial.println("ON");
215 }
216 else {digitalWrite(RelayPin,LOW);Serial.println("OFF");}
217
218 lcd.clear();
219 lcd.setCursor(0, 0);
220 lcd.print("SKset");
221 lcd.setCursor(5, 0);
222 lcd.print(Setpoint);
223 lcd.setCursor(9, 0);
224 lcd.print("ACT");
225 lcd.setCursor(13, 0);
226 lcd.print(InputAve);
227 lcd.setCursor(0, 1);
228 lcd.print("MTset");
229 lcd.setCursor(5, 1);
230 lcd.print(SetMeatTemp);
231 lcd.setCursor(9, 1);
232 lcd.print("ACT");
233 lcd.setCursor(13, 1);
234 lcd.print(tempMeatAve);
235
236 Serial.print("SmokerSetTemp=");
237 Setpoint1=Setpoint;
238 Serial.print(Setpoint1);
239 Serial.print(" ");
240 Serial.print("ActualTemp=");
241 Input1=InputAve;
242 Serial.print(Input1);
243 Serial.println();
244 Serial.println();
245 Serial.print("MeatSetTemp = ");
246 Serial.print(SetMeatTemp);
247 Serial.print(" ");
248 Serial.print("ActualMeatTemp=");
249 Serial.print(tempMeatAve);
250 Serial.println();
251 Serial.println();
252 Serial.println();
253 Serial.println();
254 Serial.println();
255 Serial.println();
256 Serial.println();
257 Serial.println();
258 Serial.println();
259 delay(50);
260
261 if (InputAve>=tempMax)
262 {digitalWrite(RelayPin, LOW);
263
264 lcd.clear();
265 lcd.setCursor(0,0);
266 lcd.print("TEMPERATURE OUT");
267 lcd.setCursor(0,1);
268 lcd.print(" OF CONTROL!!!");
269 digitalWrite(alert, HIGH);}
270
271 if (tempMeatAve >= SetMeatTemp)
272
273 {
274 digitalWrite(RelayPin, LOW);
275 Serial.println(" DINNER IS READY");
276 Serial.println(" COME AND GET IT!");
277 Serial.println();
278 lcd.clear();
279 lcd.setCursor(0, 0);
280 lcd.print(Str1);
281 lcd.setCursor(0, 1);
282 lcd.print(Str2);
283 digitalWrite(alert, HIGH);
284 delay(150);
285 digitalWrite(alert, LOW);
286 delay(150);
287 digitalWrite(alert, HIGH);
288 delay(150);
289 digitalWrite(alert, LOW);
290 delay(3000);}
291 }
292
293
294
295
Anonymous user
2 years ago
Very interesting. We've only just recently bought a pellet smoker. After seeing your project, I was glad I caught a year-end sale on the low tech Camp Chef and not outlaid bigger dollars on the current WiFi version.