Automatically turn on/off the boiler with the blynk application and NodeMCU

Hi, I’m working on a project to automatically turn on / off the water heater. The idea is to add the eventor in the blynk application to include the relay ie the water heater at 7pm, and turn it off at 3am. Two more things I’ve added are distance sensors and temperature. However, I started to write the code and I stuttered a little around it … I wrote the code and when I wanted to compile it, the compiler was ejecting an error, which I can not manage to solve …

Here are the schemes:

Should these values be read first with the classic code, or can the application itself do it?
I would be very grateful, if someone helped me a bit! :smiley:

Here’s the code:

#define BLYNK_PRINT Serial
#include <OneWire.h>
#include<DallasTemperature.h>

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

const int trigPin = D0;
const int echoPin = D1;

long duration;
int distance;
int temperature;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

void setup()
{
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

  sensors.begin();
}

BLYNK_READ(V1)
{
  //merenje rastojanja - measuring distance
  //dojavljuje eventoru rastojanje - announces distance to the eventor
  float distance = param.asFloat();
  serial.println(distance);
}

BLYNK_READ(V2)
{
  //merenje temperature - measuring temperature
  //dojavljuje eventoru temperaturu vode -  announces water temperature to the eventor
    float temperature = param.asFloat();
  serial.println(temperature);
}

void loop()
{
  Blynk.run();

  //rastojanje - reading the distance
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  distance = duration*0.034/2;  //razdaljina u cm

  //temperatura - reading the temperature
  temperature = sensors.requestTemperatures();
  delay(1000);
}

Ensure you have verbose set in the IDE. Paste compiler error.

I apologize for possibly irregular spelling, but I am Slovak and I do not know the best English and I use google translate for translation.:slight_smile:

Start by changing the two “serial” entries to “Serial”.

If you are using a computer just cut and paste the compiler errors we don’t want to see pictures.

I forgot to mention that the distance sensor will be used, that when someone enters the bathtub, this sensor detects and automatically turns off the water heater. A heat sensor will be used to display the temperature in the application and if the temperature falls below 40 °C, the water heater is automatically switched on regardless of how much it is hours.

Ok, I’m getting to work and reporting results! :smiley:

First I wiped out an unnecessary library and left only onewire.h … Then I just went to examples and there I found an example for the DS18B20, and I copied a part of void loop code into my code …

#define BLYNK_PRINT Serial
#include <OneWire.h>

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);

OneWire  ds(D2);  // on pin 10 (a 4.7K resistor is necessary)

const int trigPin = D0;
const int echoPin = D1;

long duration;
int distance;
int temperature;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

void setup()
{
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
}

BLYNK_READ(V1)
{
  //merenje rastojanja - measuring distance
  //dojavljuje eventoru rastojanje - announces distance to the eventor
  distance = param.asFloat();
  serial.println(distance);
}

BLYNK_READ(V2)
{
  //merenje temperature - measuring temperature
  //dojavljuje eventoru temperaturu vode -  announces water temperature to the eventor
    celsius = param.asFloat();
  serial.println(celsius);
}

