I am new to this arduino . I have some basic from arduino Uno and would like to transfer my project to arduino mega2560 because it more suitable for my project due to great number of digital port compare with arduino Uno. So my plan is just to change digital port number with from uno to mega 2560then use the same code which is work fine on uno upload in to mega 2560 . I already did that but somehow there is not thing happens when I supply board with 12VDC 1A power supply . but the LED on board indicated the board is on , so is that possible that anyone can please help me and point out what did I do wrong.
What this project objective
Password lock
First it allow user to set password. Then user input password by keypad. If the password is consistent with set password the relay will closed and led indicator light will be on. Otherwise the relay will open and the led light will be off
Connection
Original connection
LCD
RS -0
R/w – GND
E – 1
D4 – 2
D5 – 3
D6 – 4
D7 – 12
Vss – GND
VDD – 5V
A – 3.3v
K-GND
Keypad (4x4) but we use only 4x3
Row 1 - 11
2- 10
3 – 9
4- 8
Colum 1 – 7
2- 6
3- 5
Relay
S – 13
-
- = GND
Modified connection
LCD
RS -22
R/w – GND
E – 24
D4 – 26
D5 – 28
D6 – 30
D7 – 46
Vss – GND
VDD – 5V
A – 3.3v
K-GND
Keypad (4x4) but we use only 4x3
Row 1 - 44
2- 42
3 – 40
4- 38
Colum 1 – 36
2- 34
3- 32
Relay
S – 48
-
- = GND
Original code
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(0, 1, 2, 3, 4, 12);
#define relayPin 13
const byte ROWS = 4; //four rows
const byte COLS = 3; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {11, 10, 9, 8}; //connect to the row pinouts of the keypad
byte colPins[COLS] = { 7, 6, 5}; //connect to the column pinouts of the keypad
int pos = 0;
char secretCode[6] = {'1', '2', '3', '4', '5', '6'};
char inputCode[6] = {'0', '0', '0', '0', '0', '0'};
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup()
{
lcd.begin(16, 2);
pinMode(relayPin, OUTPUT);
//Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print(" Welcome! ");
delay(2000);
}
void loop()
{
readKey();
}
void readKey()
{
int correct = 0;
int i;
char customKey = customKeypad.getKey();
if (customKey)
{
switch(customKey)
{
case '*':
pos = 0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Input Your Code:");
break;
case '#':
for(i = 0; i < 6; i++)
{
if(inputCode[i] == secretCode[i])
{
correct ++;
}
}
if(correct == 6)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Input correctly!");
lcd.setCursor(0, 1);
lcd.print(" Please Come In ");
digitalWrite(relayPin, HIGH);
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Welcome! ");
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Input Error! ");
lcd.setCursor(0, 1);
lcd.print(" Please Again ");
digitalWrite(relayPin, LOW);
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Welcome! ");
}
break;
default:
inputCode[pos] = customKey;
lcd.setCursor(pos,1);
lcd.print(inputCode[pos]);
pos ++;
}
}
}
Modified code on mega (Change Digital pin number)
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(22, 24, 26, 28, 30, 46);
#define relayPin 48
const byte ROWS = 4; //four rows
const byte COLS = 3; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {44, 42, 40, 38}; //connect to the row pinouts of the keypad
byte colPins[COLS] = { 36, 34, 32}; //connect to the column pinouts of the keypad
int pos = 0;
char secretCode[6] = {'1', '2', '3', '4', '5', '6'};
char inputCode[6] = {'0', '0', '0', '0', '0', '0'};
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup()
{
lcd.begin(16, 2);
pinMode(relayPin, OUTPUT);
//Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print(" Welcome! ");
delay(2000);
}
void loop()
{
readKey();
}
void readKey()
{
int correct = 0;
int i;
char customKey = customKeypad.getKey();
if (customKey)
{
switch(customKey)
{
case '*':
pos = 0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Input Your Code:");
break;
case '#':
for(i = 0; i < 6; i++)
{
if(inputCode[i] == secretCode[i])
{
correct ++;
}
}
if(correct == 6)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Input correctly!");
lcd.setCursor(0, 1);
lcd.print(" Please Come In ");
digitalWrite(relayPin, HIGH);
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Welcome! ");
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Input Error! ");
lcd.setCursor(0, 1);
lcd.print(" Please Again ");
digitalWrite(relayPin, LOW);
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Welcome! ");
}
break;
default:
inputCode[pos] = customKey;
lcd.setCursor(pos,1);
lcd.print(inputCode[pos]);
pos ++;
}
}
}