Raspberry Pi Light Sensor: A Simple LDR Tutorial @Pimylifeup
Raspberry Pi Light Sensor: A Simple LDR Tutorial  @Pimylifeup
Uploaded January 2016 | Updated September 2026, 2 weeks ago
In this video I go through the process of setting up a Raspberry Pi light sensor and go through the code required to get the correct data from it.

Full Tutorial: pimylifeup.com/raspberry-pi-light-sensor

If you need a full equipment list of all the parts in this tutorial, then simply head over to the website linked directly above. It will have a list and a link to where you can buy similar parts to what I am using.

The sensor we’re using to detect light is called a photocell resistor or also known as a light dependent resistor. This small little device is super sensitive to light and changes its resistance accordingly. The darker it is the higher the resistance.

Unfortunately, the Raspberry Pi doesn’t have any analogue pins so we aren’t easily able to get the value from the light sensor. Instead we charge up a capacitor and count the time it takes for it to send our input pin high. Since the light sensor is a resistor the darker it is the higher the resistance meaning our capacitor will take longer to charge.

The code for this tutorial is super simple and there isn’t a huge amount you will need to know about it. Basically we have a counting function that returns a number representing how light or dark it is. The higher the number the less light there is on the photoresistor.

There are a lot of things you can incorporate the light sensor into. My personal favourite ideas include a light activated alarm and a garden shade sensor.

I hope you haven’t had any trouble with setting up this Raspberry Pi light sensor. If you have had any trouble, noticed I have missed something important or there is anything else you would like to say then please drop a comment below or over at pimylifeup.com.
Raspberry Pi Light Sensor: A Simple LDR TutorialTop Projects for the Raspberry Pi - April 2025The PiDog Robotic Dog Kit for the Raspberry PiBuild your very own Raspberry Pi Mumble ServerHow to setup a Raspberry Pi RFID RC522 ChipRunning x64 Software on your Raspberry Pi using Box64Installing the Rockstar Games Launcher on the Steam DeckSetting up a Cloudflare Tunnel on the Raspberry PiMonitoring your Raspberry Pi using Monit5 Awesome Raspberry Pi CasesSetting up a SQL Server on the Raspberrry Pi using MariaDBManage your Raspberry Pi using Cockpit
Pi My Life Up |

Raspberry Pi Light Sensor: A Simple LDR Tutorial

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER