coding

the code doesnt have any error but then it isnt working on the product

#include <Keypad.h>
#include<EEPROM.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
SoftwareSerial Sim900A(9, 10);
LiquidCrystal lcd(14, 15, 16, 17, 18, 19);

char password[5]="1234";
char pass[5],pass1[5];
char tempPass[5];
char customKey=0;
char key_pressed;



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 = "";

#define solenoidlock1 1
#define solenoidlock2 2
#define solenoidlock3 3
#define pickbutton 4
#define dropbutton 5
int buttonState = 0;
int buttonState1 = 0;



void setup()
{
  lcd.begin(16, 2);
  pinMode(solenoidlock1, OUTPUT); //sets solenoid as Output
  pinMode(solenoidlock2, OUTPUT); //sets solenoid as Output
  pinMode(solenoidlock3, OUTPUT); //sets solenoid as Output
  pinMode(pickbutton, INPUT); //sets button as Input
  pinMode(dropbutton, INPUT); //sets button as Input
  Sim900A.begin(9600);   // Setting the baud rate of GSM Module  
}

void loop()
{
 buttonState = digitalRead(dropbutton);
 if (buttonState == HIGH) {
  lcd.clear();
  char key = customKeypad.getKey();
  drop();
 }
 buttonState1 = digitalRead(pickbutton);
 if(buttonState1 == HIGH) {
  lcd.clear();
  char key = customKeypad.getKey();
  pick();
  
}
  }

void drop()
{ 
  char key = customKeypad.getKey();
  //use keypad to type the locker
  lcd.write("choose 1,2,3");
  lcd.setCursor(0, 1);
  if (key == '1')
  {
    digitalWrite(solenoidlock1, HIGH);
    delay(1000);
    digitalWrite(solenoidlock1,LOW);
    delay(5000);
    lcd.write("Door Opened");
    delay(5000);
    lcd.clear();
  }
  {
  digitalWrite(solenoidlock1, LOW);
  delay(1000);
  digitalWrite(solenoidlock1, HIGH);
  lcd.write("Door Closed");
  sendMessagelocker1;
}
  if (key == '2')
  {
    digitalWrite(solenoidlock2, HIGH);
    delay(1000);
    digitalWrite(solenoidlock2,LOW);
    delay(5000);
    lcd.write("Door Opened");
    delay(5000);
    lcd.clear();
  }
  {
  digitalWrite(solenoidlock2, LOW);
  delay(1000);
  digitalWrite(solenoidlock2, HIGH);
  lcd.write("Door Closed");
  sendMessagelocker2;
}
  if (key == '3')
  {
    digitalWrite(solenoidlock3, HIGH);
    delay(1000);
    digitalWrite(solenoidlock3,LOW);
    delay(5000);
    lcd.write("Door Opened");
    delay(5000);
    lcd.clear();
  }
  {
  digitalWrite(solenoidlock3, LOW);
  delay(1000);
  digitalWrite(solenoidlock3, HIGH);
  lcd.write("Door Closed");
  sendMessagelocker1;
}
}

void pick()
{
char key =customKeypad.getKey();
  if (key == '1')
  {
  lcd.print("Enter Pin Code:");
    char key = customKeypad.getKey();
    if (str_tempPass==str_randomPass)
{
lcd.print("Pin Success!");
lcd.print("locker 1 opening");
        digitalWrite(solenoidlock1, LOW);
        delay(5000);
        digitalWrite(solenoidlock1, HIGH);
        lcd.clear();
}
else if (!(str_tempPass==str_randomPass)){
Serial.println("Incorrect Pin!");
}
}
  if (key == '2')
  {
  lcd.print("Enter Pin Code:");
    char key = customKeypad.getKey();
    if (str_tempPass==str_randomPass)
{
lcd.print("Pin Success!");
lcd.print("locker 1 opening");
        digitalWrite(solenoidlock2, LOW);
        delay(5000);
        digitalWrite(solenoidlock2, HIGH);
        lcd.clear();
}
else if (!(str_tempPass==str_randomPass)){
Serial.println("Incorrect Pin!");
}
}
  
 if (key == '3')
  {
  lcd.print("Enter Pin Code:");
    char key = customKeypad.getKey();
    if (str_tempPass==str_randomPass)
{
lcd.print("Pin Success!");
lcd.print("locker 1 opening");
        digitalWrite(solenoidlock3, LOW);
        delay(5000);
        digitalWrite(solenoidlock3, HIGH);
        lcd.clear();
}
else if (!(str_tempPass==str_randomPass)){
Serial.println("Incorrect Pin!");
}
}
}
     




void sendMessagelocker1()
{
  generatePassword();
  Sim900A.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  Sim900A.println("AT+CMGS=\"+6497116543\"\r"); // Replace x with mobile number
  delay(1000);
  Sim900A.println("delivery arrived");// The SMS text you want to send
  Sim900A.println("package in locker1");// The SMS text you want to send
  Sim900A.println("please key in code");// The SMS text you want to send
  Sim900A.println(str_tempPass);
  delay(100);
  Sim900A.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
}

void sendMessagelocker2()
{
  generatePassword();
  Sim900A.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  Sim900A.println("AT+CMGS=\"+6497116543\"\r"); // Replace x with mobile number
  delay(1000);
  Sim900A.println("delivery arrived");// The SMS text you want to send
  Sim900A.println("package in locker2");// The SMS text you want to send
  Sim900A.println("please key in code");// The SMS text you want to send
  Sim900A.println(str_tempPass);
  delay(100);
  Sim900A.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
}

void sendMessagelocker3()
{
  generatePassword();
  Sim900A.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  Sim900A.println("AT+CMGS=\"+6497116543\"\r"); // Replace x with mobile number
  delay(1000);
  Sim900A.println("delivery arrived");// The SMS text you want to send
  Sim900A.println("package in locker3");// The SMS text you want to send
  Sim900A.println("please key in code");// The SMS text you want to send
  Sim900A.println(str_tempPass);
  delay(100);
  Sim900A.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
}

//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);
}
}

What Project? What error are you getting? Please make the post clear.

Hi,

  • Did you write all this code?
  • What is it supposed to do?
  • What does it do?
  • What model Arduino controller are you using?
  • On what product?

Thanks.. Tom.. :slight_smile:

Hi,
What I understood with the code you posted, that its a password protected door look system which send sms when door is opened.

However what I thought Its not sending the sms to the desired number.

share the sketch of diagram of your circuit,so can tell you better where the problem is.

Thanks

It's a pity you decided to use half of your most useful debug resource to drive a solenoid.

It has a BUNCH of warnings. Do you think it might be a problem that you get a key code from the keypad and never use it? Maybe a problem that you use the name of a function but left off the "()" so you don't actually call it in line 100, 117, 134...? You included the EEPROM library but never used it.

Fix those mistakes and MAYBE the sketch will start working.

/Users/john/Documents/Arduino/sketch_jul29a/sketch_jul29a.ino: In function 'void loop()':
/Users/john/Documents/Arduino/sketch_jul29a/sketch_jul29a.ino:66:10: warning: unused variable 'key' [-Wunused-variable]
     char key = customKeypad.getKey();
          ^~~
/Users/john/Documents/Arduino/sketch_jul29a/sketch_jul29a.ino:73:10: warning: unused variable 'key' [-Wunused-variable]
     char key = customKeypad.getKey();
          ^~~
/Users/john/Documents/Arduino/sketch_jul29a/sketch_jul29a.ino: In function 'void drop()':
/Users/john/Documents/Arduino/sketch_jul29a/sketch_jul29a.ino:100:23: warning: statement is a reference, not call, to function 'sendMessagelocker1' [-Waddress]
     sendMessagelocker1;
                       ^
/Users/john/Documents/Arduino/sketch_jul29a/sketch_jul29a.ino:100:23: warning: statement has no effect [-Wunused-value]
/Users/john/Documents/Arduino/sketch_jul29a/sketch_jul29a.ino:117:23: warning: statement is a reference, not call, to function 'sendMessagelocker2' [-Waddress]
     sendMessagelocker2;
                       ^
/Users/john/Documents/Arduino/sketch_jul29a/sketch_jul29a.ino:117:23: warning: statement has no effect [-Wunused-value]
/Users/john/Documents/Arduino/sketch_jul29a/sketch_jul29a.ino:134:23: warning: statement is a reference, not call, to function 'sendMessagelocker1' [-Waddress]
     sendMessagelocker1;
                       ^
/Users/john/Documents/Arduino/sketch_jul29a/sketch_jul29a.ino:134:23: warning: statement has no effect [-Wunused-value]
/Users/john/Documents/Arduino/sketch_jul29a/sketch_jul29a.ino: In function 'void pick()':
/Users/john/Documents/Arduino/sketch_jul29a/sketch_jul29a.ino:144:10: warning: unused variable 'key' [-Wunused-variable]
     char key = customKeypad.getKey();
          ^~~
/Users/john/Documents/Arduino/sketch_jul29a/sketch_jul29a.ino:162:10: warning: unused variable 'key' [-Wunused-variable]
     char key = customKeypad.getKey();
          ^~~
/Users/john/Documents/Arduino/sketch_jul29a/sketch_jul29a.ino:181:10: warning: unused variable 'key' [-Wunused-variable]
     char key = customKeypad.getKey();
          ^~~
In file included from /Users/john/Documents/Arduino/sketch_jul29a/sketch_jul29a.ino:2:0:
/Users/john/Library/Arduino15/packages/arduino/hardware/avr/1.8.3/libraries/EEPROM/src/EEPROM.h: At global scope:
/Users/john/Library/Arduino15/packages/arduino/hardware/avr/1.8.3/libraries/EEPROM/src/EEPROM.h:145:20: warning: 'EEPROM' defined but not used [-Wunused-variable]
 static EEPROMClass EEPROM;
                    ^~~~~~
Sketch uses 7536 bytes (23%) of program storage space. Maximum is 32256 bytes.
Global variables use 606 bytes (29%) of dynamic memory, leaving 1442 bytes for local variables. Maximum is 2048 bytes.