This website uses cookies to ensure you get the best experience on our website.
A Story of OLED Displays and Temperature Sensors

Unveiling the Magic of Arduino: A Story of OLED Displays and Temperature Sensors

In a small town, nestled between rolling hills and crystal-clear streams, lived a young tinkerer named Alex. Alex had a passion for electronics and spent countless hours in his workshop, surrounded by circuits, sensors, and tiny displays. One sunny afternoon, Alex embarked on a new adventure – to create a device that could measure and display the average temperature using an OLED screen and a KY-013 analog temperature sensor. This is the story of how Alex turned a bunch of components into a fascinating project.

Setting the Stage

Alex began by gathering all the necessary components: an Arduino board, an OLED display, and a KY-013 temperature sensor. He carefully connected the OLED display to the Arduino, ensuring the wires were properly aligned. The OLED screen, a tiny 128x64 pixel display, would be the window through which the temperature readings would be revealed.

Wiring the Components

The OLED display was connected using the I2C interface, with the SDA (data line) and SCL (clock line) pins connected to the corresponding pins on the Arduino. The KY-013 temperature sensor, which uses a thermistor to measure temperature, was connected to the analog pin A0. Alex made sure the connections were secure and double-checked the wiring before moving on to the coding part.

Bringing the Code to Life

Alex fired up his computer and opened the Arduino IDE. He started writing the code, first including the necessary libraries for the OLED display:

#include <Wire.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128

#define SCREEN_HEIGHT 64

#define OLED_RESET -1


The code then defined the pin for the temperature sensor and the constants required for the temperature calculations:

int ThermistorPin = A0;

float R1 = 1000; // value of R1 on board

float logR2, R2, T;

float c1 = 0.001129148, c2 = 0.000234125, c3 = 0.0000000876741; // Steinhart-Hart coefficients for thermistor

Initializing the OLED Display

Alex initialized the OLED display in the setup function and ensured it was ready to display information:

void setup() {


  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {

    Serial.println(F("SSD1306 allocation failed"));








Reading the Temperature

In the loop function, Alex wrote the code to read the temperature from the sensor and calculate the average temperature. He took 100 readings to ensure accuracy and averaged them out:

void loop() {

  const int numReadings = 100;

  float temperatureSum = 0;

  for (int i = 0; i < numReadings; i++) {

    int Vo = analogRead(ThermistorPin);

    R2 = R1 * Vo / (1023.0 - Vo);

    logR2 = log(R2);

    T = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2)); // temperature in Kelvin

    T = T - 273.15; // convert Kelvin to Celsius

    temperatureSum += T;



  float averageTemperature = temperatureSum / numReadings;

Displaying the Temperature

Finally, Alex wrote the code to display the average temperature on the OLED screen:




  display.setCursor(0, 0);

  display.print("Temp: ");

  display.setCursor(0, 25);


  display.print(averageTemperature, 1); // Display temperature with one decimal place

  display.print((char)247); // degree symbol 





The Magic Unfolds

With a sense of accomplishment, Alex uploaded the code to the Arduino and watched as the OLED screen sprang to life. After a short pause, the display cleared, and the average temperature was displayed in crisp, clear text. Alex marveled at how the components and code came together to create a functional device.


Through this project, Alex learned valuable lessons about connecting an OLED display to an Arduino, using the necessary libraries, and calculating the average temperature from an analog KY-013 temperature sensor. The joy of seeing the temperature readings on the OLED screen was a testament to the power of perseverance and curiosity.

This story serves as an inspiration to all budding tinkerers and hobbyists. With a bit of patience and passion, you too can create amazing projects and bring your ideas to life.

Arduino uno with analog sensor connected and display on an OLED screen
Emoji Reactions
What do you think?
👍 0
😆 0
😍 0
😲 0
😡 0
😢 0

Leave a Reply

Your email address will not be published. Required fields are marked *

Math Captcha
3 + 3 =