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?

I have the same problem when using DS18B20 with ESP and Blynk. I connect my wire bus of the sensor to pin 4, and the ESP never connect to the WiFi. I changed the pin and got the same result until I reached pin 25, which surprisingly worked. However, this is not a solution that we have to change pins because of library conflict, not hardware requirements. I tried Arduino IoT clouds and did not have any problem with using any pin for DS sensor.

It’s difficult to comment without seeing your full sketch, and your Settings.h file too.
Edgent uses several of the ESP32’s pins for LED status indication and for a button to clear the saved WiFi credentials. If a board type with RGB LED is chosen then considerably more pins are used. These aren’t part of the Blynk Library, they are part of the Edgent example sketch.

Pete.

Blynk Edgent is optional, try without it.

Hello,

Would you please help in solving my issue? I have read an old post here, and many have had the same problem. When using the ESP32 to get a temperature from DS18B20 it worked. Unfortunately, and for some reason, once extended the code with the Blynk library, wifi would not work. At first, I thought it was a coding problem; however, removing the DS18B20 wire made the wifi worded. Later I tested every pin, and when I reached pin 25, the wifi and the sensor both worked fine. I tried this with many other same boards and had the same problem. Therefore, I believe that something with the Blynk library caused this problem. Any advice, please?

It doesn’t help if we try to have the same conversation in multiple places, so let’s keep it here rather than in a new topic.

As we’ve explained, you appear to be confused by the difference between the Blynk library and the Blynk Edgent example sketch.

It would probably help if you shared full details of your sketch (correctly formatted with triple backticks) details of your board and your sensor, and how you are powering both, along with information about any changes you’ve made to the Settings.h tab within Blynk Edgent.

If you’re experiencing an issue where the board will not boot or connect to the Blynk server when connecting your sensor to a pin <24 then details of the exact symptoms, along with what you see in your serial monitor (also copied and pasted with triple backticks) will be useful.

Pete.

I did, and I had the same problem.

I could see others did share their outputs. I accidentally bring the board to my desk where the WiFi router is just underneath and the board was connected. I surprised, then when I moved it back to the other room, I got the same issue. No WiFi connection. So, I did these steps to ensure it is not WiFi signal that not strong enough,
1- remove the DS sensor wire from pin 34 to 25 = all worked very well.
2- return the sensor to pin 34 = not working.
3- Tried to use thingspeak to upload temperature readings to the cloud with wire at 34 = worked.
4- Tried to use Arduino IoT cloud to upload temperature readings to the cloud with wire at 34 = worked.
5- repeat all 2,3, and 4 steps with different pins as DS inputs = worked.
6- Tried with simple Blynk sketch without using edge:
6.1- pin 34, 35 = did not work.
6.2- pin 25, worked.
There are no any other wire connected to the board, just the DS sensor, so no other I/O identified in the sketch.

Just tested an ESP32 + DS18B20 (PIN 32)
USE 3.3V to feed the sensor!

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  This example runs directly on ESP32 chip.

  Note: This requires ESP32 support package:
    https://github.com/espressif/arduino-esp32

  Please be sure to select the right ESP32 module
  in the Tools -> Board menu!

  Change WiFi ssid, pass, and Blynk auth token to run :)
  Feel free to apply it to any other example. It's simple!
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

/* Fill-in your Template ID (only if using Blynk.Cloud) */
#define BLYNK_TEMPLATE_ID "xxxxxxxxxx"
#define BLYNK_DEVICE_NAME "Blynk20 ESP32"
#define BLYNK_AUTH_TOKEN "yyyyyyyyyyyyyyyyyyyyyyyyyyyy"

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

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

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

BlynkTimer timer;


//********************* ds18b20 DETAILS ******************************************
#include <OneWire.h> //ds18b20 Temp
#include <DallasTemperature.h> //ds18b20 Temp
#define Pin 32//  pin DATA ds18b20
OneWire oneWire(Pin); // OneWire PIN DATA
DallasTemperature sensors(&oneWire); //Se instancia la librería DallasTemperature
float temp;
//*********************************************************************************

void setup()
{
  // Debug console
  Serial.begin(115200);
  sensors.begin();// Sensor ds18b20 
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(5000L, leeTEMP);    // Check sensor
}

void leeTEMP() 
{
  sensors.requestTemperatures();
  temp = sensors.getTempCByIndex(0);
  Blynk.virtualWrite(V0, temp); 
  Serial.print("TEMP:");
  Serial.println(temp);
}

void loop()
{
  Blynk.run();
  timer.run();
}

Result:

And the Mobile APP:

1 Like

I followed your steps; it worked when I was just next to the WiFi router, stepped a few meters away and got no connection. I ordered a new board and assessed it, got the same problem. If I use any other IoT platform except blynk, it does work perfectly. So I just changed the GPIO input to solve the problem.