I’m writing code to read values from the DS18B20 sensor using Arduino MKR 1010 WiFi and send them to Blynk in intervals. My wiring is correct and the sensor is returning correct values if used without Blynk (just printing in the serial monitor). But when I add code to connect with the new Blynk I get a value of -127 every time. Is there maybe a conflict between OneWire and Blynk library?
Details :
• Hardware model + communication type: Arduino MKR 1010 WiFi
• Smartphone OS (iOS or Android) + version: iOS 14.6
• Blynk server, Arduino IDE
• Blynk Library version: 1.0.0
Minimal code:
#include <OneWire.h>
#include <DallasTemperature.h>
// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define ONE_WIRE_BUS 0
#define APP_DEBUG
#include "BlynkEdgent.h"
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
BlynkTimer sensorTimer;
void setup()
{
sensors.begin();
sensors.setWaitForConversion(false);
Serial.begin(115200);
delay(100);
BlynkEdgent.begin();
sensorTimer.setInterval(5000L, requestTemperature);
}
void loop() {
BlynkEdgent.run();
sensorTimer.run();
}
void requestTemperature(){
sensors.requestTemperatures();
Serial.print(sensors.getTempCByIndex(0));
Serial.print("°");
Serial.println("C");
Blynk.virtualWrite(5, sensors.getTempCByIndex(0));
}