I've done a lot with the code so it may be completely ruined from all the tries, but here's where I am now:
"And note that I have to have a loop whenever the smoke is detected, as I am trying to build a smoke sensor so I will only be able to disable it when the code is put in, even though the smoke is gone."
#include <Keypad.h>
int piezo = 4;
int led = 3;
int sensor = A0;
int sensorValue = 0;
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'},
};
byte rowPins[ROWS] = {12,11,10,9};
byte colPins[COLS] = {8,7,6,5};
Keypad keypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
const String password = "1234";
String input_password;
void setup()
{
Serial.begin(9600);
digitalWrite(led, 0);
}
void loop()
{
char key = keypad.getKey();
sensorValue = analogRead(sensor);
Serial.println(sensorValue, DEC);
while (sensorValue > 100)
{
char key = keypad.getKey();
Serial.println(key);
digitalWrite(piezo, 1);
tone(4, 2500);
delay(1000);
noTone(4);
delay(250);
if (key != NO_KEY){
Serial.println(key); //uncomment line to test input
switch (key) {
case '5':
digitalWrite(piezo, 0);
break;
}
}
}
}