BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       👉 SKETCH BUILDER

Problems with ESP32 and DS18B20

Hey guys,
I have a problem with the setup listed below. I’m using Blynk Edgent as recommended. When I boot the ESP with the data pin from the temperature sensor connected, the esp won’t connect to Wi-Fi. If I boot the esp with the data pin disconnected, it connects immediately. After it’s connected successfully, I can reconnect the data pin, and it works just fine. The device is not placed near me, so I can’t always go there to reboot the device in case of a failure.

• ESP32 Dev Module
• Blynk server
• Blynk Library V1.1.0
• DS18B20 Waterproof temperature sensor with 4.7k ohm resistor connected in normal mode on GPIO4

Without seeing you sketch and your Settings.h file, or your serial output it’s difficult to give a definitive answer.
However, I’d guess that whatever board type you’ve un-commented, or the custom board type if you haven’t un-commented any, is causing a pin conflict in Settings.h.

Have a read of this for more info…

Pete.

Hey Pete, thanks for the reply! Serial monitor only gives 701 error after a long time of waiting for the connection with data pin connected. Settings.h is untouched.

#define BLYNK_PRINT Serial

#define BLYNK_NO_BUILTIN

#define APP_DEBUG

#define USE_ESP32S2_DEV_KIT

#include "BlynkEdgent.h"

#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 4

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

BlynkTimer timer;

bool connected = false;

float lastTemperature;
float getWaterTemperature()
{
	sensors.requestTemperatures(); // Send the command to get temperatures
	float temperature = sensors.getTempCByIndex(0);

	if (temperature == 85.00 || temperature == -127.00) //take the last correct temperature value if getting 85 or -127 value
	{
		temperature = lastTemperature;
	}
	else
	{
		lastTemperature = temperature;
	}

	return temperature;
}

void myTimer() 
{
  Blynk.virtualWrite(V3, getWaterTemperature());  
}

BLYNK_CONNECTED()
{
  connected = true;
  Blynk.syncAll();
}

void setup() 
{  
  Serial.begin(115200);
  delay(100);

  BlynkEdgent.begin();

  sensors.begin();

  timer.setInterval(5000L, myTimer);
}

void loop() 
{
  BlynkEdgent.run();
  if (connected) {
    timer.run();
  }
}

Button pin works, so I’m pretty sure it’s the right board I’m using.

Seeing the ACTUAL text is what I was hoping for, preferable with and without the sensor connected.

Your code is missing Template ID etc.

I also have my doubts about the logic of the way you’re using the connected variable.

Pete.

I wasn’t sure about posting my Template ID here, that’s why I removed this information before posting here.
As said, I don’t have the device near me, it’s a few kilometers drive away, so I don’t have access to the serial monitor currently. But really, there is no relevant information there. It just says connecting and then after a couple of minutes the error, nothing more. The connected variable was a try to keep the sensor from reading before it is connected. I first thought that that’s the problem. Even if I just upload the esp32 edgent example without any changes to it, it won’t connect if I have the data pin connected. That’s why I don’t think it’s a code issue.

You should always redact that information, but not entirely delete those lines of code, as they play a key role in correctly compiling the sketch for Blynk IoT. Without them it appears to community members that the sketch is incorrectly structured for Blynk IoT.

That’s not a good way to do it. The logical test should be at the beginning of your myTimer function.

The only pin that should cause this type of behaviour is GPIO12. If that pin is pulled HIGH at boot time the board will enter programming mode, not run mode.

You mention a resistor in your original post. Can you elaborate on exactly how your sensors is connected to the board (all connections, including power, ground and your resistor)?

The serial output is the only window we have onto what is happening when the board boots, so unless there is an issue with how you’ve wired your sensor then seeing the serial output with and without the sensor connected is the only thing that will give us more clues.

Pete.

I just drove to the esp to get some serial output.

Booting with data pin connected:

[249] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.1.0 on ESP32

 #StandWithUkraine    https://bit.ly/swua

[255] --------------------------
[258] Product:  Farm Box
[260] Firmware: 0.1.1 (build Sep 21 2022 17:36:09)
[265] Token:    
[270] Device:   ESP32 @ 240MHz
[273] MAC:      
[276] Flash:    4096K
[278] ESP sdk:  v3.3.5-1-g85c43024c
[281] Chip rev: 1
[283] Free mem: 268668
[285] --------------------------
>[288] INIT => CONNECTING_NET
[328] Connecting to WiFi: 1und1 Mobile WLAN-AFBB
[50339] Connecting to WiFi: 1und1 Mobile WLAN-AFBB
[100350] Connecting to WiFi: 1und1 Mobile WLAN-AFBB
[150361] Connecting to WiFi: 1und1 Mobile WLAN-AFBB
[200372] Connecting to WiFi: 1und1 Mobile WLAN-AFBB
[250383] Connecting to WiFi: 1und1 Mobile WLAN-AFBB

It just keeps trying to connect.
Without the pin connected:

[241] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.1.0 on ESP32

 #StandWithUkraine    https://bit.ly/swua

[247] --------------------------
[250] Product:  Farm Box
[252] Firmware: 0.1.1 (build Sep 21 2022 17:36:09)
[257] Token:    
[262] Device:   ESP32 @ 240MHz
[265] MAC:      
[268] Flash:    4096K
[270] ESP sdk:  v3.3.5-1-g85c43024c
[273] Chip rev: 1
[275] Free mem: 268668
[277] --------------------------
>[280] INIT => CONNECTING_NET
[284] Connecting to WiFi: 1und1 Mobile WLAN-AFBB
[3138] Using Dynamic IP: 192.168.8.102
[3138] CONNECTING_NET => CONNECTING_CLOUD
[3148] Connecting to blynk.cloud:443
[4420] Certificate OK
[4462] Ready (ping: 40ms).

Connected the resistor like this, but on GPIO4:

How are you powering your ESP32?
Is it via the 5v pin with a 5v PSU, via the USB connector with a 5v PSU, or via the 3.3v pin with a 3.3v PSU?

Is your PSU good? Can it deliver sufficient voltage and current? Have you put a meter across the PSU and measured the voltage it delivers when the board boots?

Pete.

I use a 12v power supply with 2 amps output connected to a step-down converter and then to the 5v input of the esp. I think that should be enough to power an esp32 with 1 sensor connected. Haven’t measured the voltage though, could do that tomorrow.

It depends on how much current the step-down converter can provide, and how close to 5V the output is.

Try a little experiment - remove the external power supply and then power the ESP32 and sensor via the USB socket. Use a good USB power supply or power bank and a good quality USB cable.

Pete.

Should the ds18b20 not be connected to 3.3v with esp32?