Using a GPIO as power supply for DS18B20

I have a project that has a DS18B20 connected to it (w 4.k7 resistor)

Occasionally in my experience with these sensors, they deliver nan and sometimes need to have the power disconnected from them.

Is there any reason I can’t/shouldnt use a GPIO 3.3v output as the power supply, so that when the sensor delivers nan I can essentially perform a reboot on the sensor?

I guess not, since average power consumption of Dallas is only 1mA. Perhaps i’d add a small capacitor (from gpio to gnd), though, to eliminate spikes.
Regarding showing “nan”…i have quite some of these and they never show nan. So, perhaps your sensor is faulty, or perhaps you can try with smaller pullup resistor, especially if wire from esp to sensor is long.

I was able to do this with a SHT and BMP280. I found I had to make the pin go high as early as possilbe otherwise it wouldn’t work at all if pin came up after the rest of the software loaded. In my device I was using gpio13.

  on_boot:
    priority: 1000
    then:
      - lambda: |-
          pinMode(13, OUTPUT);
          digitalWrite(13, HIGH);

Made me thinking…
If you cut the power from dallas, i wonder if it will re-initialize and start working again when you re-apply power… usually init is executed at power-on only. So perhaps module reboot is only option… i was thinking purely hardware back up…

The best approach would be to find the actual problem. What you get on log when it freezes?

Just bringing this one back up, getting nan constantly now on temp sensor (no changes made to esphome code). Was working fine for years. I had updated ESPHOME to latest, and I’m fairly sure it started happening after I updated (forget version, but it’s when the menu name changed from “ESPHome” to “ESPHome Builder”)

ESPHome as follows:

esphome:
  name: pooltemp
  friendly_name: pooltemp
  comment: "Tracks swimming pool temperature"

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: *****

ota:
  password: *****
  platform: esphome
  
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    # Set this to the IP of the ESP
    static_ip: 172.16.223.54
    gateway: 172.16.223.254
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Pooltemp Fallback Hotspot"
    password: *****

captive_portal:

mqtt:
  discovery: false
  broker: 192.168.222.100
  port: 1883
  username: *****
  password: *****
  
one_wire:
  - platform: gpio
    pin: D1

sensor:
  - platform: dallas_temp
    address: 0x2d00000aaf857528
    name: "Pool Temperature"
    id: pool_temp

switch:
  - platform: restart
    name: "Pool Temperature Restart"

The log output I get is as follows:

[11:39:07][I][app:100]: ESPHome version 2024.12.2 compiled on Dec 22 2024, 22:19:10
[11:39:07][C][wifi:600]: WiFi:
[11:39:07][C][wifi:428]:   Local MAC: 5C:CF:7F:4C:62:D9
[11:39:07][C][wifi:433]:   SSID: [redacted]
[11:39:07][C][wifi:436]:   IP Address: 172.16.223.54
[11:39:07][C][wifi:439]:   BSSID: [redacted]
[11:39:07][C][wifi:441]:   Hostname: 'pooltemp'
[11:39:07][C][wifi:443]:   Signal strength: -68 dB ▂▄▆█
[11:39:07][C][wifi:447]:   Channel: 1
[11:39:07][C][wifi:448]:   Subnet: 255.255.255.0
[11:39:07][C][wifi:449]:   Gateway: 172.16.223.254
[11:39:07][C][wifi:450]:   DNS1: 0.0.0.0
[11:39:07][C][wifi:451]:   DNS2: 0.0.0.0
[11:39:07][C][logger:185]: Logger:
[11:39:07][C][logger:186]:   Level: DEBUG
[11:39:07][C][logger:188]:   Log Baud Rate: 115200
[11:39:07][C][logger:189]:   Hardware UART: UART0
[11:39:07][C][gpio.one_wire:020]: GPIO 1-wire bus:
[11:39:07][C][gpio.one_wire:021]:   Pin: GPIO5
[11:39:07][W][gpio.one_wire:078]:   Found no devices!
[11:39:07][C][dallas.temp.sensor:029]: Dallas Temperature Sensor:
[11:39:07][C][dallas.temp.sensor:034]:   Address: 0x2d00000aaf857528 (DS18B20)
[11:39:07][C][dallas.temp.sensor:035]:   Resolution: 12 bits
[11:39:07][C][dallas.temp.sensor:036]:   Update Interval: 60.0s
[11:39:07][C][restart:068]: Restart Switch 'Pool Temperature Restart'
[11:39:07][C][restart:070]:   Icon: 'mdi:restart'
[11:39:07][C][restart:090]:   Restore Mode: always OFF
[11:39:07][C][captive_portal:089]: Captive Portal:
[11:39:07][C][mdns:116]: mDNS:
[11:39:07][C][mdns:117]:   Hostname: pooltemp
[11:39:07][C][esphome.ota:073]: Over-The-Air updates:
[11:39:07][C][esphome.ota:074]:   Address: 172.16.223.54:8266
[11:39:07][C][esphome.ota:075]:   Version: 2
[11:39:07][C][esphome.ota:078]:   Password configured
[11:39:07][C][safe_mode:018]: Safe Mode:
[11:39:07][C][safe_mode:019]:   Boot considered successful after 60 seconds
[11:39:07][C][safe_mode:021]:   Invoke after 10 boot attempts
[11:39:07][C][safe_mode:022]:   Remain in safe mode for 300 seconds
[11:39:07][C][api:140]: API Server:
[11:39:07][C][api:141]:   Address: 172.16.223.54:6053
[11:39:07][C][api:143]:   Using noise encryption: YES
[11:39:07][C][mqtt:148]: MQTT:
[11:39:07][C][mqtt:149]:   Server Address: 192.168.222.100:1883 (192.168.222.100)
[11:39:07][C][mqtt:151]:   Username: [redacted]
[11:39:07][C][mqtt:152]:   Client ID: [redacted]
[11:39:07][C][mqtt:153]:   Clean Session: NO
[11:39:07][C][mqtt:155]:   Discovery IP enabled
[11:39:07][C][mqtt:161]:   Topic Prefix: 'pooltemp'
[11:39:07][C][mqtt:163]:   Log Topic: 'pooltemp/debug'
[11:39:07][C][mqtt:166]:   Availability: 'pooltemp/status'
[11:39:07][C][mqtt.sensor:028]: MQTT Sensor 'Pool Temperature':
[11:39:07][C][mqtt.sensor:032]:   State Topic: 'pooltemp/sensor/pool_temperature/state'
[11:39:07][C][mqtt.switch:041]: MQTT Switch 'Pool Temperature Restart': 
[11:39:07][C][mqtt.switch:042]:   State Topic: 'pooltemp/switch/pool_temperature_restart/state'
[11:39:07][C][mqtt.switch:042]:   Command Topic: 'pooltemp/switch/pool_temperature_restart/command'
[11:39:10][W][component:170]: Component dallas_temp.sensor cleared Warning flag
[11:39:10][W][dallas.temp.sensor:074]: 'Pool Temperature' - reading scratch pad failed bus reset
[11:39:10][W][component:157]: Component dallas_temp.sensor set Warning flag: bus reset failed
[11:39:10][D][sensor:093]: 'Pool Temperature': Sending state nan °C with 1 decimals of accuracy

