Here is a nice circuit diagram, made by JCS (from Coffee, Bits and Bikes), who is helping me with it.
The value of R2, which is indicated as 470 Ohm, is not yet final, as I still have to do some tests. The problem is the CTR of the optocoupler, which can be quite high, and so I will have to define the resistor such as to cause the transition in the proper place.
Next posts will be the code! so stay tuned!