Multiple DS18B20 / I need help with optimalization

Hello I am new with Blynk… I am programming on ESP8266 Wifi module and I am using iOS App …
I am trying to create multiple thermostats and I want to optimize code, you will understand me If you see the code…

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
#include <DallasTemperature.h>
#include <OneWire.h>

BlynkTimer timer;
WidgetRTC rtc;
OneWire oneWire(2), tep2(0);
DallasTemperature sensors(&oneWire);
DallasTemperature sensors2(&tep2);

char auth[] = "xxxx";
char ssid[] = "xx";
char pass[] = "xx";

float temp = 0;
float temp2 = 0;
double setTemp;
double setTemp2;

void setup()
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, sendSensor);
  timer.setInterval(10000L, realTime);

void loop() {;;
/* ×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××× */
{ Blynk.syncAll(); }

{  setTemp = param.asDouble(); }
{  setTemp2 = param.asDouble();  }

void sendSensor() {
  temp = sensors.getTempCByIndex(0);
  temp2 = sensors2.getTempCByIndex(0);
  Blynk.virtualWrite(V2, "add", 1, "Teplota #1", temp+ String(" °C"));
  Blynk.virtualWrite(V2, "add", 2, "Teplota #2", temp2+ String(" °C"));
  Blynk.virtualWrite(V2, "add", 3, "Teplota #3", "00.00°C");
  Blynk.virtualWrite(V2, "add", 4, "Teplota #4", "00.00°C");
  Blynk.virtualWrite(V2, "add", 5, "Teplota #5", "00.00°C");
  Blynk.virtualWrite(V1, "add", 1, "Vlhkosť #1", "00.00 %");
  Blynk.virtualWrite(V1, "add", 2, "Vlhkosť #2", "00.00 %");
  Blynk.virtualWrite(V1, "add", 3, "Tlak #1", "0.0 bar");
  Blynk.virtualWrite(V1, "add", 4, "Tlak #2", "0.0 bar");
  Blynk.virtualWrite(V1, "add", 5, "Tlak #3", "0.0 bar");
        if (temp > setTemp+1){
          digitalWrite(4, LOW);
        else if (temp < setTemp) {
          digitalWrite(4, HIGH);
        if (temp2 > setTemp2+1){
          digitalWrite(3, LOW);
        else if (temp2 < setTemp2) {
          digitalWrite(3, HIGH);

void realTime() {
  String currentTime = String(hour()) + ":" + minute();
  String currentDate = String(day()) + "." + month() + "." + year();

what ?

This community is not a code factory…
“Optimize my code” is not really “friendly” when you are requesting help…

Oh sorry, I mean it friendly but now I understand you … that wasn´t sound very good. Thanks for comment :slight_smile:

Please, spend a little bit of time searching the information you need in the forum before asking everyone to do it for you…Nobody is gonna code for you…
And… if you paste a piece of code, do it formatted. Instructions are clear about it.
I’m sorry if the picture was not explained properly, that’s why I deleted, I’m just typing using my mobile but I guess now you understand.

@Marek_Vrabel please edit your original post to add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:


1 Like

this “index” is something you need to understand better to make use of DS18B.


What do you mean, understand better ? Should I Google it And read theory About it or ?

Yes, then thank @Dave1829 for pointing you in the right direction.