Home Code Raspberry Pi and LTR-559 Light and Proximity Sensor python example

Raspberry Pi and LTR-559 Light and Proximity Sensor python example

by shedboy71

In this article we look at a Light and Proximity Sensor – this time its the LTR-559 and we will connect it to our Raspberry Pi and show how to get readings from it in python

This is the sensor that I will be using

Lets look at some information regarding the sensor

This light and proximity sensor detects light over a wide dynamic range (0.01 lux to 64,000 lux) and proximity within a short range of ~5cm.

The LTR-559 is the same sort of sensor that you’d find next to the camera in your phone to detect when it’s next to your ear and when your phone should disable the touchscreen.

It’s ideal for an automatic and manual nightlight switch that detects when ambient light drops below a certain level and automatically tiggers something like Unicorn pHAT to come on, or just wave your hand over it to toggle the light on or off manually using proximity sensing.

The LTR-559 Light and Proximity Sensor Breakout has an I2C interface and is 3.3V or 5V compatible.


  • Lite-On LTR-559ALS-01 sensor
  • I2C interface (address: 0x23)
  • IR/UV-filtering
  • 50.60Hz flicker rejection
  • 0.01 lux to 64,000 lux light detection range
  • ~5cm proximity detection range
  • 3.3V or 5V compatible
  • Reverse polarity protection
  • Raspberry Pi-compatible pinout (pins 1, 3, 5, 7, 9)
  • Compatible with all models of Raspberry Pi


Parts Required


Name Link
Raspberry Pi Raspberry Pi 4 Model B Development Board
LTR-559 Pimoroni LTR-559 Light & Proximity Sensor Breakout
Connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire



Code Example

This uses a library from Pimoroni where I bought the sensor from which you can install like this from the terminal

sudo pip3 install ltr559

I then opened the Mu editor and entered the following code example, which is the same as the default example

[codesyntax lang=”python”]

#!/usr/bin/env python

import time
from ltr559 import LTR559

ltr559 = LTR559()

    while True:
        lux = ltr559.get_lux()
        prox = ltr559.get_proximity()

        print("Lux: {:06.2f}, Proximity: {:04d}".format(lux, prox))

except KeyboardInterrupt:



Run this example and you should see the following




You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More