#include #include #include #include #include #include #include #include #include #include Adafruit_BME280 bme; #define D0 16 #define D1 5 #define D2 4 #define D3 0 #define D4 2 #define D5 14 #define D6 12 #define D7 13 #define D8 15 #define ONE_WIRE_BUS 2 const char* ssid = "your network"; // Enter SSID here const char* password = "your password"; //Enter Password here const char* PARAM_INPUT_1 = "input1"; const char* PARAM_INPUT_2 = "input2"; const char* PARAM_INPUT_3 = "input3"; int pwm_out_pin = D7; //PWM output pin int sw1_ip1 = D6; //switch 1 i/p1 int sw1_ip2 = D5; //switch 2 i/p2 int val1 = 0; int val2 = 0; int sda_pin = D2; // pin to connect to SDA pin on LCD (can be any data pin) int scl_pin = D1; // pin to connect to SCL pin on LCD (can be any data pin) LiquidCrystal_I2C lcd(0x27,20,4); // start up LCD as 16 characters X 2 lines unsigned long previousMillis = 0; const long interval = 2000; float temperature, humidity, pressure, altitude; OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); DeviceAddress TopHeat = {0x28,0xFF,0x64,0x02,0xE8,0x3F,0xF3,0x00}; DeviceAddress BotHeat = {0x28,0xFF,0x64,0x02,0xE8,0x38,0x43,0x5C}; //the following 3 lines are only required for a static network address IPAddress local_IP(192, 168, xx, xx); IPAddress gateway(192, 168, xx, xx); // Set your Gateway IP address IPAddress subnet(255, 255, 255, 0); ESP8266WebServer server(80); // Variable to store the HTTP request String header; //variables for boiling temperature calculations const double hvapmeth = 35300.0;//vapour constant for methanol J/mol const double hvapeth = 38560.0;//vapour constant for ethanol J/mol const double hvapwater = 40800.0;//vapour constant for const double pvapsealev = 760.0;//pressure at sea level mmHG const double ethbpsealev = 78.0;//boiling point of ethanol at sea level deg C const double methbpsealev = 64.7;//boiling point of methanol at sea level deg C const double watbpsealev = 100.0;//boiling point of water at sea level deg C float BPMeth = 0.0; //boiling point of methanol float BPEth = 0.0; //boiling point of ethanol float BPWater = 0.0; //boiling point of watervapabsol = 0.0;//initialise the absolute pressure variable float pressure_mmhg = 0.0; float pressure_mb = 0.0; float bottom_heat = 0.0; float top_heat = 0.0; float xhd = 5.0; float xht = -4.0; float xtl = 10.0; const int analogInPin = A0; int power = 0; int power_percent = 0; String state = ""; void setup() { Serial.begin(115200); sensors.begin(); Wire.begin(sda_pin, scl_pin); lcd.init(); lcd.backlight(); lcd.home(); lcd.clear(); pinMode(sw1_ip1, INPUT); pinMode(sw1_ip2, INPUT); analogWrite(pwm_out_pin, 0); analogWriteFreq(100); // Initialize the sensor (it is important to get calibration values stored on the device). if (bme.begin(0x76)){ lcd.println("BME280 init success"); lcd.setCursor(0,0); delay(2000); lcd.clear(); } else { // Oops, something went wrong, this is usually a connection problem, // see the comments at the top of this sketch for the proper connections. lcd.println("BME280 init fail"); } Serial.println("Connecting to "); Serial.println(ssid); //Connect to your local wi-fi network delay(1000); WiFi.mode(WIFI_STA); if (!WiFi.config(local_IP, gateway, subnet)) { lcd.print("Connecting to "); } WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting WiFi.."); } delay(2000); Serial.println("WiFi connected..!"); Serial.print("Got IP: "); Serial.println(WiFi.localIP()); lcd.setCursor(0, 0); lcd.println("Address:http://"); lcd.setCursor(0, 1); lcd.println(WiFi.localIP()); delay(2000); server.on("/get", HTTP_GET, [] (WebServerRequest *request) { String inputMessage; String inputParam; // GET input1 value on /get?input1= if (request->hasParam(PARAM_INPUT_1)) { inputMessage = request->getParam(PARAM_INPUT_1)->value(); inputParam = PARAM_INPUT_1; } // GET input2 value on /get?input2= else if (request->hasParam(PARAM_INPUT_2)) { inputMessage = request->getParam(PARAM_INPUT_2)->value(); inputParam = PARAM_INPUT_2; } // GET input3 value on /get?input3= else if (request->hasParam(PARAM_INPUT_3)) { inputMessage = request->getParam(PARAM_INPUT_3)->value(); inputParam = PARAM_INPUT_3; } else { inputMessage = "No message sent"; inputParam = "none"; } Serial.println(inputMessage); request->send(200, "text/html", "HTTP GET request sent to your ESP on input field (" + inputParam + ") with value: " + inputMessage + "
Return to Home Page"); }); // server.on("/", handle_OnConnect); // server.onNotFound(handle_NotFound); server.onNotFound(notFound); server.begin(); Serial.println("HTTP server started"); } // void handle_NotFound(){ // server.send(404, "text/plain", "Not found"); //} //void handle_OnConnect() { // server.send(200, "text/html", SendHTML(top_heat,bottom_heat,pressure,power_percent)); //} void loop() { unsigned long currentMillis; currentMillis = millis(); // Loop here getting pressure readings every 5 seconds. if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; // lcd.clear(); int set_power = analogRead(analogInPin); power = set_power/4; power_percent = set_power/10; analogWrite(pwm_out_pin, power); sensors.requestTemperatures(); top_heat = sensors.getTempC(TopHeat); bottom_heat = sensors.getTempC(BotHeat); temperature = bme.readTemperature(); pressure = bme.readPressure() / 100.0F; val1 = digitalRead(sw1_ip1); val2 = digitalRead(sw1_ip2); // lcd.home(); pressure_mmhg = pressure * 0.75; //set pressure in mmhg //calculating for Methanol float Tm = 64.7 + 273; float Tmx = 1/Tm; float pvapT1 = 760; //sea level pressure mmhg float a = log(pvapT1/pressure_mmhg); //first part of calculation float r = 8.3145; // r factor in joules/Kmol float b = hvapmeth/r; // float c = b * Tmx; float d = a + c; BPMeth = (b/d)-273; //calculating for Ethanol float Te = 78.0 + 273; float Tex = 1/Te; float e = hvapeth/r; // float f = e * Tex; float g = a + f; BPEth = (e/g)-273; //calculating for water float Tw = 100.0 + 273; float Twx = 1/Tw; float h = hvapwater/r; // float i = h * Twx; float j = a + i; BPWater = (h/j)-273; // calculate the cut points float headV = (BPMeth + xhd); float heartV = (BPEth - xht); float tailV = (BPEth + xtl); float headF = ((((BPMeth + xhd) / 16)- headV) * 16) / 0.0625; float heartF = ((((BPEth - xht) / 16)- heartV) * 16) / 0.0625; float tailF = ((((BPEth + xtl) / 16)- tailV) * 16) / 0.0625; if (top_heat <= headV){ state = "Foresh"; } if (top_heat >= headV && top_heat <= heartV){ state = "Heads "; } if (top_heat >= heartV && top_heat <= tailV){ state = "Hearts"; } if (top_heat >= tailV){ state = "Tails "; } if (val1 && val2){ Serial.println("switches off"); Serial.print("pressure="); Serial.print(pressure,2); Serial.print(" mB"); Serial.println(); Serial.print("Vap="); Serial.print(top_heat,2); Serial.print(" DegC"); Serial.print("Keg="); Serial.print(bottom_heat,2); Serial.print(" DegC"); Serial.println(); lcd.setCursor(0, 0); // set cursor to zero position on line 1 lcd.println(" Still Measurements "); lcd.setCursor(0, 1); // set cursor to zero position on line 1 lcd.print("Vap = "); lcd.print(top_heat,2); lcd.print("Deg C "); lcd.setCursor(0, 2); // set cursor to zero position on line 2 lcd.print("Keg = "); lcd.print(bottom_heat,2); lcd.print("Deg C "); lcd.setCursor(0, 3); // set cursor to zero position on line 3 lcd.print("pres="); lcd.print(pressure,2); lcd.print("mB"); lcd.print(" "); lcd.print(state); } if (val1 && !val2){ Serial.println("switch1on"); Serial.print("Meths Boil="); Serial.print(BPMeth); Serial.print(" DegC"); Serial.println(); Serial.print("Eth Boil="); Serial.print(BPEth); Serial.print(" DegC"); Serial.println(); Serial.print("Water Boil="); Serial.print(BPWater); Serial.print(" DegC"); Serial.println(); lcd.setCursor(0, 0); // set cursor to zero position on line 1 lcd.println(" Boiling Points "); lcd.setCursor(0, 1); // set cursor to zero position on line 1 lcd.print("Methanol="); lcd.print(BPMeth,2); lcd.print(" DegC "); lcd.setCursor(0, 2); // set cursor to zero position on line 2 lcd.print("Ethanol ="); lcd.print(BPEth,2); lcd.print(" DegC "); lcd.setCursor(0, 3); // set cursor to zero position on line 3 lcd.print("Water ="); lcd.print(BPWater,2); lcd.print(" DegC "); } if (val2 && !val1){ Serial.println("switch2on"); Serial.print(headV); Serial.println(); Serial.print(heartV); Serial.println(); Serial.print(tailV); Serial.println(); lcd.setCursor(0, 0); lcd.println(" Still Setup "); lcd.setCursor(0, 1); // set cursor to zero position on line 1 lcd.print("Heads Val="); lcd.print(headV); lcd.print("Deg C"); lcd.setCursor(0, 2); // set cursor to zero position on line 2 lcd.print("Heart Val="); lcd.print(heartV); lcd.print("Deg C"); lcd.setCursor(0, 3); // set cursor to zero position on line 3 lcd.print("Tails Val="); lcd.print(tailV); lcd.print("Deg C"); } } server.handleClient(); } String SendHTML(float top_heat,float bottom_heat,float pressure,float power_percent){ String ptr = ""; ptr +=""; ptr +=""; ptr +="Distil Controller"; ptr +=""; ptr +=""; ptr +=""; ptr +="\n"; ptr +=""; ptr +=""; ptr +="

Still Controller

"; ptr +="
"; ptr +="
"; ptr +="
"; ptr +=""; ptr +="
"; ptr +="
Vapour Temperature
"; ptr +="
"; ptr +=(int)top_heat; ptr +="°C
"; ptr +="
"; ptr +="
"; ptr +="
"; ptr +=""; ptr +="
"; ptr +="
Keg Temperature
"; ptr +="
"; ptr +=(int)bottom_heat; ptr +="°C
"; ptr +="
"; ptr +="
"; ptr +="
"; ptr +=""; ptr +="
"; ptr +="
Pressure
"; ptr +="
"; ptr +=(int)pressure; ptr +="mB
"; ptr +="
"; ptr +="
"; ptr +="
"; ptr +=""; ptr +="
"; ptr +="
Power Percent
"; ptr +="
"; ptr +=(int)power_percent; ptr +="%
"; ptr +="
"; ptr +="
"; ptr +="
"; ptr +="input1: "; ptr +=""; ptr +="

"; ptr +="
"; ptr +="input2: "; ptr +=""; ptr +="

"; ptr +="
"; ptr +="input3: "; ptr +=""; ptr +="
"; ptr +=""; ptr +=""; return ptr; }