#include <Wire.h>
// NTC sensor analog pin
int sensorPin = A0;
// Create the display object, no need for external libraries
SSD1306 display(128, 64, &Wire); // 128x64 OLED display
void setup() {
// Initialize the OLED display (this part is built into Wokwi)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Use default I2C address (0x3C)
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
// Set up serial communication
Serial.begin(9600);
}
void loop() {
// Read the analog value from the NTC sensor
int sensorValue = analogRead(sensorPin);
// Convert the sensor value to a temperature in Celsius
float voltage = sensorValue * (5.0 / 1023.0); // Convert the analog reading to voltage
float temperature = (1 / (log(1 / (5.0 / voltage - 1)) / 3900 + 1 / 298.15)) - 273.15;
// Clear the OLED and display the temperature
display.clearDisplay();
display.setCursor(0, 0);
display.print("Temperature: ");
display.print(temperature);
display.print(" C");
display.display(); // Update the display
// Delay before taking another reading
delay(1000);
}
Loading
ssd1306
ssd1306