Im a newbie. I have a problem with displaying text in LCD (16x2). It shows incorrect message in the lcd. Here is the code and the picture that gives the wrong output : Kindly help Thank you.

#include "SIM900.h"
#include <SoftwareSerial.h>

#include "sms.h"
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


int numdata;
boolean started  = false;
char smsbuffer[160]; //message
String newsms;
char n[20];
unsigned char i;
int sensorPin = A0;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor
int outputValue = 0;   // value output to the %
int outputValue1 = 0;   // value output to cursor

void setup()
  //Serial connection.
    lcd.begin(16, 2);


//  lcd.setCursor(0, 1);
//  lcd.clear();
//  lcd.print("   Wireless Public       via GSM"); //55 chars
//  lcd.setCursor(0, 2);
//  lcd.print("    Notice Board "); //55 chars
   Serial.println("GSM Shield testing.");
  if (gsm.begin(2400)) {
    started = true;
  else Serial.println("\nstatus=IDLE");

  // set up the LCD's number of columns and rows:


void loop()

  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 100);
  outputValue1 = map(sensorValue, 0, 1023, 0, 200);

  //scroll = lcd.scrollDisplayLeft();
  if (started) {
    //Read if there are messages on SIM card and print them.
    if (gsm.readSMS(smsbuffer, 160, n, 20))
      lcd.setCursor(0, 2);
      lcd.print("SMS Received!");
//      lcd.clear();

enter image description here

  • What characters does Serial.println(smsbuffer); print to the serial monitor? – VE7JRO May 12 '18 at 19:27
  • Yes In Serial Monitor it display the correct message that being send by the sender but when i print it in lcd it did not display the same output as what serial monitor display It only display the image that i upload. – Megumichan May 12 '18 at 19:29
  • Please edit your question to show the wireup of the LCD to your Arduino. Are you sure you didn't exchange one of the data line wires? (arduino.cc/en/Tutorial/HelloWorld) Is every message displayed wrong or just the contents of smsbuffer? Have you tried running a minimal sketch to just test the LCD with a 'hello world'? – Maximilian Gerhardt May 12 '18 at 19:38
  • I did print the smsbuffer in serial so that i can see the content of the message that being receive. Well in Serial it gives the correct output/content that the sender message. but when i print it in lcd it shows incorrect content. – Megumichan May 12 '18 at 19:46
  • @Megumichan, when i print it in lcd it shows incorrect content .... you are misunderstanding the problem ... the LCD is displaying exactly the correct content .... it is displaying what you are telling it to display ..... you have to figure out why your program is sending content that you do not want to see .... start by running the "helloWorld" demo – jsotola May 13 '18 at 2:20

The first thing to try is replacing lcd.begin(16, 2) with lcd.begin(20, 4). The image of your LCD looks like a 20 char by 4 line display. Based on your comments, it seems that the SMS part of your code is working because it's outputting the correct characters to the serial monitor. I would focus on the LCD code and connections to your Arduino.

  • Yeah in serial it shows the correct content of the message but in lcd it shows degree symbol(extended ascii code) Is it possible to convert this ascii code to string? or how can i remove this degree ascii code and change it to text? Thank you – Megumichan May 12 '18 at 21:30
  • What would you like to replace the degree symbol with? – VE7JRO May 13 '18 at 2:19
  • can i possibly replace the degree symbol to string ?? – Megumichan May 13 '18 at 3:46
  • I'm not sure what you mean, "to string". An empty string? A space character? – VE7JRO May 13 '18 at 4:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.