tutorialspinouttools
Sensors · ESP32-C3

MCP9808 on OLED: Precision Temperature

Free ESP32 & Arduino tutorial · wiring, code & parts · gokul.builds

Overview & Wiring

What it is: The MCP9808 is a high-accuracy digital temperature sensor (±0.25 °C typical, 0.0625 °C resolution) over I2C. It's the sensor to reach for when you need lab-grade temperature, not weather-station "close enough". How it works: Pure I2C, so it shares SDA/SCL with the OLED. The Adafruit library reads the calibrated temperature register directly in °C. Wiring (shared I2C bus with the OLED): MCP9808 SDA -> GPIO4 MCP9808 SCL -> GPIO5 MCP9808 VDD -> 3V3 MCP9808 GND -> GND OLED VCC=3V3, GND=GND, SDA=GPIO4, SCL=GPIO5 Libraries: "Adafruit MCP9808" (installs "Adafruit BusIO"), plus "Adafruit SSD1306" and "Adafruit GFX Library". On screen / Serial: temperature in °C with two decimals. Gotchas: Default address is 0x18. The three address pins (A0–A2) let you put up to eight on one bus (0x18–0x1F). If begin() fails, check the address jumpers.

Circuit Diagram

MCP9808 on OLED: Precision Temperature wiring diagram for ESP32-C3

Parts You Need

ESP32-C3 SuperMiniBuy →
0.96" SSD1306 OLEDBuy →

Source Code (Arduino / ESP32)

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_MCP9808.h>

Adafruit_SSD1306 display(128, 64, &Wire, -1);
Adafruit_MCP9808 mcp = Adafruit_MCP9808();

void setup() {
  Serial.begin(115200);
  Wire.begin(4, 5);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  if (!mcp.begin(0x18)) {
    Serial.println("MCP9808 not found");
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(0, 28); display.println("MCP9808 not found");
    display.display();
    while (1) delay(10);
  }
  mcp.setResolution(3);                      // 0.0625 °C, ~250 ms/read
}

void loop() {
  mcp.wake();
  float t = mcp.readTempC();
  mcp.shutdown_wake(1);                       // low-power between reads

  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.println("MCP9808");
  display.setTextSize(3);
  display.setCursor(0, 24);
  display.printf("%.2f", t);
  display.setTextSize(2);
  display.print(" C");
  display.display();

  Serial.printf("Temp: %.2f C\n", t);
  delay(500);
}
Browse all tutorials ESP32-C3 pinout Calculators