Home Alarm with a 3 wire 4x3 analog keypad nearly done but need some help please

liudr:

HazardsMind:

Yeah right, so what's the problem?

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 \0
  3. 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.