arduino code not working???? I am newbie at arduino programming

hi,
i wrote a script for the arduino to respond to a 4 digit code -but it is not working. Any idea or advice on how to fix it would be appreciated. i am a newbie 9 yoa and really keen to understand about the programming language - the guys at jaycar store suggested i make contact on this forum for guidance. If this is not the right forum, please let me know and if you could redirect me please. I appreciate your response. thanks

the code looks like this:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

//constants for LEDs
int greenLED = 12;
int redLED = 11;

//set our code
char* ourCode = "1234";
int currentPosition = 0;

//define the keypad
const byte rows = 4;
const byte cols = 4;

char keys[rows][cols] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};

byte rowPins[rows] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[cols] = {8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);

LiquidCrystal_I2C lcd(0x3F,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup()
{
  lcd.init();                      // initialize the lcd
  //lcd.init();
  
  // Print a message to the LCD.
  lcd.backlight();
  displayCodeEntryScreen();
  
  //setup and turn off both LEDs
  pinMode(redLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
  digitalWrite(redLED, LOW);
  digitalWrite(greenLED, LOW);
  
}

void loop()
{
  int l;
  
  char key = keypad.getKey();
  
  if (int(key) != 0) {
    lcd.setCursor(14,3);
    lcd.print("    ");
    lcd.setCursor(14,3);
    
    for (l=0; l<=currentPosition; ++l)
    {
      lcd.print("*");
    }

    if (key == ourCode[currentPosition])
      {
        ++currentPosition;
        if (currentPosition == 4)
        {
          unlockDoor();
          currentPosition = 0;
        }
      } else {
        invalidCode();
        currentPosition = 0;
      }

    
  }
}

void invalidCode()
{
  digitalWrite(redLED, HIGH);
  clearScreen();
  lcd.setCursor(0,0);
  lcd.print("*ACCESS DENIED!*");
  lcd.setCursor(0,1);
  lcd.print("**INVALID CODE**");
  
  delay(5000);
  digitalWrite(redLED, LOW);
  displayCodeEntryScreen();
}

void unlockDoor()
{
  digitalWrite(greenLED, HIGH);
  clearScreen();
  lcd.setCursor(0,0);
  lcd.print("*ACCESS GRANTED*");
  lcd.setCursor(0,1);
  lcd.print("**  WELCOME!  **");

  //add any code to unlock the door here
  delay(5000);
  digitalWrite(greenLED, LOW);
  displayCodeEntryScreen();
}

void displayCodeEntryScreen()
{
  clearScreen();
  lcd.setCursor(0,0);
  lcd.print("PLEASE ENTER");
  lcd.setCursor(1,0);
  lcd.print("CODE:"  "");
}

void clearScreen()
{
  lcd.setCursor(0,0);
  lcd.print("                    ");
  lcd.setCursor(0,1);
  lcd.print("                    ");
}

it is not working

Can you describe what it is doing ?

Put some Serial.prints into your program so that you know which parts of it are being executed and what the values of essential variables are at various points.

Read up on the LCD library. Could you perhaps use the lcd.clear() method instead of your function to do the same thing, for instance ?

When you post asking for help, you should put significant effort into describing your problem in detail so your readers understand what is going on without having to pour through every line of your code.

You posted 126 lines of code. Saying “it is not working” is not helpful. Does it compile? Does it get input from the keypad at all? Is it able to display to the LCD? What is it supposed to be doing, in detail, and how is it failing to do what you want it to do, again in detail? Which particular section of the code you posted is failing to perform as desired? What different approaches have you tried?

MASS2:
hi,
i wrote a script for the arduino to respond to a 4 digit code -but it is not working. Any idea or advice on how to fix it would be appreciated. i am a newbie 9 yoa and really keen to understand about the programming language - the guys at jaycar store suggested i make contact on this forum for guidance. If this is not the right forum, please let me know and if you could redirect me please. I appreciate your response. thanks

the code looks like this:

#include <Wire.h>

#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

//constants for LEDs
int greenLED = 12;
int redLED = 11;

//set our code
char* ourCode = “1234”;
int currentPosition = 0;

//define the keypad
const byte rows = 4;
const byte cols = 4;

char keys[rows][cols] = {
 {‘1’,‘2’,‘3’},
 {‘4’,‘5’,‘6’},
 {‘7’,‘8’,‘9’},
 {’*’,‘0’,’#’}
};

byte rowPins[rows] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[cols] = {8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);

LiquidCrystal_I2C lcd(0x3F,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup()
{
 lcd.init();                      // initialize the lcd
 //lcd.init();
 
 // Print a message to the LCD.
 lcd.backlight();
 displayCodeEntryScreen();
 
 //setup and turn off both LEDs
 pinMode(redLED, OUTPUT);
 pinMode(greenLED, OUTPUT);
 digitalWrite(redLED, LOW);
 digitalWrite(greenLED, LOW);
 
}

void loop()
{
 int l;
 
 char key = keypad.getKey();
 
 if (int(key) != 0) {
   lcd.setCursor(14,3);
   lcd.print("    “);
   lcd.setCursor(14,3);
   
   for (l=0; l<=currentPosition; ++l)
   {
     lcd.print(”*");
   }

if (key == ourCode[currentPosition])
     {
       ++currentPosition;
       if (currentPosition == 4)
       {
         unlockDoor();
         currentPosition = 0;
       }
     } else {
       invalidCode();
       currentPosition = 0;
     }

}
}

void invalidCode()
{
 digitalWrite(redLED, HIGH);
 clearScreen();
 lcd.setCursor(0,0);
 lcd.print(“ACCESS DENIED!”);
 lcd.setCursor(0,1);
 lcd.print(“INVALID CODE”);
 
 delay(5000);
 digitalWrite(redLED, LOW);
 displayCodeEntryScreen();
}

void unlockDoor()
{
 digitalWrite(greenLED, HIGH);
 clearScreen();
 lcd.setCursor(0,0);
 lcd.print(“ACCESS GRANTED”);
 lcd.setCursor(0,1);
 lcd.print("**  WELCOME!  **");

//add any code to unlock the door here
 delay(5000);
 digitalWrite(greenLED, LOW);
 displayCodeEntryScreen();
}

void displayCodeEntryScreen()
{
 clearScreen();
 lcd.setCursor(0,0);
 lcd.print(“PLEASE ENTER”);
 lcd.setCursor(1,0);
 lcd.print(“CODE:”  “”);
}

void clearScreen()
{
 lcd.setCursor(0,0);
 lcd.print("                    “);
 lcd.setCursor(0,1);
 lcd.print(”                    ");
}

If you change

lcd.print("*");

to

lcd.print(key);

Do you get the correct code?

I just realised that it's the arduino.
I accidentally twisted a LED connected to 5V and GND therefore getting 10V in the arduino probably burning the ATmega128

Opps