Restructure Arduino code and add door sensor