Index
Introduction
The Digital Temperature Sensor is used to measure temperature and provide a digital output signal. The sensor continuously monitors the surrounding temperature and changes its output state when a preset threshold is reached. The ESP32 can read this digital signal and determine whether the temperature is above or below the threshold. In this tutorial, we’ll interface a Digital Temperature Sensor with the ESP32 and monitor its status through the Serial Monitor.
Required Components
- ESP32 Board
- Digital Temperature Sensor Module
- Jumper wires
- Breadboard
Pinout

Circuit Diagram / Wiring

- Digital Temperature Sensor VCC → 3.3V (ESP32)
- Digital Temperature Sensor GND → GND (ESP32)
- Digital Temperature Sensor DO → GPIO 15 (ESP32)
Code / Programming
/*
Filename: ol_digital_temperature_sensor.ino
Description: Reads digital temperature sensor status and prints result via Serial Monitor
Author: www.oceanlabz.in
Modification: 1/4/2025
*/
#define TEMP_SENSOR_PIN 15
void setup() {
Serial.begin(115200);
pinMode(TEMP_SENSOR_PIN, INPUT);
}
void loop() {
int sensorState = digitalRead(TEMP_SENSOR_PIN);
if (sensorState == LOW) {
Serial.println("Temperature Above Threshold");
} else {
Serial.println("Temperature Below Threshold");
}
delay(500);
}
Explanation
- The TEMP_SENSOR_PIN reads the digital output from the temperature sensor module.
- The sensor compares the measured temperature with the threshold set by the onboard potentiometer.
- When the temperature exceeds the threshold value, the sensor output changes state.
- The ESP32 continuously monitors the sensor output and displays the status on the Serial Monitor.
Troubleshooting
- Ensure that the sensor is powered correctly (VCC to 3.3V and GND to GND) and that the DO pin is connected to GPIO 15.
- If the sensor does not respond, adjust the onboard potentiometer to set an appropriate temperature threshold.
- If the readings appear unstable, check the wiring connections and ensure a stable power supply.
- If no messages appear in the Serial Monitor, verify that the correct COM port and ESP32 board are selected in the Arduino IDE.

