I am learning Arduino at the moment and started a project.
I have a keypad from aliexpress that when enters the right pincode or use rfid the relay sends 5v. and i read pir sensor.
So far i can get the keypad and pirsensor working and read there value's
Now the hard part.
The keypad sends 5v for 5 seconds and then 0V.
How would i approach the following:
Voltage on system / turn on
Keypad is active and pir sensor values are coming in. / alarm on
Enter pincode or use Rfid.
System goes to inactief.
do nothing with pir sensor values / alarm off
When i want to activate the alarm again, by entering pin or use rifd again how to know that state is alarm off or on and reactivate alarm again?
I'd use an led (or maybe more than one) but one would work:
led off= no power
led solid on= power on, system disarmed
led blinking= power on, system armed
... or something along those lines anyway. Perhaps a beeper (like my next door neighbour's annoying house alarm) that beeps once when they arm, and twice when they disarm.
Good that you used the word "state" though- this project is perfect for a state machine approach.
When you enter the right Pincode there is a relay in the keypad unit. I input 5v in COM and NO sends out to arduino.
Its not that i do not know when alarm is off or on. When 1st time i insert Pincode and 5v gets to arduino. How to store this in the arduino that alarm is off? so the next time i enter a Pincode the arduino see that alarm is already off so it will set it to On!
Wait a minute... are you saying that with the Arduino turned off, the keypad is used to enter a pin that then activates a relay to turn the Arduino on? If that's the case, how do you read the keypad? Maybe I misunderstood?
This needs a schematic to show the system wiring and components, and perhaps a flow chart or state diagram to explain the states and actions.
You haven't answered my question in #5. Maybe you think #6 is an answer?
Let me ask explicitly again: Does the successful reading of the keypad / rfid tag happen with no reference to the Arduino, so that the relay which seems to be part of the reader powers the Arduino? But then you say it's only on for 5 seconds, presumably to unlatch a lock, so how does that provide power to the Arduino? Or is the Arduino actually powered up all the time, and you want this 5s signal to tell it the keypad / tag was read?
OK eventually it's beginning to get clearer in my mind. Have a look at statechangedetect in File / Examples in the IDE, which will allow you to see the change on a pin. Your reader is very much like a button which is active high; does the reader output explicitly remain low if not high though? If not you may need a pull down resistor on the pin to make sure it's kept low until it's meant to be high.
Well there are numerous tools available for that stuff, but pen and paper's the easiest!