#include <SPI.h>
const int csPin = 10; //Control Switch des
MCP41HV51
int sensorPin = A0;
int bitwertNTC = 0;
int basevalue = 48; //Basiswert bei 25°C zur Kalibrierung des Bodenfühlers
int currentvalue = 0;
long
widerstand1=2000; //Ohm
int bWert =3950; // B- Wert vom NTC
double widerstandNTC =0;
double kelvintemp = 273.15; // 0°Celsius in Kelvin
double Tn=kelvintemp
+ 25; //Nenntemperatur in Kelvin
double TKelvin = 0; //Die errechnete Ist-Temperatur
double T = 0; //Die errechnete Ist-Temperatur
void setup() {
SPI.begin();
pinMode(csPin, OUTPUT);
digitalWrite(csPin, LOW);
Serial.begin(9600);
}
void loop() {
// if (Serial.available()>0) // Wenn serielle Kommunikation vorhanden // erfordert eine Eingabe
{
Serial.println("Sensormessung: ");
bitwertNTC = analogRead(sensorPin); // lese Analogwert an A0 aus
widerstandNTC = widerstand1*(((double)bitwertNTC/1024)/(1-((double)bitwertNTC/1024)));
// berechne den Widerstandswert vom NTC
TKelvin = 1/((1/Tn)+((double)1/bWert)*log((double)widerstandNTC/widerstand1));
// ermittle die Temperatur in Kelvin
T=TKelvin-kelvintemp; // ermittle die Temperatur in °C
Serial.println("Analog: "); //
Serial.println(bitwertNTC); //
Serial.println("NTC- Widerstand: "); //Gebe die ermittelten Widerstandswert
Serial.println(widerstandNTC); //
Serial.println("Temperatur: "); //Gebe die ermittelten
Serial.println(T); //
SPI.transfer(0); // setzt den MPC41HV51 zurück
if (bitwertNTC<=199){(currentvalue = basevalue – 48);} // 99.0°C
if (bitwertNTC>=200&&bitwertNTC<=203){(currentvalue = basevalue – 39);} // 9 60.0°C
if (bitwertNTC>=204&&bitwertNTC<=216){(currentvalue = basevalue – 38);} // 10 58.0°C
if (bitwertNTC>=217&&bitwertNTC<=228){(currentvalue = basevalue – 37);} // 11 56.0°C
if (bitwertNTC>=229&&bitwertNTC<=241){(currentvalue = basevalue – 36);} // 12 54.0°C
if (bitwertNTC>=242&&bitwertNTC<=252){(currentvalue = basevalue – 35);} // 13 52.5°C
if (bitwertNTC>=253&&bitwertNTC<=263){(currentvalue = basevalue – 34);} // 14 51.0°C
if (bitwertNTC>=264&&bitwertNTC<=274){(currentvalue = basevalue – 33);} // 15 49.5°C
if (bitwertNTC>=275&&bitwertNTC<=285){(currentvalue = basevalue – 32);} // 16 48.0°C
if (bitwertNTC>=286&&bitwertNTC<=297){(currentvalue = basevalue – 31);} // 17 46.6°C
if (bitwertNTC>=298&&bitwertNTC<=306){(currentvalue = basevalue – 30);} // 18 45.5°C
if (bitwertNTC>=307&&bitwertNTC<=318){(currentvalue = basevalue – 29);} // 19 44.0°C
if (bitwertNTC>=319&&bitwertNTC<=327){(currentvalue = basevalue – 28);} // 20 43.0°C
if (bitwertNTC>=328&&bitwertNTC<=336){(currentvalue = basevalue – 27);} // 21 42.0°C
if (bitwertNTC>=337&&bitwertNTC<=345){(currentvalue = basevalue – 26);} // 22 41.0°C
if (bitwertNTC>=346&&bitwertNTC<=355){(currentvalue = basevalue – 25);} // 23 40.0°C
if (bitwertNTC>=356&&bitwertNTC<=364){(currentvalue = basevalue – 24);} // 24 39.0°C
if (bitwertNTC>=365&&bitwertNTC<=368){(currentvalue = basevalue – 23);} // 25 38.5°C
if (bitwertNTC>=369&&bitwertNTC<=377){(currentvalue = basevalue – 22);} // 26 37.5°C
if (bitwertNTC>=378&&bitwertNTC<=387){(currentvalue = basevalue – 21);} // 27 36.5°C
if (bitwertNTC>=388&&bitwertNTC<=393){(currentvalue = basevalue – 20);} // 28 36.0°C
if (bitwertNTC>=394&&bitwertNTC<=403){(currentvalue = basevalue – 19);} // 29 35.0°C
if (bitwertNTC>=404&&bitwertNTC<=408){(currentvalue = basevalue – 18);} // 30 34.5°C
if (bitwertNTC>=409&&bitwertNTC<=419){(currentvalue = basevalue – 16);} // 32 33.5°C
if (bitwertNTC>=420&&bitwertNTC<=424){(currentvalue = basevalue – 15);} // 33 33.0°C
if (bitwertNTC>=425&&bitwertNTC<=429){(currentvalue = basevalue – 14);} // 34 32.5°C
if (bitwertNTC>=430&&bitwertNTC<=434){(currentvalue = basevalue – 13);} // 35 32.0°C
if (bitwertNTC>=435&&bitwertNTC<=445){(currentvalue = basevalue – 11);} // 37 31.0°C
if (bitwertNTC>=445&&bitwertNTC<=450){(currentvalue = basevalue – 10);} // 38 30.5°C
if (bitwertNTC>=451&&bitwertNTC<=456){(currentvalue = basevalue – 9);} // 39 30.0°C
if (bitwertNTC>=457&&bitwertNTC<=461){(currentvalue = basevalue – 8);} // 40 29.5°C
if (bitwertNTC>=462&&bitwertNTC<=466){(currentvalue = basevalue – 7);} // 41 29.0°C
if (bitwertNTC>=467&&bitwertNTC<=472){(currentvalue = basevalue – 6);} // 42 28.5°C
if (bitwertNTC>=473&&bitwertNTC<=484){(currentvalue = basevalue – 5);} // 43 27.5°C
if (bitwertNTC>=485&&bitwertNTC<=490){(currentvalue = basevalue – 4);} // 44 27.0°C
if (bitwertNTC>=491&&bitwertNTC<=495){(currentvalue = basevalue – 3);} // 45 26.5°C
if (bitwertNTC>=496&&bitwertNTC<=500){(currentvalue = basevalue – 2);} // 46 26.0°C
if (bitwertNTC>=501&&bitwertNTC<=506){(currentvalue = basevalue – 1);} // 47 25.5°C
if (bitwertNTC>=507&&bitwertNTC<=512){(currentvalue = basevalue);} // 48 25.0°C
if (bitwertNTC>=513&&bitwertNTC<=519){(currentvalue = basevalue + 1);} // 49 24.5°C
if (bitwertNTC>=520&&bitwertNTC<=524){(currentvalue = basevalue + 2);} // 50 24.0°C
if (bitwertNTC>=525&&bitwertNTC<=529){(currentvalue = basevalue + 3);} // 51 23.5°C
if (bitwertNTC>=530&&bitwertNTC<=535){(currentvalue = basevalue + 4);} // 52 23.0°C
if (bitwertNTC>=536&&bitwertNTC<=540){(currentvalue = basevalue + 5);} // 53 22.5°C
if (bitwertNTC>=541&&bitwertNTC<=546){(currentvalue = basevalue + 7);} // 55 22.0°C
if (bitwertNTC>=547&&bitwertNTC<=552){(currentvalue = basevalue + 8);} // 56 21.5°C
if (bitwertNTC>=553&&bitwertNTC<=557){(currentvalue = basevalue + 10);} // 58 21.0°C
if (bitwertNTC>=558&&bitwertNTC<=563){(currentvalue = basevalue + 11);} // 59 20.5°C
if (bitwertNTC>=564&&bitwertNTC<=569){(currentvalue = basevalue + 12);} // 60 20.0°C
if (bitwertNTC>=570&&bitwertNTC<=575){(currentvalue = basevalue + 14);} // 62 19.5°C
if (bitwertNTC>=576&&bitwertNTC<=581){(currentvalue = basevalue + 15);} // 63 19.0°C
if (bitwertNTC>=582&&bitwertNTC<=587){(currentvalue = basevalue + 17);} // 65 18.5°C
if (bitwertNTC>=588&&bitwertNTC<=592){(currentvalue = basevalue + 18);} // 66 18.0°C
if (bitwertNTC>=593&&bitwertNTC<=598){(currentvalue = basevalue + 19);} // 68 17.5°C
if (bitwertNTC>=599&&bitwertNTC<=604){(currentvalue = basevalue + 21);} // 69 17.0°C
if (bitwertNTC>=605&&bitwertNTC<=610){(currentvalue = basevalue + 23);} // 71 16.5°C
if (bitwertNTC>=611&&bitwertNTC<=616){(currentvalue = basevalue + 25);} // 73 16.0°C
if (bitwertNTC>=617&&bitwertNTC<=621){(currentvalue = basevalue + 27);} // 75 15.5°C
if (bitwertNTC>=622&&bitwertNTC<=627){(currentvalue = basevalue + 29);} // 77 15.0°C
if (bitwertNTC>=628&&bitwertNTC<=633){(currentvalue = basevalue + 31);} // 79 14.5°C
if (bitwertNTC>=634&&bitwertNTC<=639){(currentvalue = basevalue + 33);} // 81 14.0°C
if (bitwertNTC>=640&&bitwertNTC<=644){(currentvalue = basevalue + 35);} // 83 13.5°C
if (bitwertNTC>=645&&bitwertNTC<=650){(currentvalue = basevalue + 37);} // 85 13.0°C
if (bitwertNTC>=651&&bitwertNTC<=656){(currentvalue = basevalue + 39);} // 87 12.5°C
if (bitwertNTC>=657&&bitwertNTC<=662){(currentvalue = basevalue + 41);} // 89 12.0°C
if (bitwertNTC>=663&&bitwertNTC<=667){(currentvalue = basevalue + 43);} // 91 11.5°C
if (bitwertNTC>=668&&bitwertNTC<=673){(currentvalue = basevalue + 45);} // 93 11.0°C
if (bitwertNTC>=674&&bitwertNTC<=679){(currentvalue = basevalue + 47);} // 95 10.5°C
if (bitwertNTC>=680&&bitwertNTC<=684){(currentvalue = basevalue + 50);} // 98 10.0°C
if (bitwertNTC>=685&&bitwertNTC<=690){(currentvalue = basevalue + 53);} //101 9.5°C
if (bitwertNTC>=691&&bitwertNTC<=695){(currentvalue = basevalue + 56);} //104 9.0°C
if (bitwertNTC>=696&&bitwertNTC<=701){(currentvalue = basevalue + 58);} //106 8.5°C
if (bitwertNTC>=702&&bitwertNTC<=706){(currentvalue = basevalue + 61);} //109 8.0°C
if (bitwertNTC>=707&&bitwertNTC<=712){(currentvalue = basevalue + 63);} //111 7.5°C
if (bitwertNTC>=713&&bitwertNTC<=717){(currentvalue = basevalue + 66);} //114 7.0°C
if (bitwertNTC>=718&&bitwertNTC<=723){(currentvalue = basevalue + 69);} //117 6.5°C
if (bitwertNTC>=724&&bitwertNTC<=728){(currentvalue = basevalue + 72);} //120 6.0°C
if (bitwertNTC>=729&&bitwertNTC<=733){(currentvalue = basevalue + 75);} //123 5.5°C
if (bitwertNTC>=734&&bitwertNTC<=738){(currentvalue = basevalue + 79);} //127 5.0°C
if (bitwertNTC>=739&&bitwertNTC<=744){(currentvalue = basevalue + 82);} //130 4.5°C
if (bitwertNTC>=745&&bitwertNTC<=749){(currentvalue = basevalue + 85);} //133 4.0°C
if (bitwertNTC>=750&&bitwertNTC<=754){(currentvalue = basevalue + 88);} //136 3.5°C
if (bitwertNTC>=755&&bitwertNTC<=759){(currentvalue = basevalue + 92);} //140 3.0°C
if (bitwertNTC>=760&&bitwertNTC<=764){(currentvalue = basevalue + 96);} //144 2.5°C
if (bitwertNTC>=765&&bitwertNTC<=769){(currentvalue = basevalue + 99);} //147 2.0°C
if (bitwertNTC>=770&&bitwertNTC<=774){(currentvalue = basevalue + 102);} //150 1.5°C
if (bitwertNTC>=775&&bitwertNTC<=779){(currentvalue = basevalue + 107);} //155 1.0°C
if (bitwertNTC>=780&&bitwertNTC<=784){(currentvalue = basevalue + 111);} //159 0.5°C
if (bitwertNTC>=785&&bitwertNTC<=789){(currentvalue = basevalue + 116);} //164 0.0°C
if (bitwertNTC>790){(currentvalue = basevalue + 118);} // alle Werte größer 790 stellen das Thermostat auf 0°C
{SPI.transfer(currentvalue);}
delay(10000); // Warte 10 Sekunden und mache alles nochmal
}
}
Hier gehts zum Download: BEOK.ino