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);
}