DS18B20 with HC-SR04 getting slow down the loop

I am trying to build water level control system with DS18B20 / DH22 with HC-SR04.
configurable menu is add in sketch and selection between DS18B20 / DH22 at different temperature to check the effect on accuracy (in my case).

I only have a problem when I select DS18B20 through configuration menu than pump ON /OFF button (Pump_Btn)response time is increased because of " DallasTemperature.h " 750 ms get reading time slow down the sketch.

I need help just fix the response time of Pump_Btn. which has problem with only DS18B20 and working fine with DH22.

I have many other ideas for the same project but I want to built with minimum cost that's why I an trying to use DS18B20 because it is waterproof.

Didn't open the attachment, but you might try to read ds18b20 asynchronous (Google it).
That avoids the ~750ms waiting time.
Leo..

Do you really need to read the temperature more frequently than once every 750 ms?

Nick_Pyner:
Do you really need to read the temperature more frequently than once every 750 ms?

No, even one reading is enough in one hour . But I dont have idea how to do that.

Wawa:
Didn't open the attachment, but you might try to read ds18b20 asynchronous (Google it).
That avoids the ~750ms waiting time.
Leo..

Thanks for suggestions. That's exactly problem which I am facing. I will try that.

For the one measurement an hour look up millis() based timing. A simple example is Blink Without Delay.

Wawa:
Didn't open the attachment, but you might try to read ds18b20 asynchronous (Google it).
That avoids the ~750ms waiting time.
Leo..

Yes I got it and working now thanks, I have problem to print temperature it did not print in loop as below sketch.

#include <OneWire.h>
#include <DS18B20.h>

const byte ONEWIRE_PIN = 2;
 byte sensorAddress[8] = {0x28, 0xB1, 0x6D, 0xA1, 0x3, 0x0, 0x0, 0x11};

OneWire onewire(ONEWIRE_PIN);
DS18B20 sensors(&onewire);

void setup() {
 
  while(!Serial);
  Serial.begin(9600);

  sensors.begin();
  
  // The first requests sensor for measurement
  sensors.request(sensorAddress);
}

void loop() {
  // If the sesor measurement is ready, prnt the results
  if (sensors.available())
  {
    // Reads the temperature from sensor
    float temperature = sensors.readTemperature(sensorAddress);
    
    // Prints the temperature on Serial Monitor
    Serial.print(temperature);
    Serial.println(F(" 'C"));
    
    // Another requests sensor for measurement
    sensors.request(sensorAddress);
  }

Serial.print(temperature);   // Not printing this Error is 'temperature' was not declared in this scope
    Serial.println(F(" 'C"));
  
  // Here, put your code performs without delay
}