---
title: LightSensor
description: A library that provides access to the device's light sensor.
sourceCodeUrl: https://github.com/expo/expo/tree/sdk-53/packages/expo-sensors
packageName: expo-sensors
iconUrl: /static/images/packages/expo-sensors.png
platforms: ["android"]
---
`LightSensor` from `expo-sensors` provides access to the device's light sensor to respond to illuminance changes.
## Installation
## Usage
```jsx
const [{ illuminance }, setData] = useState({ illuminance: 0 });
const [subscription, setSubscription] = useState(null);
const toggle = () => {
if (subscription) {
unsubscribe();
} else {
subscribe();
}
};
const subscribe = () => {
setSubscription(
LightSensor.addListener(sensorData => {
setData(sensorData);
})
);
};
const unsubscribe = () => {
subscription && subscription.remove();
setSubscription(null);
};
useEffect(() => {
subscribe();
return () => unsubscribe();
}, []);
return (
<View style={styles.sensor}>
<Text>Light Sensor:</Text>
<Text>
Illuminance: {Platform.OS === 'android' ? `${illuminance} lx` : `Only available on Android`}
</Text>
<View style={styles.buttonContainer}>
<TouchableOpacity onPress={toggle} style={styles.button}>
<Text>Toggle</Text>
</TouchableOpacity>
</View>
</View>
);
}
const styles = StyleSheet.create({
sensor: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
paddingHorizontal: 10,
},
buttonContainer: {
flexDirection: 'row',
alignItems: 'stretch',
marginTop: 15,
},
button: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#eee',
padding: 10,
},
});
```
## API
```js
```