Bird
0
0
Arduinoprogramming~5 mins

Displaying sensor data on screen in Arduino

Choose your learning style9 modes available
Introduction

We show sensor data on a screen so we can see what the sensor is measuring in real time. This helps us understand and use the sensor information easily.

You want to see the temperature from a temperature sensor on a small screen.
You need to display distance measurements from an ultrasonic sensor on an LCD.
You want to show light levels from a photoresistor on an OLED display.
You are testing a sensor and want to watch its values change live.
You want to create a simple device that shows sensor readings without a computer.
Syntax
Arduino
void setup() {
  // Initialize screen and sensor
}

void loop() {
  int sensorValue = analogRead(sensorPin);  // Read sensor
  display.clearDisplay();                   // Clear screen
  display.print(sensorValue);               // Show value
  display.display();                        // Update screen
  delay(500);                              // Wait before next read
}

analogRead(sensorPin) reads the sensor value from the specified pin.

Use display.clearDisplay() to clear old data before showing new data.

Examples
Read sensor on pin A0 and print value to Serial Monitor.
Arduino
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
Clear LCD screen and print text plus sensor value.
Arduino
lcd.clear();
lcd.print("Temp: ");
lcd.print(sensorValue);
For OLED displays, clear, set cursor, print value, then update screen.
Arduino
display.clearDisplay();
display.setCursor(0,0);
display.print(sensorValue);
display.display();
Sample Program

This program reads an analog sensor on pin A0 and shows the value on a 16x2 LCD screen. It updates every second.

Arduino
#include <LiquidCrystal.h>

const int sensorPin = A0;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2);  // Set up LCD size
  lcd.print("Sensor Data:");
}

void loop() {
  int sensorValue = analogRead(sensorPin);
  lcd.setCursor(0, 1);          // Move to second line
  lcd.print("Value: ");
  lcd.print(sensorValue);        // Show sensor value
  lcd.print("    ");            // Pad to clear old digits
  delay(1000);                  // Wait 1 second
}
OutputSuccess
Important Notes

Make sure your sensor is connected to the correct analog pin.

LCD or OLED libraries must be included and initialized properly.

Use delays to control how often the screen updates to avoid flickering.

Summary

Displaying sensor data helps you see real-time measurements easily.

Use sensor reading functions and screen commands to show values.

Clear the screen before updating to keep the display clean.