the arduino code notdoesnot have error but not working

  arduino, arduino-ide, c++

I am having issues with my program.
The modules are keypad,Buzzer,vibration sensor,LCD i2c .

At first LCD should show locker.
What i need is if vibration sensor picks an input the buzzer should act non stop.The LCD should show warning. And if a password of ‘888’ is pressed the LCD should come back to normal and Buzzer should stop.
But my code doesnt have any error.But it is not working with my modules.i done many changes but the programe is not working as i expected it to.

full code i wrote :

#include <Keypad.h>
#include <SPI.h>
// Create instances
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
char initial_password[4] = {'8', '8', '8'};  // Variable to store initial password
char password[4];   // Variable to store users password
char key_pressed = 0; // Variable to store incoming keys
uint8_t i = 0;  // Variable used for counter
// defining how many rows and columns our keypad have
const byte rows = 4;
const byte columns = 4;
// Keypad pin map
char hexaKeys[rows][columns] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};


// Initializing pins for keypad
byte row_pins[rows] = {9, 8, 7, 6};
byte column_pins[columns] = {5, 4, 3};
// Create instance for keypad
Keypad keypad_key = Keypad( makeKeymap(hexaKeys), row_pins, column_pins, rows, columns);

boolean alarmIsActive = false;




constexpr uint8_t vib_pin = 2;
constexpr uint8_t buzz = 12;

void setup() {

  pinMode(vib_pin, INPUT);
  pinMode(buzz, OUTPUT);

  lcd.init();   // LCD screen
  lcd.backlight();
  SPI.begin();      // Init SPI bus
  lcd.clear(); // Clear LCD screen

}

void loop()
{

  if (alarmIsActive == true)
  {
    int val;
    val = digitalRead(vib_pin);
    if (val == 1)
    {
      digitalWrite(buzz, HIGH);
      alarmIsActive == false;
    }
  }
  if (! alarmIsActive)
  {

    key_pressed = keypad_key.getKey(); // Storing keys
    if (key_pressed)
    {
      password[i++] = key_pressed; // Storing in password variable
      lcd.print("*");
    }
    if (i == 3) // If 3 keys are completed
    {
      delay(200);
      if (!(strncmp(password, initial_password, 3))) // If password is matched
      {
        lcd.clear();
        lcd.print("Pass Accepted");
        digitalWrite(buzz, LOW);
        lcd.clear();
        i = 0;
        alarmIsActive = false;

      }
      else    // If password is not matched
      {
        lcd.clear();
        lcd.print("WARNING");


        lcd.clear();
        i = 0;
        alarmIsActive = false;
      }
    }
  }
}

Source: Windows Questions C++

LEAVE A COMMENT