To make sure that this is not software related, set the iPhone back to factory settings, using iTunes on your computer.
Set it up manually after that, without using the latest backup and test motion sensor again.
This article explains the steps to take:
Restore your iPhone, iPad or iPod touch to factory settings
If the feature works again, use the latest backup to get your data and settings back. If the issue comes back, your backup data contained the error and you'll have to start again, without using the backup data.
If the problem still exists after setting it back to factory settings, without the backup data, the issue is hardware related.
In that case the phone has to be serviced by Apple: