user45745: 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);

//gsm
SMSGSM sms;

int numdata;
boolean started  = false;
char smsbuffer[160]; //message
String newsms;
char n[20];
unsigned char i;
//lcd
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.
  //gsm
    lcd.begin(16, 2);

  Serial.begin(9600);

//  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)) {
    Serial.println("\nstatus=READY");
    started = true;
  }
  else Serial.println("\nstatus=IDLE");

  //lcd
  // 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
      lcd.clear();
      lcd.setCursor(0, 2);
      lcd.print("SMS Received!");
      delay(2000);
      lcd.clear();
      lcd.setCursor(0,1);
      Serial.println(n);
      Serial.println(smsbuffer);
      lcd.print(smsbuffer);
      delay(1000);
//      lcd.clear();
    }
    delay(1000);
  }
}



user37523: 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.

user-1: I arrived a little late; however I'm leaving some further information to Debug similar problems for those who arrive here in the Future.
Regarding the Question
As already answered above:
 - You are specifying your LCD as a 16 Column with 2 Rows (1602); and in your picture you clearly have a 20 Column with 4 Rows.
Change:
lcd.begin(16, 2);

To:
lcd.begin(20, 4);

How LCD Works
Take into consideration that LCD works as a Matrix and both Columns and Rows are Zero Based Index.
That is; when you set the LCD Cursor Columns or Rows; you start counting with 0.
See Example Bellow:
lcd.setCursor(0, 2);

The 1st Parameter (Zero) Represents Columns.
The 2nd (Two) Represents Rows.
Therefore on the 1st Parameter: "0" (Column); (Considering you're reading from Left to Right and Top to Bottom); You Set the Cursor on the very 1 Column on the LCD.
The 2nd Parameter (2): you’l be Setting char on the 3rd Row (Line).
Note: 3rd and not 2nd; because both Columns and Rows are "Zero Based" Indexed.
Debugging LCD Issues

Check If your LCD is Properly Wired. You may have switched a wire; wire not properly plugged or broken.
Specially if you’re not using a I2C back module). Wiring without I2C (“I Squared C”) module can be confusing in certain occasions.

Check your Library and Hardware.
Make sure you’re using the correct library (I2C library: if your LCD has the module: use a compatible I2C Library; and specify the LCD parameters accordingly).
In case you don’t have a I2C module; then use a library to with a workaround for that situation. (You specify all the Pins).

Check you Code:
Check the way you initialize your LCD.
i.e: lcd.begin(16,2); or lcd.begin(20, 4);

Make sure you print inside LCD Index.
Setting the cursor outside its bounds can also cause “weird” chars.

There can be other situations related with improper wiring or some sort of short circuit with other components connected to your project that can also produce weird characters.

In certain circumstances; pressing Reset; Cutting the Power for a little while or Re-Uploading the project fixes the issue.

Not clearing the LCD whenever there is New data can simulate the effect of weird characters; but actually they are old data characters that remained there.


Writing Custom Characters to LCD
As you've Probably Noticed you are Unable to print the a Custom Character (i.e: Degree Symbol) on your LCD.
That can be solved by Creating your own (Custom) char and Declare it on your Code.
I won't explain every detail, in order to avoid going off topic and to avoid providing an extensive and hard-to-read answer.
Instead will leave an example, that is easy to understand and 2 Links bellow with further information regarding Custom Characters.
Links:

More Information and Examples for Custom Characters.
LCD Character Generator

Example for Degree Character
/* LCD Custom Characters
*******************************************/
// This is your Char Definition in Bytes:
byte DegreeDef[8] = { B01100, B10010, B10010, B01100, B00000, B00000, B00000, B00000 };

// This is the byte Char to be used to write to LCD.
const byte Degree = 0x2;


void LCDInitialization()
{  
  // LCD Initialiation Code Here
  // ...

  // Initialize Custom Characters.
  lcd.createChar(2, DegreeDef);

  // Do Something Else...
}

void PrintToLCD()
{
  // Note:
  // "lcd.write" is Different from "lcd.print".
  // Use "write" to Print your Custom LCD Characters.
  lcd.setCursor(0, 1);
  lcd.write(Degree);
}

I hope this helps debugging your issue.

user78327: Hello I had the same problem and noticed that if you setup the lcd screen in this order:
LiquidCrystal lcd (d7, d6, d5, d4, , en, rs) ;

you get some weird character showing up...
but if you do this way:
LiquidCrystal lcd (rs, en, d4, d5, d6, d7) ;

you don't get any weird character.

45745: <p>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.</p>

<pre><code>#include "SIM900.h"
#include &lt;SoftwareSerial.h&gt;

#include "sms.h"
#include &lt;LiquidCrystal.h&gt;

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

//gsm
SMSGSM sms;

int numdata;
boolean started  = false;
char smsbuffer[160]; //message
String newsms;
char n[20];
unsigned char i;
//lcd
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.
  //gsm
    lcd.begin(16, 2);

  Serial.begin(9600);

//  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)) {
    Serial.println("\nstatus=READY");
    started = true;
  }
  else Serial.println("\nstatus=IDLE");

  //lcd
  // 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
      lcd.clear();
      lcd.setCursor(0, 2);
      lcd.print("SMS Received!");
      delay(2000);
      lcd.clear();
      lcd.setCursor(0,1);
      Serial.println(n);
      Serial.println(smsbuffer);
      lcd.print(smsbuffer);
      delay(1000);
