When we open the door we generate electricity from the motion of the door, but when we close it, we can't generate electricity from it because the direction of the power (Positive and negative) is inversed
So, it can burn our capacitor and the resistor.
We solved this problem by using diode.
The diode will unite the direction of the power when we open and close the door in any direction