Compare commits
	
		
			3 commits
		
	
	
		
			0b8e4d3a5c
			...
			67c1f0503a
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 67c1f0503a | |||
| fc39b3c863 | |||
| d846c930d4 | 
					 1 changed files with 41 additions and 18 deletions
				
			
		|  | @ -16,17 +16,16 @@ DallasTemperature sensors(&oneWire);  // declare sensors | ||||||
| double pidset, watertemp, output; | double pidset, watertemp, output; | ||||||
| 
 | 
 | ||||||
| // PID adjustment
 | // PID adjustment
 | ||||||
| double Kp=2, Ki=5, Kd=1; | double Kp=500, Ki=10, Kd=0; | ||||||
| PID myPID(&watertemp, &output, &pidset, Kp, Ki, Kd, DIRECT); | PID myPID(&watertemp, &output, &pidset, Kp, Ki, Kd, DIRECT); | ||||||
| int WindowSize = 5000; | int WindowSize = 5000; | ||||||
| unsigned long windowStartTime; | unsigned long windowStartTime; | ||||||
| 
 | 
 | ||||||
| // Temp adjustment
 | // Temp adjustment
 | ||||||
| int tempset; | float tempset; | ||||||
| int poti; | int poti; | ||||||
| 
 | 
 | ||||||
| // time
 | // time
 | ||||||
| int onesecond = 1000; |  | ||||||
| unsigned long previousMillis; | unsigned long previousMillis; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -67,7 +66,26 @@ void setup() { | ||||||
|   lcd.print("Weckkubator 0.0.1"); |   lcd.print("Weckkubator 0.0.1"); | ||||||
|   delay(3000); |   delay(3000); | ||||||
|   lcd.clear(); |   lcd.clear(); | ||||||
|    | 
 | ||||||
|  |   // Setup LCD
 | ||||||
|  |   // Output temperatureset
 | ||||||
|  |   lcd.setCursor(0, 1); | ||||||
|  |   lcd.print("set:    "); | ||||||
|  |   lcd.print(pidset); | ||||||
|  |   lcd.write((byte)0); | ||||||
|  | 
 | ||||||
|  |   // Output watertemp
 | ||||||
|  |   lcd.setCursor(0, 2); | ||||||
|  |   lcd.print("temp:   "); | ||||||
|  |   lcd.print(watertemp); | ||||||
|  |   lcd.write((byte)0); | ||||||
|  |   lcd.print("C"); | ||||||
|  | 
 | ||||||
|  |   // output PID
 | ||||||
|  |   lcd.setCursor (0, 3); | ||||||
|  |   lcd.print("output: "); | ||||||
|  |   lcd.print(output); | ||||||
|  | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void loop() { | void loop() { | ||||||
|  | @ -77,11 +95,13 @@ void loop() { | ||||||
| 
 | 
 | ||||||
|   // update LCD
 |   // update LCD
 | ||||||
|   unsigned long currentMillis = millis(); |   unsigned long currentMillis = millis(); | ||||||
|   if (currentMillis - previousMillis >= onesecond) { |   if (currentMillis - previousMillis >= 250) { | ||||||
|     settemp(); |     settemp(); | ||||||
|     readtemp(); |     readtemp(); | ||||||
|     lcdoutput(); |     lcdoutput(); | ||||||
|  |     previousMillis = currentMillis; | ||||||
|   } |   } | ||||||
|  |    | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //------------------------------------------
 | //------------------------------------------
 | ||||||
|  | @ -89,10 +109,7 @@ void loop() { | ||||||
| void pid() { | void pid() { | ||||||
| 
 | 
 | ||||||
|   myPID.Compute(); |   myPID.Compute(); | ||||||
| 
 |    | ||||||
|   /************************************************
 |  | ||||||
|    * turn the output pin on/off based on pid output |  | ||||||
|    ************************************************/ |  | ||||||
|   if (millis() - windowStartTime > WindowSize) |   if (millis() - windowStartTime > WindowSize) | ||||||
|   { //time to shift the Relay Window
 |   { //time to shift the Relay Window
 | ||||||
|     windowStartTime += WindowSize; |     windowStartTime += WindowSize; | ||||||
|  | @ -117,23 +134,20 @@ void readtemp() { | ||||||
| // LCD output
 | // LCD output
 | ||||||
| void lcdoutput() { | void lcdoutput() { | ||||||
|   // Output temperatureset
 |   // Output temperatureset
 | ||||||
|   lcd.setCursor(0, 1); |   lcd.setCursor(8, 1); | ||||||
|   lcd.print("set: "); |   lcd.print(pidset); | ||||||
|   lcd.print(tempset); |  | ||||||
|   lcd.write((byte)0); |   lcd.write((byte)0); | ||||||
|   lcd.print("C"); |   lcd.print("C"); | ||||||
| 
 | 
 | ||||||
|   // Output watertemp
 |   // Output watertemp
 | ||||||
|   lcd.setCursor(0, 2); |   lcd.setCursor(8, 2); | ||||||
|   lcd.print("temp: "); |  | ||||||
|   lcd.print(watertemp); |   lcd.print(watertemp); | ||||||
|   lcd.write((byte)0); |   lcd.write((byte)0); | ||||||
|   lcd.print("C"); |   lcd.print("C"); | ||||||
|   lcd.print("   "); |   lcd.print("   "); | ||||||
| 
 | 
 | ||||||
|   // output PID
 |   // output PID
 | ||||||
|   lcd.setCursor (0, 3); |   lcd.setCursor (8, 3); | ||||||
|   lcd.print("output: "); |  | ||||||
|   lcd.print(output); |   lcd.print(output); | ||||||
|   lcd.print("   "); |   lcd.print("   "); | ||||||
| 
 | 
 | ||||||
|  | @ -144,6 +158,15 @@ void lcdoutput() { | ||||||
| // Read Poti
 | // Read Poti
 | ||||||
| void settemp() { | void settemp() { | ||||||
|   poti = analogRead(A3); |   poti = analogRead(A3); | ||||||
|   tempset = (18+(poti*0.07));  // range between 18°C and 18+1024*0,07 (~89°C)
 |   tempset = (20+(poti*0.04)); | ||||||
|   pidset = tempset; | 
 | ||||||
|  |   if (tempset <= 50) { | ||||||
|  |     pidset = tempset; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   if (tempset >= 51) { | ||||||
|  |     pidset = (tempset+30); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |    | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue