LCD runs in tinkercad but not on arduino

My board runs on tinker cad and code works, but when I replicate the tinkercad onto the arduino board, the LCD turns on, but nothing else seems to work, There is no text on LCD, LED's dont light and keypad doesn't seem to be working. No errors in code. All connections look good. For a moment i got some weird symbols on it but they were very dim. This happened when i connected the R/W on the LCD to ground. But now they have gone and cant even get them back.

#include <Keypad.h>

#include <LiquidCrystal.h>
#include <Servo.h>

Servo myservo;
int pos=0; // LCD Connections
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);
const byte rows=4;
const byte cols=4;

char key[rows][cols]={
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[rows]={8,7,6,5};
byte colPins[cols]={4,3,2,1};
Keypad keypad= Keypad(makeKeymap(key),rowPins,colPins,rows,cols);
char* password="4567";
int currentposition=0;
int RedpinLock = 10;
int GreenpinUnlock = 11;
int invalidcount=12;



void setup()
{

displayscreen();
Serial.begin(9600);
pinMode(RedpinLock, OUTPUT);
pinMode(GreenpinUnlock, OUTPUT);
myservo.attach(9); //SERVO ATTACHED//

lcd.begin(16,2);

}

void loop()
{
if( currentposition==0)
{
displayscreen();

}
int l ;
char enteredNum = keypad.getKey();
if(enteredNum!=NO_KEY)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("PASSWORD:");
lcd.setCursor(7,1);
lcd.print(" ");
lcd.setCursor(7,1);
for(l=0;l<=currentposition;++l)
{

lcd.print("*");
}

if (enteredNum==password[currentposition])
{
++currentposition;
if(currentposition==4)
{

unlockdoor();
currentposition=0;

}

}

else
{
incorrect();
currentposition=0;
  
 


}
// LOOP ENDS!!!//
}
}

//*******************************************OPEN THE DOOR FUNCTION!!!!***********************************************//

void unlockdoor()
{
delay(900);

lcd.setCursor(0,0);
lcd.println(" ");
lcd.setCursor(1,0);
lcd.print("Access Granted");
lcd.setCursor(4,1);
lcd.println("WELCOME!!");
lcd.setCursor(15,1);
lcd.println(" ");
lcd.setCursor(16,1);
lcd.println(" ");
lcd.setCursor(14,1);
lcd.println(" ");
lcd.setCursor(13,1);
lcd.println(" ");
digitalWrite(RedpinLock, LOW);
digitalWrite(GreenpinUnlock, HIGH);

for(pos = 180; pos>=0; pos-=5) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
}
delay(2000);



delay(1000);
counterbeep();

delay(1000);

for(pos = 0; pos <= 180; pos +=5) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15);


currentposition=0;

lcd.clear();
displayscreen();
}
}

//INCORRECT CODE ENTERED FUNCTION//

void incorrect()
{
delay(500);
lcd.clear();
lcd.setCursor(1,0);
lcd.print("CODE");
lcd.setCursor(6,0);
lcd.print("INCORRECT");
lcd.setCursor(15,1);
lcd.println(" ");
lcd.setCursor(4,1);
digitalWrite(RedpinLock, HIGH);
digitalWrite(GreenpinUnlock, LOW);

lcd.setCursor(13,1);
lcd.println(" ");
Serial.println("CODE INCORRECT");
delay(3000);
lcd.clear();
displayscreen();
}
//****************************** CLEAR THE SCREEN!!!**********************//
void clearscreen()
{
lcd.setCursor(0,0);
lcd.println(" ");
lcd.setCursor(0,1);
lcd.println(" ");
lcd.setCursor(0,2);
lcd.println(" ");
lcd.setCursor(0,3);
lcd.println(" ");
digitalWrite(RedpinLock, LOW);
digitalWrite(GreenpinUnlock, LOW);


}
//********************************DISPALAY FUNCTION!!!***********************************************************//
void displayscreen()
{

lcd.setCursor(0,0);
lcd.println("Enter the");
lcd.setCursor(1 ,1);

lcd.println("Password");
  
  digitalWrite(RedpinLock, HIGH);
digitalWrite(GreenpinUnlock, LOW);
}

//*************************** ARM SERVO****************************************************************************//
void armservo()
{

for (pos=180;pos<=180;pos+=50)
{
myservo.write(pos);
delay(5);
}
delay(5000);

for(pos=180;pos>=0;pos-=50)
{
myservo.write(pos);
}

}
//*******************************COUNTER BEEP*************************************//
void counterbeep()
{
delay(1200);


lcd.clear();

lcd.setCursor(2,15);
lcd.println(" ");
lcd.setCursor(2,14);
lcd.println(" ");
lcd.setCursor(2,0);
delay(200);
lcd.println("Door Locks in...");

lcd.setCursor(4,1);
lcd.print("5");
delay(200);
lcd.clear();
lcd.setCursor(2,0);
lcd.println("Door Locks in...");

delay(1000);
//2
lcd.setCursor(2,0);
lcd.println("Door Locks in...");
lcd.setCursor(4,1); //2
lcd.print("4");
delay(100);
lcd.clear();
lcd.setCursor(2,0);
lcd.println("Door Locks in...");
delay(1000);
//3
lcd.setCursor(2,0);
lcd.println("Door Locks in...");
lcd.setCursor(4,1); //3
lcd.print("3");
delay(100);
lcd.clear();
lcd.setCursor(2,0);
lcd.println("Door Locks in...");
delay(1000);
//4
lcd.setCursor(2,0);
lcd.println("Door Locks in...");
lcd.setCursor(4,1); //4
lcd.print("2");
delay(100);
lcd.clear();
lcd.setCursor(2,0);
lcd.println("Door Locks in...");
delay(1000);
//
lcd.setCursor(4,1);
lcd.print("1");
delay(100);
lcd.clear();
lcd.setCursor(2,0);
lcd.println("Door Locks in...");
delay(1000);
//5
lcd.clear();
lcd.setCursor(2,0);
lcd.print("RE-LOCKING");
delay(500);
lcd.setCursor(12,0);
lcd.print(".");
delay(500);
lcd.setCursor(13,0);
lcd.print(".");
delay(500);
lcd.setCursor(14,0);
lcd.print(".");
delay(400);
lcd.clear();
lcd.setCursor(4,0);
lcd.print("LOCKED!");
delay(440);
}
  1. Disconnect your servo and focus on the rest. It's too power hungry to attach to the Uno anyway, so you'll need an external 5VDC power supply or a 6V battery pack for that anyway.
    Once the LCD is working then we can discuss how to get your servo powered.

Servo Removed still no luck, could it be code? or if it works in tinkercad it is good?

Welcome to the forum.

It runs in Tinkercad :thinking: but does it run in Wokwi :partying_face:
Try the link below and start the simulation.

A I2C display is easier because it has only four wires. There is probably a wire not well connected. Can you check all your wires ? Breadboards have bad contacts and jumper wires can be broken and pins must be soldered correctly.
I think that most of us had trouble getting a LCD display to work the first time.

Changed the breadboard to a brand new one and wires, no change. Loosing my head with it :sweat_smile:

Can you show a photo ?

Hope you can help, if you need a better angle let me know, the green pins at top go to the keypad.

Hello ciaranmallo

Load and run the "Hello World" example to check the wiring of the LCD.

If you look at the breadboard it is likely that the power rails split in the middle , and there is no continuity between the two .
You need a port to adjust the display contrast .
As prev go to basics and get each part to work on its own .

What is that orange wire at the bottom doing ? Seems to connect + to -

I’d get rid of tinker cad and just build projects , getting each part to function on its own

1 Like

never mind.

You haven't used pinMode to set the LCD pins to be outputs.

Is this done by the library?

Looks to me like you have many errors in the wiring in you photo compared with the fritzing at #1.
example....pin 1 ...ground...ok
pin 2 supply...ok
pin 3 ...yellow to supply..??
pin 4 10K to ground....??
D0 to....???? why..??
many others also...........

You beat me to it.

Problem, bread board power rail split:


Solution, bread board power rail split:

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.