Add NTC thermostor
Add read NTC 100K Thermistor value Change MCU to ArduinoNANO. Need more analog inputs. ESP8266 have only 1 analog input(
This commit is contained in:
		
							parent
							
								
									18662adfec
								
							
						
					
					
						commit
						b5937aa1db
					
				|  | @ -1,23 +1,31 @@ | |||
| //enable 2040 LCD
 | ||||
| #include <LiquidCrystal_I2C.h> | ||||
| LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display
 | ||||
| //enable NTC thermistor
 | ||||
| #include <GyverNTC.h> | ||||
| // термистор на пине А0
 | ||||
| // сопротивление резистора 10к
 | ||||
| // тепловой коэффициент 3950
 | ||||
| GyverNTC therm(0, 100000, 3950); | ||||
| 
 | ||||
| // объявляем массив кнопок
 | ||||
| //enable button lib and define buttons array
 | ||||
| #define BTN_AMOUNT 5 | ||||
| #define EB_HOLD 1000 | ||||
| #include <EncButton2.h> | ||||
| EncButton2<EB_BTN> btn[BTN_AMOUNT]; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| int cursor=0; | ||||
| //define vars
 | ||||
| int cursor=1; //позиция курсора
 | ||||
| int t_current=230; | ||||
| int t_current_temp=230; | ||||
| int t_set=230; | ||||
| int t_set_temp=230; | ||||
| int motor_speed=100; | ||||
| int motor_speed_temp=100; | ||||
| int save=100; | ||||
| 
 | ||||
| int save=100; //режим работы меню. 100- режим выбора. 1,2,3 - выбранное значение
 | ||||
| float filT = 0; //фильтрованное значение датчика
 | ||||
| long previousMillis = 0;        // храним время последнего переключения светодиода
 | ||||
| long interval = 1000;           // интервал между включение/выключением светодиода (1 секунда)
 | ||||
| void setup() | ||||
| { | ||||
| 
 | ||||
|  | @ -39,18 +47,18 @@ void setup() | |||
|   lcd.print("Tc: ");//4,0 - set Temperature current
 | ||||
|   lcd.setCursor(4,0); | ||||
|   lcd.print(t_current); | ||||
|   lcd.setCursor(13,0); | ||||
|   lcd.print("Ts: ");//17,0 - set Temperature setting
 | ||||
|   lcd.setCursor(17,0); | ||||
|   lcd.setCursor(12,0); | ||||
|   lcd.print("Ts: ");//16,0 - set Temperature setting
 | ||||
|   lcd.setCursor(16,0); | ||||
|   lcd.print(t_set); | ||||
|   lcd.setCursor(0,2); | ||||
|   lcd.print("Mot.Speed: 100");//11,2 - Motor speed
 | ||||
|   lcd.setCursor(11,2); | ||||
|   lcd.print(motor_speed); | ||||
| 
 | ||||
|   btn[0].setPins(INPUT_PULLUP, D7); | ||||
|   btn[1].setPins(INPUT_PULLUP, D6); | ||||
|   btn[2].setPins(INPUT_PULLUP, D5); | ||||
|   btn[0].setPins(INPUT_PULLUP, PD2); | ||||
|   btn[1].setPins(INPUT_PULLUP, PD3); | ||||
|   btn[2].setPins(INPUT_PULLUP, PD4); | ||||
|   Serial.begin(115200); | ||||
| } | ||||
| 
 | ||||
|  | @ -66,6 +74,8 @@ void change_params(int save, int plus){ | |||
|       if (t_current>=300 || t_current<=0){ | ||||
|         //stop heating
 | ||||
|       } | ||||
|       lcd.noBlink(); | ||||
|       lcd.noCursor(); | ||||
|       lcd.setCursor(4,0); | ||||
|       lcd.print("   "); | ||||
|       lcd.setCursor(4,0); | ||||
|  | @ -86,9 +96,9 @@ void change_params(int save, int plus){ | |||
|         t_set_temp=0; | ||||
|       } | ||||
| 
 | ||||
|       lcd.setCursor(17,0); | ||||
|       lcd.setCursor(16,0); | ||||
|       lcd.print("   "); | ||||
|       lcd.setCursor(17,0); | ||||
|       lcd.setCursor(16,0); | ||||
|       lcd.print(t_set_temp); | ||||
|     } | ||||
|     //change motor speed
 | ||||
|  | @ -112,16 +122,33 @@ void change_params(int save, int plus){ | |||
|       lcd.print(motor_speed_temp); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void loop() | ||||
| { | ||||
|   lcd.blink();  | ||||
| {  | ||||
|   unsigned long currentMillis = millis(); | ||||
|    | ||||
|   //проверяем не прошел ли нужный интервал, если прошел то
 | ||||
|   if(currentMillis - previousMillis > interval) { | ||||
|     // сохраняем время последнего переключения
 | ||||
|     previousMillis = currentMillis;  | ||||
|     change_params(0,100);   | ||||
|   } | ||||
| 
 | ||||
|   filT += (therm.getTemp() - filT) * 0.1; | ||||
|   t_current_temp=filT; | ||||
|   //therm.getTempAverage();
 | ||||
|    | ||||
|   if (save==100){ | ||||
|     lcd.noBlink(); | ||||
|     lcd.cursor(); | ||||
|   } | ||||
|   for (int i = 0; i < BTN_AMOUNT; i++) btn[i].tick(); | ||||
|   //moving cursor
 | ||||
|   if (cursor==0){ | ||||
|       lcd.setCursor(3, 0); | ||||
|   } | ||||
|   //if (cursor==0){
 | ||||
|   //    lcd.setCursor(3, 0);
 | ||||
|   //}
 | ||||
|   if (cursor==1){ | ||||
|       lcd.setCursor(16, 0); | ||||
|       lcd.setCursor(15, 0); | ||||
|   } | ||||
|   if (cursor==2){ | ||||
|       lcd.setCursor(10, 2); | ||||
|  | @ -129,27 +156,35 @@ void loop() | |||
|     //listen button held
 | ||||
|   if (btn[0].held()) { | ||||
|     Serial.println("hold enter"); | ||||
|     //enter change mode
 | ||||
|     if (save==100){ | ||||
|       Serial.println("hold enter and save==100"); | ||||
|       save=cursor; | ||||
|       lcd.noBlink();  | ||||
|       lcd.blink();  | ||||
|       lcd.cursor(); | ||||
|     }else{ | ||||
| 
 | ||||
|       if(save==0){ | ||||
|         Serial.println("hold enter and save==0"); | ||||
|         t_current=t_current_temp; | ||||
|         lcd.setCursor(4,0); | ||||
|         lcd.print("   "); | ||||
|         lcd.setCursor(4,0); | ||||
|         lcd.print(t_current); | ||||
|       } | ||||
|       //enter save mode
 | ||||
|       // if(save==0){
 | ||||
|       //   Serial.println("hold enter and save==0");
 | ||||
|       //   t_current=t_current_temp;
 | ||||
|       //   lcd.setCursor(4,0);
 | ||||
|       //   lcd.print("   ");
 | ||||
|       //   lcd.setCursor(4,0);
 | ||||
|       //   lcd.print(t_current);
 | ||||
|       //   lcd.cursor();
 | ||||
|       //   lcd.blink();
 | ||||
|       //   delay(3000);
 | ||||
|       // }
 | ||||
|       if(save==1){ | ||||
|         Serial.println("hold enter and save==1"); | ||||
|         t_set=t_set_temp; | ||||
|         lcd.setCursor(17,0); | ||||
|         lcd.setCursor(16,0); | ||||
|         lcd.print("   "); | ||||
|         lcd.setCursor(17,0); | ||||
|         lcd.setCursor(16,0); | ||||
|         lcd.print(t_set); | ||||
|         lcd.cursor(); | ||||
|         lcd.blink(); | ||||
|         delay(3000); | ||||
|       } | ||||
|       if(save==2){ | ||||
|         Serial.println("hold enter and save==2"); | ||||
|  | @ -158,8 +193,13 @@ void loop() | |||
|         lcd.print("   "); | ||||
|         lcd.setCursor(11,2); | ||||
|         lcd.print(motor_speed); | ||||
|         lcd.cursor(); | ||||
|         lcd.blink(); | ||||
|         delay(3000); | ||||
|       } | ||||
|       lcd.blink(); | ||||
|       lcd.noBlink();  | ||||
|       lcd.cursor(); | ||||
|       //lcd.blink();
 | ||||
|       save=100; | ||||
|     }  | ||||
|   } | ||||
|  | @ -175,9 +215,9 @@ void loop() | |||
|       lcd.print("   "); | ||||
|       lcd.setCursor(4,0); | ||||
|       lcd.print(t_current); | ||||
|       lcd.setCursor(17,0); | ||||
|       lcd.setCursor(16,0); | ||||
|       lcd.print("   "); | ||||
|       lcd.setCursor(17,0); | ||||
|       lcd.setCursor(16,0); | ||||
|       lcd.print(t_set); | ||||
|       lcd.setCursor(11,2); | ||||
|       lcd.print("   "); | ||||
|  | @ -186,7 +226,7 @@ void loop() | |||
|     } | ||||
|     cursor++; | ||||
|     if (cursor>2){ | ||||
|       cursor=0; | ||||
|       cursor=1; | ||||
|     } | ||||
|   }   | ||||
|   if (btn[1].click() && save!=100) { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue