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.
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
}