void loop()
{
  Blynk.run();

  //rastojanje - reading the distance
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  distance = duration*0.034/2;  //razdaljina u cm

  //temperature
    byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;
  
  if ( !ds.search(addr)) {
    Serial.println("No more addresses.");
    Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }
  
  Serial.print("ROM =");
  for( i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(addr[i], HEX);
  }

  if (OneWire::crc8(addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return;
  }
  Serial.println();
 
  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      Serial.println("  Chip = DS18S20");  // or old DS1820
      type_s = 1;
      break;
    case 0x28:
      Serial.println("  Chip = DS18B20");
      type_s = 0;
      break;
    case 0x22:
      Serial.println("  Chip = DS1822");
      type_s = 0;
      break;
    default:
      Serial.println("Device is not a DS18x20 family device.");
      return;
  } 

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end
  
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  
  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad

  Serial.print("  Data = ");
  Serial.print(present, HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print(OneWire::crc8(data, 8), HEX);
  Serial.println();

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
}

However, now there is still one mistake, which is:

Arduino: 1.8.5 (Windows 10), Board: "NodeMCU 0.9 (ESP-12 Module), 80 MHz, 115200, 4M (3M SPIFFS)"

In file included from C:\Users\Denis HD\Documents\Arduino\automatski_bojler.ino\automatski_bojler.ino.ino:2:0:

C:\Users\Denis HD\Documents\Arduino\libraries\OneWire/OneWire.h:108:2: error: #error "Please define I/O register types here"

 #error "Please define I/O register types here"

  ^

exit status 1
Error compiling for board NodeMCU 0.9 (ESP-12 Module).

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

So the software asks me to define the I / O registers, but I do not know how to define them because I did not do it before …

This isn’t. Blynk issue.
The error message you’re getting is telling you about a problem with your OneWire library file. It gives you the location and name of the file that requires attention, and I think the 108 in the error message refers to the line number within that OneWire.h file.

I seem to recall some compatibility issues with the original Inewire library and the ESP8266, so it’s possible that you’re using a version of the library that’s incompatible with your hardware.

As I said, it’s not Blynk related, so maybe do a bit of googling?

Pete.

1 Like

So you ignored my valuable advice.

Use a decent DS18B20 tutorial and test it without Blynk Arduino Project Hub

As a novice to Blynk restrict loop() to just 2 lines as per the PUSH_DATA example.

@Costas I did not ignore your advice, I tried to fix what I can … and I found on another forum that the problem is in the folder name … :smiley:
Or if you do not want to read everything from that forum, here’s a quote in which solution:

[quote] I used only the “DS18x20” example sketch.
But you said you got an error regarding IO registers? This means your IDE is using the “normal” OneWire" library located under your “Documents\arduino\libraries” folder, instead of the modified library located in your arduino program folder… (for me, this would be c:\arduino-1.6.1-esp8266\libraries\OneWire for the modified library, and NOT c:\users\dennis\documents\arduino\libraries\OneWire which is the wrong one!!).

(you can see which library path is used, when you enable verbose output for compiling in the arduino IDE, and check the output when testing the sketch). If the library used is the original one, it will fail. In this case I recommend to remove the original “OneWire” folder from your user arduino folder, then restart IDE - and it will use the modified OneWire library.[/quote]

Everything might work out, but now I have a HDD problem because it’s full … so I’ll probably postpone this code writing, so for a couple of days when I buy a second HDD of higher capacity, I’ll try once again to do everything you advised me , and I announce the results …

You did and you ignored the same advice on the other forum you linked to: VERBOSE.

1 Like

Sorry, my mistake … Now it prints a mistake, that there is no library called OneWire.h, so it probably is not a good library, as @PeteKnight said …

Arduino: 1.8.5 (Windows 10), Board: "NodeMCU 0.9 (ESP-12 Module), 80 MHz, 115200, 4M (3M SPIFFS)"

D:\Arduino\arduino-builder -dump-prefs -logger=machine -hardware D:\Arduino\hardware -hardware C:\Users\Denis HD\AppData\Local\Arduino15\packages -tools D:\Arduino\tools-builder -tools D:\Arduino\hardware\tools\avr -tools C:\Users\Denis HD\AppData\Local\Arduino15\packages -built-in-libraries D:\Arduino\libraries -libraries C:\Users\Denis HD\Documents\Arduino-NodeMCU0.9\sketchbook\libraries -fqbn=esp8266:esp8266:nodemcu:CpuFrequency=80,UploadSpeed=115200,FlashSize=4M3M -ide-version=10805 -build-path C:\Users\DENISH~1\AppData\Local\Temp\arduino_build_291021 -warnings=none -build-cache C:\Users\DENISH~1\AppData\Local\Temp\arduino_cache_404259 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.esptool.path=C:\Users\Denis HD\AppData\Local\Arduino15\packages\esp8266\tools\esptool\0.4.9 -prefs=runtime.tools.mkspiffs.path=C:\Users\Denis HD\AppData\Local\Arduino15\packages\esp8266\tools\mkspiffs\0.1.2 -prefs=runtime.tools.xtensa-lx106-elf-gcc.path=C:\Users\Denis HD\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2 -verbose C:\Users\Denis HD\Documents\Arduino-NodeMCU0.9\automatski_bojler.ino\automatski_bojler.ino.ino
D:\Arduino\arduino-builder -compile -logger=machine -hardware D:\Arduino\hardware -hardware C:\Users\Denis HD\AppData\Local\Arduino15\packages -tools D:\Arduino\tools-builder -tools D:\Arduino\hardware\tools\avr -tools C:\Users\Denis HD\AppData\Local\Arduino15\packages -built-in-libraries D:\Arduino\libraries -libraries C:\Users\Denis HD\Documents\Arduino-NodeMCU0.9\sketchbook\libraries -fqbn=esp8266:esp8266:nodemcu:CpuFrequency=80,UploadSpeed=115200,FlashSize=4M3M -ide-version=10805 -build-path C:\Users\DENISH~1\AppData\Local\Temp\arduino_build_291021 -warnings=none -build-cache C:\Users\DENISH~1\AppData\Local\Temp\arduino_cache_404259 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.esptool.path=C:\Users\Denis HD\AppData\Local\Arduino15\packages\esp8266\tools\esptool\0.4.9 -prefs=runtime.tools.mkspiffs.path=C:\Users\Denis HD\AppData\Local\Arduino15\packages\esp8266\tools\mkspiffs\0.1.2 -prefs=runtime.tools.xtensa-lx106-elf-gcc.path=C:\Users\Denis HD\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2 -verbose C:\Users\Denis HD\Documents\Arduino-NodeMCU0.9\automatski_bojler.ino\automatski_bojler.ino.ino
Using board 'nodemcu' from platform in folder: C:\Users\Denis HD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0
Using core 'esp8266' from platform in folder: C:\Users\Denis HD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0
Detecting libraries used...
"C:\Users\Denis HD\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Denis HD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0/tools/sdk/include" "-IC:\Users\Denis HD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0/tools/sdk/lwip/include" "-IC:\Users\DENISH~1\AppData\Local\Temp\arduino_build_291021/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC   -DARDUINO=10805 -DARDUINO_ESP8266_NODEMCU -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_NODEMCU"  -DESP8266 "-IC:\Users\Denis HD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266" "-IC:\Users\Denis HD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\variants\nodemcu" "C:\Users\DENISH~1\AppData\Local\Temp\arduino_build_291021\sketch\automatski_bojler.ino.ino.cpp" -o "nul"
"C:\Users\Denis HD\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\Denis HD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0/tools/sdk/include" "-IC:\Users\Denis HD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0/tools/sdk/lwip/include" "-IC:\Users\DENISH~1\AppData\Local\Temp\arduino_build_291021/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11  -ffunction-sections -fdata-sections -w -x c++ -E -CC -DF_CPU=80000000L -DLWIP_OPEN_SRC   -DARDUINO=10805 -DARDUINO_ESP8266_NODEMCU -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_NODEMCU"  -DESP8266 "-IC:\Users\Denis HD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266" "-IC:\Users\Denis HD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\variants\nodemcu" "C:\Users\DENISH~1\AppData\Local\Temp\arduino_build_291021\sketch\automatski_bojler.ino.ino.cpp" -o "C:\Users\DENISH~1\AppData\Local\Temp\arduino_build_291021\preproc\ctags_target_for_gcc_minus_e.cpp"
C:\Users\Denis HD\Documents\Arduino-NodeMCU0.9\automatski_bojler.ino\automatski_bojler.ino.ino:2:21: fatal error: OneWire.h: No such file or directory

 #include <OneWire.h>

                     ^

compilation terminated.

exit status 1
Error compiling for board NodeMCU 0.9 (ESP-12 Module).

The verbose message you have is indicating that you failed to install the correct libraries.

OneWire works fine with ESP8266’s.

Sure there is… and it works fine in my applications.

@Costas & @Gunner I installed the OneWire.h library, but afterwards the software wrote to me that I had to install the library for ESP8266, and finally, when I wanted to compile, I was told the next error is:

C:\Users\Denis HD\Documents\Arduino-NodeMCU0.9\automatski_bojler.ino\automatski_bojler.ino.ino: In function 'void BlynkWidgetRead1(BlynkReq&)':

automatski_bojler.ino:46: error: 'param' was not declared in this scope

   distance = param.asFloat();

              ^

automatski_bojler.ino:47: error: 'serial' was not declared in this scope

   serial.println(distance);

   ^

C:\Users\Denis HD\Documents\Arduino-NodeMCU0.9\automatski_bojler.ino\automatski_bojler.ino.ino: In function 'void BlynkWidgetRead2(BlynkReq&)':

automatski_bojler.ino:54: error: 'celsius' was not declared in this scope

     celsius = param.asFloat();

     ^

automatski_bojler.ino:54: error: 'param' was not declared in this scope

     celsius = param.asFloat();

               ^

automatski_bojler.ino:55: error: 'serial' was not declared in this scope

   serial.println(celsius);

   ^

Using library OneWire at version 2.3.3 in folder: C:\Users\Denis HD\Documents\Arduino-NodeMCU0.9\sketchbook\libraries\OneWire 
Using library ESP8266WiFi at version 1.0 in folder: C:\Users\Denis HD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WiFi 
Using library Blynk at version 0.5.0 in folder: C:\Users\Denis HD\Documents\Arduino-NodeMCU0.9\sketchbook\libraries\Blynk 
exit status 1
'param' was not declared in this scope

What???
In this tutorial everything works properly, I do not understand why it will not work in my code, when I installed all the necessary libraries?