trial error ds18b20 — Esp32 Devkit C V4 simulation

An interactive Esp32 Devkit C V4 circuit simulation you can run free in your browser on Velxio, by dwisatriya32.

Components

Sketch code

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

// DS18B20 pins, reading the flat face: GND, DQ, VDD.
// DQ needs a 4.7k pull-up to 5V — 1-Wire is open-drain.
#define ONE_WIRE_PIN 2

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

void setup() {
  Serial.begin(9600);
  sensors.begin();
  Serial.print("Resolution: ");
  Serial.print(sensors.getResolution());
  Serial.println(" bits");
}

void loop() {
  sensors.requestTemperatures();          // takes 750 ms at 12 bits
  float c = sensors.getTempCByIndex(0);

  if (c == DEVICE_DISCONNECTED_C) {
    Serial.println("no probe on the bus - is the pull-up wired?");
  } else {
    Serial.print(c, 2);
    Serial.println(" C");
  }
  delay(1000);
}

More projects by dwisatriya32