Try the free app "Check My Android". It is designed to test the hardware. I used it to test my Nexus 7, which would no longer rotate. Now, whenever it is stuck in the horizontal position and I need to rotate I open this app and it immediately puts it into the vertical position, where it stays. When it is stuck in the vertical position and I want to force it to the horizontal, I open an app that wants to be used in the horizontal position. In my case, it is the free app Perfect Piano which forces the device to horizontal and it stays that way until I need to rotate it again. Crazy workaround, but all else has failed for me.