Esp32 V2 with DS18B20

Hi I’m nic.
I am testing with esp32V2 and DS18B20.
However, there was a problem.
Read the correct data only on pin 14. The rest of the pins are shown as Caution-127.
I used onewire and dallas library.
Is there a problem?
I want to read the data using pin 36.

Hello, I want to know more about the situation.
I don’t know how pin 14 differs from other pins.
Can you show your code?

Pin36 is a free pin,

Pin36 I believe is an input only pin. It will not send a the commands to the DS18B20.

The DS18B20 can be programmed as an alarm only device, I have not done this myself but from what I understand you would put the DS18B20 in to another arduino and set the alarm threshold, the chip will then check the temperature and compare it with what you have set in the user rom and if that is exceeded fire an alarm state out the 1wire line.

If however you are reading the temperatures you need to send a command to the DS18B20 using the onewire lib and tell it to return the temperature.

on startup you also need to configure the DS18B20 with the relevant settings like what resolution you want returned etc…

I have a unit that was running 40 DS18B20’s off pin 4 and was working a treat, there however was a minor timing issue I had to deal with. After the system came out of deep sleep I had to send the request temperatures twice for some reason or the first sensor in the chain would not return the correct temperature.

To conserve poser I also used the VEXT line to cut power to the sensors when they were not being read. So how my program flow went was like this…

  1. wakeup from deep sleep
  2. enable VEXT
  3. send the resolution required to the DS18B20 (could have set this permanently but for the sake of one line versus several lines it was easier to set it each time the system woke up)
  4. broadcast the get temperatures message
  5. read each sensor’s temperature based on the sensors index.
  6. store the temperatures on the CF card
  7. go back to sleep

Hope this makes sense and helps you out :slight_smile:

I am trying to use a ds18b20 for weeks now and cannot have any answer than -127. I tried almost all available ports and when I read this post, I also tried port 14 without success. Here is how I initiate the sensor:
#define ONE_WIRE_BUS 13
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

Then I start the sensor, and in the loop, I read it, but nothing. I am losing my mind :slight_smile:

Can you provide your code?

Hi, Thks, here it is

#include <Arduino.h>
#include <heltec.h>

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

// Data wire is plugged into port 13 on the Arduino
//#define ONE_WIRE_BUS 13

//OneWire oneWire(ONE_WIRE_BUS);
OneWire ds(13);
DallasTemperature sensors(&ds);

//DallasTemperature sensors(&oneWire);

void setup() {
// Start the Serial Monitor
Serial.println(“Serial begins”);
// Start the DS18B20 sensor

float Temperature = (float)(sensors.getTempCByIndex(0));
float temperatureC = sensors.getTempCByIndex(0);
float temperatureF = sensors.getTempFByIndex(0);

Serial.println(“Go to sleep”);

void loop() {

I tested this code, it works fine.

I used these two libraries.

Thks Shaffer. In fact the problem was at 20 inches of the module… maybe when I soldered the module I didn’t do it in the right manner.
I had another module and I connected the wire, now I have the temperature. I am using your libraries.

Thank you again, without your help, I don’t think I had found my problem. When you said my code works for you, the problem need to be the module itself.

1 Like