Your code might be fine... but without understand the hardware it might not work.
If your input (Pin 9) is not pulled low then even when 5v is not applied, it may appear HIGH.
Your code might be fine... but without understand the hardware it might not work.
If your input (Pin 9) is not pulled low then even when 5v is not applied, it may appear HIGH.