Quantcast
Channel: Sensors - Arduino Forum
Viewing all articles
Browse latest Browse all 1074

DS18B20 not working reliably on Nano ESP32

$
0
0

Hi all,

I've a strange problem with using two DS18B20 sensors on the Nano ESP32. I'm using the following circuit (the buzzer is not connected atm):

And here are some pictures of my board:


Finally, this is a minimal version of my sketch (adopted from ESP32 DS18B20 Temperature Sensor with Arduino IDE (Single, Multiple, Web Server) | Random Nerd Tutorials):

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

// GPIO where the DS18B20 is connected to
const int oneWireBus = 8;     

OneWire oneWire( oneWireBus );

DallasTemperature sensors( &oneWire );

void setup() {
  // Start the Serial Monitor
  Serial.begin(9600);
  // Start the DS18B20 sensor
  sensors.begin();
}

void loop() {
  Serial.println( "Number of devices:       " + String( sensors.getDeviceCount() ) );
  Serial.println( "Number of DS18* devices: " + String( sensors.getDS18Count() ) );
  sensors.requestTemperatures(); 
  float temperature1 = sensors.getTempCByIndex( 0 );
  float temperature2 = sensors.getTempCByIndex( 1 );
  Serial.println( temperature1 );
  Serial.println( temperature2 );
  delay( 5000 );
}

When I upload my sketch, everything is running fine and I get the following output:

Number of devices:       2
Number of DS18* devices: 2
21.75
21.62

As soon as I disconnect the board from the computer and connect it again, it doesn't work anymore and I get the following output (-127 is an error value):

Number of devices:       0
Number of DS18* devices: 0
-127.00
-127.00

When I reupload the sketch, it also doesn't work.

When I change oneWireBus to 5, i.e. a pin where nothing is connect, upload the sketch it doesn't work as one would expect. However, when I then change oneWireBus back to 8 and upload the sketch, it is working again.

I also tried with one sensor only with the same result.

I'm on Ubuntu 22.04. I tried with Arduino IDE 2.3.3 as well as with Platform IO 6.1.16, both with the same result. OneWire version is 2.3.8, while DallasTemperature version is 3.9.0.

Please let me know if you need some additional information.

Do you have any suggestions on how to further track down the issue?

Thank you in advance for your help!

19 posts - 4 participants

Read full topic


Viewing all articles
Browse latest Browse all 1074

Trending Articles