Hi liudr. Thank you for the revised code. This does work but when the alarm is tripped any keypad press turns the alarm off. I tried it this morning. I am reading all I can find about state machines too. Perhaps I should leave it today as I have had more injections into my spine and they hurt badly. I may have a look later if I feel better. I hope I am not taking up too much of your time on this.RegardsJeremy

There are times when electronics projects are like Women. Just when you think everything is fine the blow up in your face :-0

Hi liudr. Thank you for the revised code. This does work but when the alarm is tripped any keypad press turns the alarm off. I tried it this morning. I am reading all I can find about state machines too. Perhaps I should leave it today as I have had more injections into my spine and they hurt badly. I may have a look later if I feel better. I hope I am not taking up too much of your time on this.RegardsJeremy

Good! Yes, that feature can be turned on and off inside the alarm case. I don't kow what you exactly wanted.

Good! Yes, that feature can be turned on and off inside the alarm case. I don't kow what you exactly wanted.

Hi liudr. What I wanted is to attach a PIR sensor and have the value it senses for movement set the alarm buzzer off for say 30 seconds. The keypad needs the correct code to disarm the alarm buzzer and ignore the PIR sensing or turn off the PIR sensor using a transistor. If i use a PNP transistor setting a digital pin HIGH via a resistor to the base of the transistor would cut the power to the PIR sensor.

Well any number you put in for the 5th digit, will be changed to zero, thats not a problem?You enter 12345, the code after that part sees 123450. I can't test it myself, but thats what I see from this.

Again I can't test it, but if it works then it works.

No. Reread the code. More importantly, get the C from ground up by the author I recommended you.

I don't have a PIR sensor so I can't help with that. I recommend you read my code a few times, find out how it is able to sound alarm/LED for 30 seconds while monitoring keypad input. Then you can change it to do your PIR logic. I imagine if someone walks up to the PIR sensor, it sounds the alarm. then they type in the code to disarm it? It's all your call how to do this.

Well any number you put in for the 5th digit, will be changed to zero, thats not a problem?You enter 12345, the code after that part sees 123450. I can't test it myself, but thats what I see from this.

Again I can't test it, but if it works then it works.

No. Reread the code. More importantly, get the C from ground up by the author I recommended you.

HazardsMind,

Sorry I issued the RTFM on this. I should have pointed out what the code does:

1) It fills the buffer with up to 5 characters from the keypad (password).2) It then terminates the string in the buffer with \03) It then performs a string comparison with the password using strcmp(), which requires a zero terminated C-string, thus step 2.4) It then decides whether to sound the alarm or to clear the alarm.

My step 2 was not necessary if I set the C-string's 5th location to zero in setup like buffer[5]=0 or have char buffer[10]=" ". But if I move the code to a different project, that line is very likely to be left out (forget to move) and this wouldn't work (buffer[5] is just a random value). The initial value of the buffer is also wasting 6 bytes of arduino SRAM, which is only 2K long.

Ok, thank you for clarifying that. It just seemed wrong for some reason, and I have no way to test your code for myself. (At work) I understand everything you want to do, its just, it looked odd to add a zero to buffer[5] and then compare it. I thought that when you got the last key, that is was adding on an extra 0.

Hi and a big thank you to liudr. Here is the code I am now using. I have got over the keypad press turning the alarm off. I have added another state called disarmed and the system stops at that point until the tactile button is pressed. This is fine but the motion sensor is a different story. I have tried instead to use a digital pin to read the sensor as it gives a clear 1 if motion detected and a 0 if not. I have tried using it in different places in the sketch but it is causing problems with the key presses(it was doing the same with an analog input) Also I can use a tactile button to simulate the motion sensor because it keeps going high with me moving my hands around.It is getting there but not quite. I will keep trying to get the sensor working though.Jeremy

int led=11;// led to simulate alarmint PIR=A5;// motion sensor cannot get to work so not usedint tripped;// value to hold pirint pirPin=5;/*I was using this pin as pir gives a digital 1 or 0 cannot get it to work in the sketch it just seems to stall the keypad*/int buttonPin=2;//small tactile button to turn system onint buttonState;//state of the tactile buttonvoid setup(){ Serial.begin(9600); pinMode(alarm_pin,OUTPUT); digitalWrite(alarm_pin,LOW); // digitalWrite(A0,HIGH); // DO this only if you are using phi-3 shield. pinMode(alarm_pin,OUTPUT); digitalWrite(alarm_pin,LOW); pinMode(led,OUTPUT); pinMode(pirPin,INPUT); pinMode(buttonPin,INPUT);

}

void loop(){ byte temp; switch (system_state) { case get_password: if (millis()-alarm_starting>=10000)// if alarm is tripped this turns led off // I changed the time just for testing { digitalWrite(led,LOW); } // do get password stuff temp=panel_keypad.getKey(); // Use phi_keypads object to access the keypad if (temp!=NO_KEY) { Serial.write(temp); buffer[pointer++]=temp; if (pointer==5) { buffer[pointer]=0; pointer=0; if (!strcmp(buffer,password)) { Serial.println("Authenticated!"); system_state=dissarmed;//cleared; //dissarmed turns the system off cleared_starting=millis(); digitalWrite(led,LOW); // Open a door or something }

Hi HazardsMind. I did put the sensor in in various places in the get password case because i could only get a reading on it there. I found it caused problems with the keypad function.The problem seems to be in the case get password part of the sketch where the program sits for the majority of the time waiting for a key press.I wherever the sensor is in the sketch the keypad is slow to respond and I noticed that when the alarm was triggered the led on pin 11 was very dim. I have tried giving the motion sensor its own power supply with the grounds connected but this makes no difference. I tried the led on a different pin with the same result. I was trying to work out how to have the sketch sit waiting in a different part lets call it case check_sensor but I am not able to do this. My programming skills have been learned over the last few months with some library books and the internet. I used to drive a Bus and my hobby is electronics and now I am learning to program my arduino.The trouble with me is I always think "How hard can it be?"Learning to write code is like learning to speak Chinese with a Spanish phrase book. But I am picking it up slowly.Jeremy

There are times when electronics projects are like Women. Just when you think everything is fine the blow up in your face :-0