I’m currently working with random generated numbers which will be sent to my number (using a gsm module) my problem is, whenever I enter the correct random number sent to me it will display invalid pin and it will direct to the first function which will generate a new random number. I hope someone can help me, many thanks
This will be my code
#include <Keypad.h> //http://www.arduino.cc/playground/upload … Keypad.zip
#include <SoftwareSerial.h>
#include<EEPROM.h>
SoftwareSerial Sim800l(10,11);
char password[4]=“1234”;
char pass[4],pass1[4];
char customKey=0;
const byte ROWS = 4; // Four rows
const byte COLS = 4; // columns
// Define the Keymap
char hexaKeys[ROWS][COLS] = {
{‘1’,‘2’,‘3’,‘A’},
{‘4’,‘5’,‘6’,‘B’},
{‘7’,‘8’,‘9’,‘C’},
{‘*’,‘0’,‘#’,‘D’}
};
byte rowPins[ROWS] = { 23,25,27,29 };// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = { 22,24,26,28, };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
// Create the Keypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
uint8_t id = 1;
int i=0;
int c;
int randNumber;
String str_tempPass=“”;
String str_randomPass=“”;
char* text;
char* number;
bool error; //to catch the response of sendSms
void setup(){
Serial.begin(9600);
}
void loop(){
customKey = customKeypad.getKey();
if (customKey)
{
password[i++]=customKey;
Serial.print(“*”);
}
if(i==4)
{
delay(200);
for(int j=0;j<4;j++)
pass[j]=EEPROM.read(j);
if(!(strncmp(password, pass,4)))
{
Serial.println(“Password Accepted”);
c=0;
delay(2000);
//sms sent
str_tempPass=“”;
generatePassword();
//str_tempPass=“Your PIN Code is:” + (str_tempPass);
//char sendto[21]=“+9**********, message[141]=”";
Sim800l.begin(9600);
if (Sim800l.available()){
Serial.println(" ");
Serial.write(Sim800l.read());
}
Serial.println(“Sending Text…”);
Sim800l.print(“AT+CMGF=1\r”); // Set the shield to SMS mode
delay(100);
Sim800l.print(“AT+CMGS="+9**********"\r”);
delay(200);
Sim800l.print(str_tempPass=“Your PIN Code is:” + (str_tempPass));
Sim800l.print(“\r”); //the content of the message
delay(500);
Sim800l.print((char)26);//the ASCII code of the ctrl+z is 26 (required according to the datasheet)
delay(100);
Sim800l.println();
Serial.println(“Text Sent.”);
delay(500);
pCode();
}
else
{
Serial.println(“Access Denied…”);
c++;
Serial.println(c);
i=0;
}
}
}
//GENERATE PIN
void generatePassword()
{
randomSeed(analogRead(0));
for (int i=0; i < 4; i++)
{
randNumber = random(0,9);
str_tempPass = str_tempPass + String(randNumber);
}
Serial.print(str_tempPass);
}
//PINCODE
void pCode()
{
int j=0;
Serial.println(“Enter Pin Code:”);
while(j<4)
{
char key=customKeypad.getKey();
if (key == ‘A’) {
j=0;
i=0;
for(id = 1 ;id <=5; id++)
{
if(EEPROM.read(id)==0)
{
return id;
}
}
if(id>5)
{
return 0;
}
}
else if(key)
{
pass1[j++]=key;
Serial.print(“*”);
}
key=0;
}
delay(500);
if (str_tempPass==str_randomPass)
{
Serial.println(“Pin Success!”);
Serial.println(“Vault Open!”);
}
else if (!(str_tempPass==str_randomPass)){
Serial.println(“Incorrect Pin!”);
}
}