#define INACTIEF 0
#define OPWARMEN 1
#define POMPEN 2
#define PIN_STARTKNOP 2
#define PIN_GROENELED 5
#define PIN_TEMPLED 4
#define PIN_POMP 11
#define PIN_TEMPSENSOR A0
const float BETA = 3950;
byte statusMachine = INACTIEF;
float celsius;
void setup() {
Serial.begin(9600);
pinMode(PIN_STARTKNOP, INPUT_PULLUP);
pinMode(PIN_GROENELED, OUTPUT);
pinMode(PIN_TEMPLED, OUTPUT);
pinMode(PIN_POMP, OUTPUT);
pinMode(PIN_TEMPSENSOR, INPUT);
digitalWrite(PIN_GROENELED, HIGH);
}
void loop() {
//Serial.println(statusMachine);
switch (statusMachine){
case INACTIEF:
buttonCheck();
break;
case OPWARMEN:
opwarmen();
break;
case POMPEN:
pompen();
break;
default:
Serial.println("ERROR. Er is iets mis.");
}
}
void buttonCheck(){
if(digitalRead(PIN_STARTKNOP) == LOW){
digitalWrite(PIN_GROENELED, LOW);
statusMachine = OPWARMEN;
}
}
void opwarmen(){
celsius = 1 / (log(1 / (1023. / analogRead(PIN_TEMPSENSOR) - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print(celsius);
Serial.println("°C");
if(celsius>50){
digitalWrite(PIN_TEMPLED, LOW);
statusMachine = POMPEN;
} else {
digitalWrite(PIN_TEMPLED, HIGH);
statusMachine = OPWARMEN;
}
}
void pompen(){
}
void Temperatuur(){
celsius = 1 / (log(1 / (1023. / analogRead(PIN_TEMPSENSOR) - 1)) / BETA + 1.0 / 298.15) - 273.15;
}
/*
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
*/