I guess it could possibly be a faulty sensor.

Oh weird nvm, I added this to esphome yaml code and also wiggled some wires around on the device, one of the two things has fixed it.

external_components:
  - source:
      type: git
      url: https://github.com/ssieb/esphome
      ref: onewire
    components: [ gpio ]
    refresh: 1min

To be honest - I get this frequently and even a reboot of the node doesnt seem to rectify the situation.

My guess is that the 18b20 gets out of clock sync and cant recover while it still has power.

The only solution I have found is to cycle the power on the whole node or pull the plug on the sensor (my sensors have plugs)

Are you using a pullup resistor? I had similar issues with a DS18B20 sensor and it turned out to be the pullup resistor wasnt maintaining connection and once i addressed that, it reports 100% reliably now.

yep… use 2.2k (instead of 4.7k) on all my DS18B20s… been there and thought that was the issue… but its not

Isn’t the DS18B20 expecting 5V input? I have it connected to my VIN pin, a GND pin and the oneline to a GPIO pin and it works good. Resistor is also used.

DS18B20 has power supply range of 3.0-5.5V.
So correct way to power it with Esp is 3.3V.

But, it would be good idea to verify the sensor really has >3V supply. Long bad quality wiring can affect it…

The DS18B20 has an open collector output pin, so it is perfectly fine to run it at 5V and use a pull-up to 3V3 when using them with the esp series. I have been doing this successfully for as many years as the esp8266 has been available.

There are now many fakes of the DS18B20 and they do have some different behaviors. The real ones are quite tolerant, some of the fakes not so much.

They are supposed to work fine at lower voltages, but they seem a little more reliable at the higher voltage.

1 Like

You are right, thank’s for correcting!
I saw some time ago research about fake DS18B20s, they ordered those from multiple vendors on all major online marketplaces and the result was they were all fakes.
Ps. 5V voltage compatibility is valid with bare sensor pulled up to 3.3V, NOT for DS18B20-module that has pullup to Vcc of the module.

1 Like

Running on a 5v supply.

My experience with various DS18B20 devices has generally been great. The only troubles I have had are:

  1. I decided to make my own senors and buried them with little to no waterproofing. They lasted months before they succumbed to the damp/corrosive conditions underground.
  2. I bought some that had stainless steel covers but did not actually have any waterproofing other than standard heat shrink (not even the waterproof kind). Most of them worked fine, except the ones in the compost pile. After 30-60 days at 50-60C they had issues. On one or more the power pin broke off and they attempted to work with passive power, despite not having the right amount of power.
  3. My latest batch of (fake) ones for the compost pile started acting strange. I pulled the probe out and they started responding. I put it back in and they were fine again.
  4. When the goats chew the wires in them, they stop working.

So, yeah my experience has been great with some still working after a decade and for months without disruption (which is how long the power is active).

There are different behaviors for the different fake ones, so perhaps your fake ones are less reliable. My oldest ones are real ones, as far as I know, but most like many of mine are fake ones.

That looks boost converter. How are you powering that?
For sure it adds plenty of noise on output.

Power your Esp from quality power supply, like old Samsung charger.
If you have bare sensor, just power it from Esp 5V pin, pullup at 3.3V
if it’s sensor module, from 3.3V pin.
Use good quality cable, far from mains wiring, motors etc.
If it’s still freezing, power it from Gpio-pin and make some automation to reset it.