1 | #include <OneWire.h>
|
2 | #include <DallasTemperature.h>
|
3 | #include <SPI.h>
|
4 | #include <SD.h>
|
5 | File myFile;
|
6 | #define ONE_WIRE_BUS 3
|
7 | OneWire oneWire(ONE_WIRE_BUS);
|
8 | DallasTemperature sensors(&oneWire);
|
9 | #include <LiquidCrystal.h>
|
10 | LiquidCrystal lcd(4, 5, 6, 7, 8, 9);
|
11 | #define Pumpe_AN 0
|
12 | #define Pumpe_LED 10
|
13 | #define Einstellung 1
|
14 |
|
15 | /********************************************************************************/
|
16 | //DeviceAdressen der einzelnen ds1820 Temperatursensoren angeben. (loop anpassen)
|
17 | //DeviceAddress sensorA = { 0x28, 0xF8, 0x1F, 0xD0, 0x5, 0x0, 0x0, 0xEA };
|
18 | //DeviceAddress sensorI = { 0x28, 0x6B, 0x8E, 0xCF, 0x5, 0x0, 0x0, 0xDA };
|
19 | DeviceAddress sensorA = { 0x28, 0xFF, 0x1E, 0x35, 0xA4, 0x15, 0x01, 0x7A };
|
20 | DeviceAddress sensorI = { 0x28, 0xFF, 0x6B, 0x29, 0xA4, 0x15, 0x03, 0x53 };
|
21 |
|
22 | // Solltemperatur
|
23 | int MPumpeA = 0;
|
24 | int Tempsoll = 30;
|
25 | int Tempdif = 2;
|
26 | int MTempdif = 0;
|
27 | int resolution = 10; // DS18S20 only 9bit, other 9...12
|
28 | float TempSensorA = 0.0; // Zwischenspeicher zum auslesen
|
29 | float TempSensorI = 0.0; // Zwischenspeicher zum auslesen
|
30 | int sensorPin = A0; // select the input pin for the potentiometer
|
31 | int sensorValue = 0; // variable to store the value coming from the sensor
|
32 | int sensorPin1 = A1; // select the input pin for the potentiometer
|
33 | int sensorValue1 = 0; // variable to store the value coming from the sensor
|
34 |
|
35 | /********************************************************************************/
|
36 | void setup()
|
37 | {
|
38 | lcd.begin(16,2);
|
39 | lcd.clear();
|
40 | pinMode(Pumpe_AN, OUTPUT);
|
41 | pinMode(Pumpe_LED, OUTPUT);
|
42 | pinMode(Einstellung, INPUT);
|
43 | Serial.begin(9600);
|
44 | sensors.begin();
|
45 | delay(1000);
|
46 | sensors.setResolution(sensorA, resolution);
|
47 | sensors.setResolution(sensorI, resolution); //Bitbreite angeben 9
|
48 | sensors.setWaitForConversion(false);
|
49 |
|
50 | Serial.print("SD Karte ");
|
51 |
|
52 | if (!SD.begin(53)) {
|
53 | Serial.println("nicht gefunden!");
|
54 | return;
|
55 | }
|
56 | Serial.println("korrekt angeschlossen");
|
57 | myFile = SD.open("temper.txt", FILE_WRITE);
|
58 | }
|
59 | /********************************************************************************/
|
60 | void loop()
|
61 | {
|
62 | sensors.requestTemperatures();
|
63 | delay(1000);
|
64 | TempSensorA = sensors.getTempC(sensorA);
|
65 | TempSensorI = sensors.getTempC(sensorI);
|
66 | MTempdif = TempSensorA - TempSensorI;
|
67 |
|
68 | Serial.print(F("SensorA: ")); Serial.println(TempSensorA);
|
69 | Serial.print(F("SensorI: ")); Serial.println(TempSensorI);
|
70 | Serial.print(F("Differenz: ")); Serial.println(MTempdif);
|
71 |
|
72 |
|
73 |
|
74 | if (digitalRead(Einstellung) == HIGH )
|
75 | {
|
76 | lcd.setCursor(0, 0);
|
77 | lcd.print("Einstellung ");
|
78 | lcd.setCursor(0, 1);
|
79 | lcd.print("S:");
|
80 | lcd.print(Tempsoll);
|
81 | lcd.setCursor(8, 1);
|
82 | lcd.print("D:");
|
83 | lcd.print(Tempdif);
|
84 |
|
85 | sensorValue = analogRead(sensorPin);
|
86 | Tempsoll = 30 + (sensorValue/102);
|
87 | Serial.println(Tempsoll);
|
88 | delay(100);
|
89 | sensorValue1 = analogRead(sensorPin1);
|
90 | Tempdif = 2 + (sensorValue1/341);
|
91 | Serial.println(Tempdif);
|
92 | delay(100);
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | }
|
98 | else
|
99 | {
|
100 | lcd.setCursor(0, 0);
|
101 | lcd.print("I:");
|
102 | lcd.print(TempSensorI,2);
|
103 | lcd.setCursor(8, 0);
|
104 | lcd.print("A:");
|
105 | lcd.print(TempSensorA,2);
|
106 | lcd.setCursor(0, 1);
|
107 | lcd.print("S:");
|
108 | lcd.print(Tempsoll);
|
109 | lcd.setCursor(8, 1);
|
110 | lcd.print("D:");
|
111 | lcd.print(Tempdif);
|
112 | if (TempSensorI > Tempsoll)
|
113 | {
|
114 | if (MPumpeA == 1)
|
115 | {
|
116 | if (myFile) {
|
117 | Serial.print("Writing to temper.txt...");
|
118 | myFile.print(TempSensorI );
|
119 | myFile.print(TempSensorA );
|
120 | myFile.println("0");
|
121 | // close the file:
|
122 | myFile.close();
|
123 | Serial.println("done.");
|
124 | }
|
125 | }
|
126 |
|
127 |
|
128 | digitalWrite(Pumpe_AN, LOW);
|
129 | digitalWrite(Pumpe_LED, LOW);
|
130 | delay(120);
|
131 | MPumpeA = 0;
|
132 | }
|
133 | else
|
134 | {
|
135 | if (MTempdif > Tempdif)
|
136 | {
|
137 | digitalWrite(Pumpe_AN, HIGH);
|
138 | digitalWrite(Pumpe_LED, HIGH);
|
139 | delay(120);
|
140 | MPumpeA = 1;
|
141 | if (MPumpeA == 1)
|
142 | {
|
143 | if (myFile) {
|
144 | Serial.print("Writing to temper.txt...");
|
145 | myFile.print(TempSensorI );
|
146 | myFile.print(TempSensorA );
|
147 | myFile.println("0");
|
148 | // close the file:
|
149 | myFile.close();
|
150 | Serial.println("done.");
|
151 | }
|
152 | }
|
153 | }
|
154 | else
|
155 | {
|
156 | if (MPumpeA == 1)
|
157 | {
|
158 | if (myFile) {
|
159 | Serial.print("Writing to temper.txt...");
|
160 | myFile.print(TempSensorI );
|
161 | myFile.print(TempSensorA );
|
162 | myFile.println("0");
|
163 | // close the file:
|
164 | myFile.close();
|
165 | Serial.println("done.");
|
166 | }
|
167 | }
|
168 | digitalWrite(Pumpe_AN, LOW);
|
169 | digitalWrite(Pumpe_LED, LOW);
|
170 | delay(120);
|
171 | MPumpeA = 0;
|
172 | }
|
173 | }
|
174 | }
|
175 | }
|