How to connect 16*2 LCD with Arduino

HI

i am very new to Arduino programming.

i wired my circuit like below:

and i wrote my program like this

#include <LiquidCrystal.h>

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

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

but after uploading my code, i am getting like below:

please help me to fix this

thanks & Regards,
Ben

your arduino - LCD wiring and LiquidCrystal library initalization is not matching.

LiquidCrystal lcd(7,8,9,10,11,12) might work..

Hi

Thanks for your replay

i have changed as you mentioned and the result is same. No luck

make connection like this:

lcd 1st pin → GND
lcd 2nd pin → vcc
lcd 3rd pin → GND

after this if a dark squares appear on 1st row of lcd then proceed further

lcd 4th pin → digital pin 9
lcd 5th pin → GND
lcd 6th pin → digital pin 8

lcd 11th pin → digital pin 5
lcd 12th pin → digital pin 4
lcd 13th pin → digital pin 6
lcd 14th pin → digital pin 7

now run this code

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(9, 8, 5, 4, 6, 7);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

Thanks for your replay.

my LCD is working now.

i have did some changes on code

#include <LiquidCrystal.h>

LiquidCrystal lcd(9, 8, 5, 4, 6, 7);
String Lprint = "Test Message";
void setup()
{

  lcd.print(LcdPrint(Lprint));
}

void loop()
{
  
}

int LcdPrint(String x){
  lcd.begin(16,2);
  lcd.print(x);
}

but on my LCD , “Test Message12” is displaying. Dont know from where this “12” came

firstly, in place String use string.

but on my LCD , "Test Message12" is displaying. Dont know from where this "12" came

"12" might be a garbage data. to avoid these use lcd.clear() before printing any thing on lcd .

HI

i added lcd.clear()
on my code

#include <LiquidCrystal.h>

LiquidCrystal lcd(9, 8, 5, 4, 6, 7);
String Lprint = "Test Message";
void setup()
{
  
  lcd.print(LcdPrint(Lprint));
}

void loop()
{
  
}

int LcdPrint(String x){
  lcd.begin(16,2);
  lcd.clear();
  lcd.print(x);
}

but still that 12 is coming

You should only be using lcd.begin once, in setup since the LCD module only needs to be initialized once…

You don’t need lcd.clear immediately after lcd.begin since it is done as part of the initialization.

The strange display shown in your photograph is not due to improper wiring or code, it is usually caused by a bad connection between the display and the pc board on which it is mounted. Don’t be surprised if it reappears.

Try using some simple code instead of your LcdPrint function:

#include <LiquidCrystal.h>

//LiquidCrystal lcd(RS, E, D4, D5, D6, D7);
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);      // put your pin numbers here

void setup()
  {
  lcd.begin(16, 2);                          // put your LCD parameters here
  lcd.print("hello, world!");
  lcd.setCursor(0,1);
  lcd.print("it works!");
  }

void loop()
  {
  }

Don

I don't know why you are doing what your are with the String object and functionalizing the lcd.print but it is causing your problem.

lcd.print() will not accept a void function as an input. You have typed LcdPrint(String x) as an int. I don't know why but it is returning the value of 12. I hope someone can explain this.

If you change the function type to char and have it return a space (char 32) the mysterious 12 goes away. The cursor is positioned after the space.

As Don says, move lcd.begin(16,2) into set up

char LcdPrint(String x)
 {
  lcd.print(x);
  return 32;  
}

thanks for your help,

it worked for me.

actually am trying to create one project

for that reason only i used LCD

Any Ideas? ---> http://forum.arduino.cc/index.php?topic=255812.15

You have hijacked an old thread to point to another old thread that you also hijacked. Why don't you just start a new topic of your own?

Don