Yarana Iot Guru
Published © MIT

Printing Text on a 16×2 LCD with an App: A Step-by-Step

Send text from your phone to a 16×2 LCD using ESP32/Arduino + I²C (or direct pins) — create a live mobile display in minutes

BeginnerFull instructions provided8 hours89
Printing Text on a 16×2 LCD with an App: A Step-by-Step

Things used in this project

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

💻 Code — ESP32 + I²C LCD + Web API (recommended full example)

C/C++
This example: ESP32 runs Wi-Fi AP/station, hosts a small web page, accepts text via form or GET /set?text=..., and prints on I²C 16×2 LCD. Uses LiquidCrystal_I2C library.
// ESP32 + 16x2 I2C LCD + Web API (works with Blynk/MIT/App too)
#include <WiFi.h>
#include <WebServer.h>
#include <LiquidCrystal_I2C.h>

const char* ssid = "YourWiFi";
const char* password = "YourPassword";

// I2C address may vary (0x27 or 0x3F). Use I2C scanner if needed.
LiquidCrystal_I2C lcd(0x27, 16, 2);

WebServer server(80);

String htmlPage() {
  String s = "<!doctype html><html><head><meta name='viewport' content='width=device-width'>";
  s += "<title>LCD Text Sender</title></head><body style='font-family:Arial;'>";
  s += "<h3>Send text to 16x2 LCD</h3>";
  s += "<form action='/set' method='GET'>";
  s += "<input name='text' style='width:80%' placeholder='Type message (max 32 chars)'>";
  s += "<input type='submit' value='Send'>";
  s += "</form><p>Use /set?text=Hello via GET to send programmatically.</p>";
  s += "</body></html>";
  return s;
}

void handleRoot() {
  server.send(200, "text/html", htmlPage());
}

void handleSet() {
  if (server.hasArg("text")) {
    String txt = server.arg("text");
    txt.trim();
    // split into two lines max 16 chars each
    String line1 = txt.substring(0, min(16, (int)txt.length()));
    String line2 = "";
    if (txt.length() > 16) line2 = txt.substring(16, min(32, (int)txt.length()));
    // pad or clear
    lcd.clear();
    lcd.setCursor(0,0); lcd.print(line1);
    lcd.setCursor(0,1); lcd.print(line2);
    server.send(200, "text/plain", "OK");
  } else {
    server.send(400, "text/plain", "Missing text param");
  }
}

void setup() {
  Serial.begin(115200);
  lcd.init();
  lcd.backlight();
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("YaranaIoT Guru");
  lcd.setCursor(0,1);
  lcd.print("LCD Ready");

  WiFi.begin(ssid, password);
  Serial.print("Connecting WiFi");
  int tries=0;
  while (WiFi.status() != WL_CONNECTED && tries++ < 30) {
    delay(500);
    Serial.print(".");
  }
  if (WiFi.status() == WL_CONNECTED) {
    Serial.println("\nConnected! IP: " + WiFi.localIP().toString());
  } else {
    Serial.println("\nWiFi failed -> starting AP: ESP_LCD_AP");
    WiFi.softAP("ESP_LCD_AP");
    Serial.println("AP IP: " + WiFi.softAPIP().toString());
  }

  server.on("/", handleRoot);
  server.on("/set", handleSet);
  server.begin();
  Serial.println("HTTP server started");
}

void loop() {
  server.handleClient();
}

🧰 Direct 4-bit Wiring Code (if not using I²C)

C/C++
If you wired LCD in 4-bit mode use LiquidCrystal.h:
#include <LiquidCrystal.h>
LiquidCrystal lcd(15, 2, 4, 16, 17, 5); // RS, E, D4, D5, D6, D7
// rest of code similar to above: lcd.begin(16,2); lcd.print(...)

Credits

Yarana Iot Guru
48 projects • 25 followers
Yarana Iot GuruYarana IoT Guru: Arduino,ESP32, GSM, NodeMCU & more.Projects, Tutorials & App Development. Innovate with us!
Thanks to YaranaIoT Guru.

Comments