The logic part is also a bit more evolved than before with two interdependent finite-state automatons running at the same time.
General rules:
- Lx: Light automaton state,
- Rx: Remote automaton state,
- TL: Light automaton timer,
- TR: Remote automaton timer,
- The automaton is assessed every 100ms (10Hz frequency) so a timer of 10 means 1 second,
- The timer of the corresponding automaton is reset each time its state evolve,
- Every inputs are retrieved once before assessing the two automatons (the logical inputs like the door and key sensors as well as the remote button pressed, if any),
- Every outputs are set after both automatons have been assessed,
- At any time, only one state of each automaton is active (the active state of one automaton can be used as condition for the other automaton, and one automaton car define the active state of the other automaton).
Inputs:
- DOOR: both front doors are closed,
- /DOOR: one (or both) of the front door is opened,
- KEY: the ignition key is OFF,
- /KEY: the ignition key is ON,
- REMOTEL: the remote button Lock has been pressed,
- REMOTEU: the remote button Unlock has been pressed,
- REMOTET: the remote button Trunk release has been pressed.
Outputs:
- LIGHT: interior lights are ON,
- LED: the blue LED is ON,
- TURNS: both sides of turn signals are ON,
- LOCK: the lock signal of the car central locking is active,
- UNLOCK: the unlock signal of the car central locking is active,
- TRUNK: the trunk release signal is active,
- When not specified, the output is OFF/inactive.
Regarding the remote button state retrieval, I use the
RCSwitch library for Arduino which allows to easily capture and process the 433MHz remote signals. The remotes I have uses an
EV1527 IC encoder that sends 24bits long frames: 20bits are used only for address coding (1048576 unique combinations), and 4bits are used for data (in this case: button Lock is 1, button Unlock is 2 and button Trunk release is 4).
I have developed a way to save the address 20bits of a new remote in the EEPROM of the Arduino, by pressing one of the three buttons during the first 15 seconds after the Arduino boot. I limited the number of remotes to three (but it's a variable in the code: the 1KB EEPROM of the Arduino could save up to 340 codes). When 3 remotes are already saved, if a new one is learned it overwrite the oldest one.
Each 100ms, before assessing both automatons, a code check if a new remote code has been received. If it's the case it checks the length (24bits) and the protocol (EV1527 IC encoder is protocol 1). If it matches, It compares the 20bits address with the three remotes saved. And finally if it also matches It retrieves the data part to generate the REMOTEL/REMOTEU/REMOTET input signals.
Compared to the previous version, the Arduino must remain active at all time: no more sleep (Power Down) state. Otherwise it would be impossible to monitor efficiently for the remotes frames. Which means the system has an higher consumption while "idling", but the deactivation of all unused microcontroller modules on the chip allow the consumption to stay under 15mA (Arduino + RF module active). Every Keyless Kit in the shops have similar consumption (if not higher...).
The two state automatons work roughly as follow:
- When you close the doors with the ignition OFF: the interior light goes ON for 30 seconds and then goes OFF if the light was previously ON, or stays OFF otherwise.
- When you open one door with the ignition OFF: the interior light goes ON for a maximum of 10 minutes and then goes OFF (timeout to save the battery).
- When you close the doors with the ignition ON: the interior light goes OFF.
- When you open one door with the ignition ON: the interior light goes ON.
- When you turn the ignition ON with both doors closed: the interior light goes OFF.
- When you turn the ignition ON with at least one door open: the interior light goes ON.
- When you turn the ignition OFF with both doors closed: the interior light goes ON for 15 seconds and then goes OFF.
- When you turn the ignition OFF with at least one door open: the interior light goes ON for a maximum of 10 minutes and then goes OFF (timeout to save the battery).
- When you unlock the car (with the remote): the interior light goes ON for 30 seconds and then goes OFF.
- When you lock the car (with the remote): the interior light goes OFF.
- When the car is locked: the LED flashes every 10 seconds (ON for 1% of the time), and the interior light is always OFF.
- The Lock function consists in: activate Lock signals while short blinking twice the turn signals and the LED.
- The Unlock function consists in: activate Unlock signals while long blinking once the turn signals and the LED.
- The Trunk release function consists in: activate Trunk signals while short blinking once the turn signals and the LED.
- The Lock function is only available when the car is unlocked (LED doesn't flash), both doors are closed and the ignition is OFF.
- The Unlock function is only available when the car is locked (LED flashes).
- The Trunk release function is only available when the ignition is OFF (prevent opening the trunk while driving).
- To activate the Trunk release function: press the Trunk release button on the remote once and then press it a second time after 400ms and within a 1 second timeout, or keep the button pressed for more than 400ms. It prevents inadvertently opening the trunk.
- When the car is locked (LED flashes) if one door is opened or if the ignition is turned ON, the Unlock function is executed.
The Arduino code is available here.
Finally the pictures, it doesn't look much (tape covering the circuit, lot of hot glue and Rilsan to keep everything in place...) but it works great since last weekend:
Now, if you're interested, you can make your own.