Can someone please help me with my code?

I’m making a keypad unlock door lock. Im new to Arduino and so I don’t know most of the codes.
Can someone please correct my code?

#include <Servo.h>
#include <Keypad.h>
Servo ServoMotor;
char* “999”;
int position = 0;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{‘1’,‘2’,‘3’,‘A’},
{‘4’,‘5’,‘6’,‘B’},
{‘7’,‘8’,‘9’,‘C’},
{’’,‘0’,’#’,‘D’}
};
{
byte rowPins[ROWS] = { 8, 7, 6, 9 };
byte colPins[COLS] = { 5, 4, 3, 2 };
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int RedpinLock = 12;
int GreenpinUnlock = 13;
void setup()
};
{
ServoMotor.attach(11);
LockedPosition(true);
}
void loop()
{
char key = keypad.getKey();
if (key == '
’ || key == ‘#’)
{
position = 0;
LockedPosition(true);
}
if (key == password[position])
{
position ++;
}
if (position == 3)
{
LockedPosition(false);
}
delay(100);
}
void LockedPosition(int locked)
{
if (locked)
{
digitalWrite(RedpinLock, HIGH);
digitalWrite(GreenpinUnlock, LOW);
ServoMotor.write(11);
}
else
{
digitalWrite(RedpinLock, LOW);
digitalWrite(GreenpinUnlock, HIGH);
ServoMotor.write(90);
}
}

}

First off we need the sketch posted properly.


In the Arduino IDE, use CTRL T to format your code then copy the complete sketch.

Use the </> button from the ‘reply menu’ to attach the copied sketch.

#include <Servo.h>
#include <Keypad.h>
Servo ServoMotor;
char* "999";
int position = 0;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
{
  byte rowPins[ROWS] = { 8, 7, 6, 9 };
  byte colPins[COLS] = { 5, 4, 3, 2 };
  Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  int RedpinLock = 12;
  int GreenpinUnlock = 13;
  void setup()
};
{
  ServoMotor.attach(11);
  LockedPosition(true);
}
void loop()
{
  char key = keypad.getKey();
  if (key == '*' || key == '#')
  {
    position = 0;
    LockedPosition(true);
  }
  if (key == password[position])
  {
    position ++;
  }
  if (position == 3)
  {
    LockedPosition(false);
  }
  delay(100);
}
void LockedPosition(int locked)
{
  if (locked)
  {
    digitalWrite(RedpinLock, HIGH);
    digitalWrite(GreenpinUnlock, LOW);
    ServoMotor.write(11);
  }
  else
  {
    digitalWrite(RedpinLock, LOW);
    digitalWrite(GreenpinUnlock, HIGH);
    ServoMotor.write(90);
  }
}

}

Welcome to the forum.

You will be better of if we teach you how to fish and not when we catch the fish for you.

I would recommend you have a look at a few examples in the IDE first and use Google to search for terms you do not understand.

File → Examples → …

If something is unclear, post some specific questions and you will get lots of answers.

Have a look at the brackets in your code. Every opening bracket needs a closing bracket of the same type. Formatting your code already shows you something is wrong.

How are your components wired together ?
A simple schematic (not a Frizzy diagram) please.

A (clear, well lit) photo of your project may help too.

Do you want to give us a few more hints? What Arduino? Does your code compile? And upload? When you run it what EXACTLY does it do?

Steve

char * "999";
is not a valid statement. If you are creating a variable, you have to give it a name.

{
  byte rowPins[ROWS] = { 8, 7, 6, 9 };
  byte colPins[COLS] = { 5, 4, 3, 2 };
  Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  int RedpinLock = 12;
  int GreenpinUnlock = 13;
  void setup()
};

There is an extra set of curly braces around this block of statements. Get rid of them, and the ‘;’ at the end.

The variable ‘password’ is not declared. I’m guessing you meant ‘char * “999”;’ to be ‘const char * password = “999”;’ or you could use ‘char password = “999”;’ if you ever want to change those three characters in your sketch.

There is an extra ‘}’ after the LockedPosition() function.