/**************************************************************
* Main code made by @Amarillo
*
* Hardware model : WeMos D1 mini (in Blynk)
* DS18B20 signal connected to D4 / GPIO 2
**************************************************************
* Blynk is a platform with iOS and Android apps to control
* Arduino, Raspberry Pi and the likes over the Internet.
* You can easily build graphic interfaces for all your
* projects by simply dragging and dropping widgets.
*
* Downloads, docs, tutorials: http://www.blynk.cc
* Blynk community: http://community.blynk.cc
* Social groups: http://www.fb.com/blynkapp
* http://twitter.com/blynk_app
* Blynk library is licensed under MIT license
* This example code is in public domain.
*
**************************************************************
* This example runs directly on ESP8266 chip / WeMos D1 mini
* Change WiFi ssid, pass, and Blynk auth token to run :)
*
* Blynk virtual pins
* V1 - first sensor
* V2 - second sensor
* V3 - third sensor
* V4 - forth sensor
* V5 - minTemp
* V6 - maxTemp
* V7 - reset button
* V8 - Calibration
* V9 - # of sensors / devices
*
* If less than 4 sensors are connected, they simulate sensor # 1 / same temperature
**************************************************************/
#include <DallasTemperature.h>
#include <BlynkSimpleEsp8266.h>;
#define ONE_WIRE_BUS 2 // DS18B20 pin to GPIO2 - on WeMos this is D4
const char* ssid = "SSID";
const char* wifiPassord = "yourPWD";
const char auth[] = "yourBlynkAuthToken3b20681bdb54c8";
float temperatur1, temperatur2, temperatur3, temperatur4;
float kalibrering, maxTemp, minTemp;
int timer1, start;
byte numberOfDevices;
BlynkTimer timer;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
BLYNK_WRITE(V7) {
if (param.asInt()) {
start = millis();
} else {
if (millis() - start > 1000) {
maxTemp = 0;
minTemp = 80;
Blynk.virtualWrite(5, 0); // Sett minTemp (V5) to 0
Blynk.virtualWrite(6, 0); // Sett maxTemp (V6) to 0
}
}
}
BLYNK_WRITE(V8) {
kalibrering = param.asFloat();
}
void setup() {
Serial.begin(115200);
// DS18B20
sensors.begin(); // Start up the sensors library
sensors.setResolution(12); // Mode Resol Conversion time - 9 bits 0.5°C 93.75 ms - 10 bits 0.25°C 187.5 ms - 11 bits 0.125°C 375 ms - 12 bits 0.0625°C 750 ms
sensors.requestTemperatures(); // Get temperature
numberOfDevices = sensors.getDeviceCount(); // Counting DS18B20 devices
Blynk.begin(auth, ssid, wifiPassord);
while (Blynk.connect() == false) {}
Blynk.syncAll();
timer1 = timer.setInterval(5000, hentTemp); // Gets temp every 5 sec.
}
void loop() {
Blynk.run();
timer.run();
}
void hentTemp() {
sensors.requestTemperatures(); // Gets all sensor values
Blynk.virtualWrite(9, numberOfDevices); // Sends # of sensors to Virtual pin V9
Serial.print("\nNo of sensores: "); Serial.println(numberOfDevices); // Writes # of sensors to Serial Monitor (Arduino IDE)
temperatur1 = (sensors.getTempCByIndex(0)); // Get temp from sensor 1
Blynk.virtualWrite(1, temperatur1); // Write temp from sensor 1 to Blynk
if (temperatur1 < minTemp) { minTemp = temperatur1; Blynk.virtualWrite(5, minTemp); } // Update minTemp if temp is lower
if (temperatur1 > maxTemp) { maxTemp = temperatur1; Blynk.virtualWrite(6, maxTemp); } // Update maxTemp if temp is higher
Serial.print("Temp1: "); Serial.println(temperatur1); // Print temp to Serial Monitor (Arduino IDE)
if (numberOfDevices >= 2) { // Runs if 2 sensors
temperatur2 = (sensors.getTempCByIndex(1)); // Get temp from sensor 2
Serial.print("Temp2: "); Serial.println(temperatur2); // Print temp to Serial Monitor (Arduino IDE)
} else { temperatur2 = (sensors.getTempCByIndex(0)); } // If no second sensor, read from sensor #1 to avoid error -127°C
Blynk.virtualWrite(2, temperatur2);
if (temperatur2 < minTemp) { minTemp = temperatur2; Blynk.virtualWrite(5, minTemp); }
if (temperatur2 > maxTemp) { maxTemp = temperatur2; Blynk.virtualWrite(6, maxTemp); }
if (numberOfDevices >= 3) { // Runs if 3 sensors
temperatur3 = (sensors.getTempCByIndex(2));
Serial.print("Temp3: "); Serial.println(temperatur3);
} else { temperatur3 = (sensors.getTempCByIndex(0)); }
Blynk.virtualWrite(3, temperatur3);
if (temperatur3 < minTemp) { minTemp = temperatur3; Blynk.virtualWrite(5, minTemp); }
if (temperatur3 > maxTemp) { maxTemp = temperatur3; Blynk.virtualWrite(6, maxTemp); }
if (numberOfDevices >= 4) { // Runs if 4 sensors
temperatur4 = (sensors.getTempCByIndex(3));
Serial.print("Temp4: "); Serial.println(temperatur4);
} else { temperatur4 = (sensors.getTempCByIndex(0)); }
Blynk.virtualWrite(4, temperatur4);
if (temperatur4 < minTemp) { minTemp = temperatur4; Blynk.virtualWrite(5, minTemp); }
if (temperatur4 > maxTemp) { maxTemp = temperatur4; Blynk.virtualWrite(6, maxTemp); }
}