Instead of delay 5000 you setup a variable and set it to millis() + 5000
Addition with unsigned longs is not guaranteed to work. Subtraction is. Now - then > interval as test will always work. Then + 5000 > interval may not. Might as well learn to do it properly from the beginning.