//      lcd.clear();
    }
    delay(1000);
  }
}
</code></pre>

<p><a href="https://i.stack.imgur.com/8Cto9.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8Cto9.jpg" alt="enter image description here"></a></p>
 37523: <p>The first thing to try is replacing <code>lcd.begin(16, 2)</code> with <code>lcd.begin(20, 4)</code>. 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.</p>
 -1: <p>I arrived a little late; however I'm leaving some further information to Debug similar problems for those who arrive here in the Future.</p>
<p><br><strong>Regarding the Question</strong></p>
<p>As already answered above:
<br> - You are specifying your LCD as a 16 Column with 2 Rows (1602); and in your picture you clearly have a 20 Column with 4 Rows.</p>
<p><strong>Change:</strong></p>
<pre><code>lcd.begin(16, 2);
</code></pre>
<p><strong>To:</strong></p>
<pre><code>lcd.begin(20, 4);
</code></pre>
<p><br><strong>How LCD Works</strong></p>
<p>Take into consideration that LCD works as a Matrix and both Columns and Rows are Zero Based Index.
That is; when you set the LCD Cursor Columns or Rows; you start counting with 0.</p>
<p>See Example Bellow:</p>
<pre><code>lcd.setCursor(0, 2);
</code></pre>
<p>The 1st Parameter (Zero) Represents Columns.
<br>The 2nd (Two) Represents Rows.</p>
<p>Therefore on the 1st Parameter: &quot;0&quot; (Column); (Considering you're reading from Left to Right and Top to Bottom); You Set the Cursor on the very 1 Column on the LCD.</p>
<p>The 2nd Parameter (2): you’l be Setting char on the 3rd Row (Line).</p>
<p><strong>Note:</strong> 3rd and not 2nd; because both Columns and Rows are &quot;Zero Based&quot; Indexed.</p>
<p><br><strong>Debugging LCD Issues</strong></p>
<ol>
<li><p>Check If your LCD is Properly Wired. You may have switched a wire; wire not properly plugged or broken.
Specially if you’re not using a I2C back module). Wiring without I2C (“I Squared C”) module can be confusing in certain occasions.</p>
</li>
<li><p>Check your Library and Hardware.
Make sure you’re using the correct library (I2C library: if your LCD has the module: use a compatible I2C Library; and specify the LCD parameters accordingly).
In case you don’t have a I2C module; then use a library to with a workaround for that situation. (You specify all the Pins).</p>
</li>
<li><p>Check you Code:
Check the way you initialize your LCD.
i.e: lcd.begin(16,2); or lcd.begin(20, 4);</p>
</li>
<li><p>Make sure you print inside LCD Index.
Setting the cursor outside its bounds can also cause “weird” chars.</p>
</li>
<li><p>There can be other situations related with improper wiring or some sort of short circuit with other components connected to your project that can also produce weird characters.</p>
</li>
<li><p>In certain circumstances; pressing Reset; Cutting the Power for a little while or Re-Uploading the project fixes the issue.</p>
</li>
<li><p>Not clearing the LCD whenever there is New data can simulate the effect of weird characters; but actually they are old data characters that remained there.</p>
</li>
</ol>
<p><br><strong>Writing Custom Characters to LCD</strong></p>
<p>As you've Probably Noticed you are Unable to print the a Custom Character (i.e: Degree Symbol) on your LCD.
That can be solved by Creating your own (Custom) char and Declare it on your Code.
I won't explain every detail, in order to avoid going off topic and to avoid providing an extensive and hard-to-read answer.
Instead will leave an example, that is easy to understand and 2 Links bellow with further information regarding Custom Characters.</p>
<p><br><strong>Links:</strong></p>
<ul>
<li><a href="https://www.engineersgarage.com/arduino/making-custom-characters-on-lcd-using-arduino/" rel="nofollow noreferrer">More Information and Examples for Custom Characters</a>.</li>
<li><a href="https://maxpromer.github.io/LCD-Character-Creator/" rel="nofollow noreferrer">LCD Character Generator</a></li>
</ul>
<p><br><strong>Example for Degree Character</strong></p>
<pre><code>/* LCD Custom Characters
*******************************************/
// This is your Char Definition in Bytes:
byte DegreeDef[8] = { B01100, B10010, B10010, B01100, B00000, B00000, B00000, B00000 };

// This is the byte Char to be used to write to LCD.
const byte Degree = 0x2;


void LCDInitialization()
{  
  // LCD Initialiation Code Here
  // ...

  // Initialize Custom Characters.
  lcd.createChar(2, DegreeDef);

  // Do Something Else...
}

void PrintToLCD()
{
  // Note:
  // &quot;lcd.write&quot; is Different from &quot;lcd.print&quot;.
  // Use &quot;write&quot; to Print your Custom LCD Characters.
  lcd.setCursor(0, 1);
  lcd.write(Degree);
}
</code></pre>
<p>I hope this helps debugging your issue.</p>
 78327: <p>Hello I had the same problem and noticed that if you setup the lcd screen in this order:</p>
<pre><code>LiquidCrystal lcd (d7, d6, d5, d4, , en, rs) ;
</code></pre>
<p>you get some weird character showing up...
but if you do this way:</p>
<pre><code>LiquidCrystal lcd (rs, en, d4, d5, d6, d7) ;
</code></pre>
<p>you don't get any weird character.</p>
