In your dialer enter:
*#0*#
This will allow you to directly diagnose your phone's hardware. In your case, select "Sensor" and move your phone while watching the Accelerometer raw data. If all 3 (x, y, and z) are reading your hardware is fine and this is a software issue(soft reset possibly a solution). If not you have a hardware problem and it's time to use that warranty or find a repair shop to swap out that component.