Arduino freezes after some commands

I have a problem with Arduino. Arduino freezes after getting some commands and I need to hard reset board to make program work again. I tried 2 programs, one of them is much less complex than other and both of them have the same problem. What could be a reason for that?

The most likely cause is ‘loopus infinitus’…an infinite loop that keeps the CPU busy, but produces no output visible from the outside. Seeing the program, we might be able to help you. Reducing the program to the smallest possible sub-set of code that still produces the problem might even help you find it yourself (and would make it much easier for others reviewing the code to find the problem). If your code needs special hardware, can you repeat the problem without that hardware?

If you do post code, please also post the exact circumstances under which the problem occurs (as much as you are able to determine). i.e. “It always happens when I press button2 no matter what else is done before” or “It only happens if I press button2 after pressing button1” or “It always seems to happen after 10 minutes of run-time”. The more details you can provide, the easier it will be to narrow down where to look for the problem.