Green LED will not turn on

Hello,

I am currently working on a school project and I have decided to create a locking mechanism using an 1602 LCD with a I2C module, a basic matrix keypad, and 2 different colored LED's (green and red).

I am having an issue where when i enter the correct pin/password and my greenLED will not turn on. My redLED turns on when I input the wrong answer. I have attached my code and if you guys need a picture of the hardware then I'll post it.

I have attached my code which I am using and should not be too hard to understand.

*Forgot to mention that I am using the Arduino Mega 2560

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

#define Password_Length 8
#define greenLED 11
#define redLED 10
//
//RedLED = 10;
//GreenLED = 11;

char Data[Password_Length];
char Master[Password_Length] = "1234567";

int lockOutput = 13;

byte dataCount = 0;

char key;

const byte ROWS = 4; // use 4X4 keypad for both instances
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] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
Keypad kpd( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup(){
// Wire.begin( );
kpd.begin( makeKeymap(keys) );
Serial.begin(9600);

lcd.backlight();
lcd.init();

pinMode(lockOutput, OUTPUT);
pinMode(redLED, OUTPUT); //RED LED
pinMode(greenLED, OUTPUT); //GREEN LED
}

//byte alternate = false;

void loop(){
// alternate = !alternate;
lcd.setCursor(0,0);
lcd.print("Enter Pin: ");

key = kpd.getKey();

if(key){
Data[dataCount] = key;
lcd.setCursor(dataCount, 1);
lcd.print(Data[dataCount]);
dataCount++;
}

if(dataCount == Password_Length-1 ){
lcd.clear();

if(!strcmp(Data, Master)){
lcd.print("Correct!");
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
lcd.clear();
lcd.print("Locking in 5 Sec!");
delay(5000);
lcd.print("Locked!");
}else {
lcd.print("INCORRECT!");
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delay(1000);
digitalWrite(10, LOW);
}
lcd.clear();
clearData();
}
}

void clearData(){
while(dataCount != 0) {
Data[dataCount--] = 0;
}
return;
}

Code tags please!

And read the forum guide in case you accidentally break any other rules :wink:

OK, first things first.

You need to go and read the forum instructions so that you can go back and modify your original post (not re-post it) - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window. Just highlight each section of code (or output if you later need to post that) from the IDE and click the icon.

In fact, the IDE itself has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read. While you were lucky so far, If you do not post it as "code" it can easily be quite garbled and is always more difficult to read due to the font.

It is inappropriate to attach it as a ".ino" file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And even that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only single blanks between complete functional blocks.

Why do we think this is more important than just having your question answered? Because it is really difficult to write code properly - as with any other task requiring care - if everything is disorganised!

mcoraza12:
and if you guys need a picture of the hardware then I'll post it.

A hand-drawn schematic would be nice, too.

Before we worry about the code, would you please try switching the LEDs on your breadboard so that red should light up on correct, and green on incorrect. Just as a test.