Here is a good example, read this all you need is inside..
http://www.41post.com/3745/programming/android-acessing-the-gyroscope-sensor-for-simple-applications
Also, its better to check if this sensor is available on your hardware, for example:
Boolean sensorAvailable = false;
List<Sensor> sensorList = sm.getSensorList(Sensor.TYPE_ALL);
for(int i=0;i<sensorList.size();i++){
if(sensorList.get(i)==Sensor.TYPE_GYROSCOPE){
sensorAvailable=true;
}
}
If sensor not available, give some Toast to show the user that this will not work with the device. For example in your onClick:
@Override
public void onClick(View arg0) {
if(sensorAvailable==true){
if(decide==1)
{
sm.registerListener(Gyro.this,gyroscope,SensorManager.SENSOR_DELAY_NORMAL);
click.setText("Stop");
decide=0;
}else if(decide==0){
sm.unregisterListener(Accelerometer.this);
click.setText("Start");
decide=1;
}else{
Toast.makeText(Gyro.this,"Gyroscope not available",Toast.LENGTH_LONG).show();
}
}