Hello I am attempting to program an alarm system using an arduino R3 project kit. The system is password activated by having one password to 'arm' and a second to 'disarm'. Arming activates an ultrasonic sensor, and if something is detected in a certain distance it activates a buzzer and lights an LED. I believe I have most of the code correct aside from the passwords, I think the final function is what is tripping me up,. My code:
#include <Password.h>
#include <Keypad.h>
#define trigPin 13
#define echoPin 12
#define ledPin 6
Password armed = Password( "1234" );
Password disarmed = Password( "5678" );
const int buzzer = 11;
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2};
byte colPins[COLS] = {9, 8, 7,};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
keypad.addEventListener(keypadEvent);
pinMode(buzzer, OUTPUT);
pinMode(ledPin, OUTPUT);
}
void loop(){
char key = keypad.getKey();
digitalWrite(trigPin, LOW);
digitalWrite(ledPin, LOW);
}
void enterPassword(){
long duration, distance;
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (armed.evaluate()){
digitalWrite(trigPin, HIGH);
if (distance < 5){
digitalWrite(ledPin, HIGH);
tone(buzzer, 1000);}
}
else if(disarmed.evaluate()){
digitalWrite(trigPin, LOW);
noTone(buzzer);
digitalWrite(ledPin, LOW);}
}
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
Serial.print("Pressed: ");
Serial.println(eKey);
switch (eKey){
case '*': enterPassword();
break;
case '#': armed.reset();
disarmed.reset();
break;
default: armed.append(eKey);
disarmed.append(eKey);}
}
}
The code compiles but I get the following errors and the keypad doesn't execute the command like I had initially intended:
ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
Password armed = Password( "1234" );
ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
Password disarmed = Password( "5678" );
I've been baffled for quite awhile so any and all help would be greatly appreciated!! Thank you in advance. ![]()