My advice would be to just start with the program which turns the LED on.

Then enhance it to turn the LED off again.

Then enhance it to turn the LED on when some condition is detected.