#include // Including library for dht #include LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // defining the pins used for the display #define dht_dpin 13 // defining the pin used for the dht sensor dht DHT; #define pwm 9 // defining the pin used to set at pwm value to control the speed of the fan byte degree[8] = { 0b00011, 0b00011, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000 }; void setup() { lcd.begin(16,2); lcd.createChar(1, degree); lcd.clear(); lcd.print(" Fan Speed "); lcd.setCursor(0,1); lcd.print(" Controlling "); analogWrite(pwm, 255); delay(2000); lcd.clear(); lcd.print("Circuit Digest "); lcd.clear(); delay(2000); analogWrite(pwm,127); delay(2000); Serial.begin(9600); // starts the communication for the serial monitor at xxxx baud speed } int fanspeed=0; //variabel used to store the vaue of the speed the fan i set to unsigned int outdoor=0; char incomingByte; void loop(){ //her angiver vi at den skal læse fra DHT sensor DHT.read11(dht_dpin); //her angiver en variabel som er temp læst fra dht11 sensor int temp=DHT.temperature; //her angiver vi en variabel ser er humidity fra dht11 sensor int humi=DHT.humidity; //her angiver vi hvor vores fan speed skal stå på displayet lcd.setCursor(0,1); //Her sætter vi kommandoer afhængigt af temp if(temp <24 ) { analogWrite(9,0); analogWrite(pwm, 0); fanspeed=0; lcd.print("Fan OFF "); delay(100); } else if(temp==24) { analogWrite(pwm, 51); lcd.print("Fan Speed: 20% "); fanspeed=20; //Serial.print("Fan Speed: 20% "); delay(100); } else if(temp==25) { analogWrite(pwm, 102); lcd.print("Fan Speed: 40% "); fanspeed = 40; //Serial.print("Fan Speed: 40% "); delay(100); } else if(temp==26) { analogWrite(pwm, 153); lcd.print("Fan Speed: 60% "); fanspeed = 60; //Serial.print("Fan Speed: 60% "); delay(100); } else if(temp==27) { analogWrite(pwm, 204); lcd.print("Fan Speed: 80% "); fanspeed = 80; //Serial.print("Fan Speed: 80% "); delay(100); } else if(temp>27) { analogWrite(pwm, 255); lcd.print("Fan Speed: 100% "); fanspeed = 100; //Serial.print("Fan Speed: 100% "); delay(100); } if (Serial.available() > 0) { // something came across serial outdoor = 0; // throw away previous integerValue while(1) { // force into a loop until 'n' is received PÅ dansk køre loop indtil der er linjeskift incomingByte = Serial.read(); if (incomingByte == '\n') break; // exit the while(1), we're done receiving - Bryder LOOP med linjeskift if (incomingByte == -1) continue; // if no characters are in the buffer read() returns -1 outdoor *= 10; // shift left 1 decimal place outdoor = ((incomingByte - 48) + outdoor); // convert ASCII to integer, add, and shift left 1 decimal place } // Her skrives data til serial Serial.print(outdoor); // writes the ourdoor temperature taken from node-red(who got i from weather.com) Serial.print(','); Serial.print(temp); // writes the Temperature measured with the dht11 to the serial Serial.print(','); Serial.print(fanspeed); // Writes the Fanspeed in % to the serial monitor Serial.print(','); Serial.print(humi); Serial.println(); // making a new line, making i posiible for node-red to split the data belonging together. } // Her skrives temp og humidity til lcdscreen, lcd.setCursor(0,0); lcd.print("In"/*,DHT.temperature,"C",DHT.humidity,"%"*/); lcd.setCursor(3,0); lcd.print(temp); lcd.setCursor(5,0); lcd.print((char)223); lcd.setCursor(6,0); lcd.print("C"); lcd.setCursor(8,0); lcd.print("Out"/*,DHT.temperature,"C",DHT.humidity,"%"*/); lcd.setCursor(12,0); lcd.print(temp); //HER SKAL HENTES EN TEMP UDE FRA evt DATABASE lcd.setCursor(14,0); lcd.print((char)223); lcd.setCursor(15,0); lcd.print("C"); delay(5000); // FOr at DHT sensor kan nå at læse // Grunden til ar der her kun er 2400 ms i delay er for at in og out temp står lige lang tid på lcd, hvis man læser den forgående kode igennem er der // 100ms if/elseif statement og efter den 3000ms + de 1900 ms herunder }