Try using this code, I have edited some parts of your code so this should work.
#include <LiquidCrystal.h>
const int rs = 30, en = 31, d4 = 32, d5 = 33, d6 = 46, d7 = 47;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup()
{
pinMode(36, OUTPUT);
digitalWrite(36, LOW);
delay(5000); //Its okay to use delay here since its in the setup() function and will run only once
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
// 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);
}
For this Hello World sketch, avoid using delay();
statement in the void loop()
as it is not good to use when you have the millis();
used.
If the above wont work, check your LCD Wiring, many problems usually arouse from wrong wirings.
Also I may suggest you to use some cheap LCD I2C Backpacks as this will ease the coding and will use less wire and pins on your Arduino. Here is a example
If your'e going to use a I2C LCD Backpack, here is a working sample code.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define BACKLIGHT_PIN 13
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
// Creat a set of new characters
const uint8_t charBitmap[][8] = {
{ 0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 },
{ 0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 },
{ 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 },
{ 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 },
{ 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 },
{ 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 },
{ 0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 },
{ 0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 }
};
void setup()
{
int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));
// Switch on the backlight
pinMode ( BACKLIGHT_PIN, OUTPUT );
digitalWrite ( BACKLIGHT_PIN, HIGH );
//lcd.begin(16,2);
lcd.begin(20,4); // initialize the lcd
for ( int i = 0; i < charBitmapSize; i++ )
{
lcd.createChar ( i, (uint8_t *)charBitmap[i] );
}
lcd.home (); // go home
lcd.print("LCD TESTER - BY:");
lcd.setCursor ( 0, 1 ); // go to the next line
lcd.print ("ABBAS (PRJCT.ME)");
delay ( 3000 );
}
void loop()
{
lcd.home ();
// Do a little animation by writing to the same location
//for ( int i = 0; i < 2; i++ )
for ( int i = 0; i < 4; i++ )
{
//for ( int j = 0; j < 16; j++ )
for ( int j = 0; j < 20; j++ )
{
lcd.print (char(random(7)));
}
lcd.setCursor ( 0, 1 );
for ( int j = 0; j < 20; j++ )
{
lcd.print (char(random(7)));
}
lcd.setCursor ( 0, 2 );
for ( int j = 0; j < 20; j++ )
{
lcd.print (char(random(7)));
}
lcd.setCursor ( 0, 3 );
}
delay (200);
}