Whats wrong with my device?

I failed to read batteries in your original post.

Unfortunantly I'm a software guy, so I can not offer any advice or solution. I can however verify that the code is not the source of the problem. But then again; you already knew that.

/me fail