Photosensitive resistor

From Let's Control It
Jump to: navigation, search

Introduction

Instead of using a Lux/light sensor you may use a analog photosensitive resistor, also known as a photoresistor, to detect the level of light. Even though it is not giving you Lux, it does give you a 0-3.3V input of the level of light. If you close your hand around the resistor the voltage drops to about 0.65V and for direct sunlight or a bright lamp the voltage is a little more than 3.27V (32752 in formula, see below). In order to use the full spectrum (0-3.3V) an analog input device ADS1115 may be used. See hardware and settings below. If you aren't interested in the resolution of the signal you can skip the analog input device and create a voltage divider. As a rough guide, a 10k resistor can be connected between 3.3V and the analog input. The LDR can then be connected between the analog input and ground. This assumes you are using a NodeMCU like the Wemos D1 mini and not a bare ESP8266 chip.

Photosensitive resistor.jpg

Photosensitive resistor2.jpg

Hardware

There's a handful of different boards you may purchase, the one picture here also have two mounting holes but you may want to look at others as well. Be sure that you buy a board that do have analog output and not only digital! If you have a "digital only" you can't really measure the level of light more than be given a 1 if the light level is above the set value (which you tweak with the potentiometer, blue in the pictures). Otherwise the digital pin will read 0, and you will only be able to use the digital only device as a switch (which is not the scope of this page).

Photoresistor Mounted2.jpg

The ADS1115 is seen in the lower center of the picture (purple).

Photoresistor Mounted.jpg

Software

The formula 100-%value%*100/32752 turn the value into a percentage of about 18-20% at night (it will never hit 0% since it will always be some voltage over the resistor) and on an average day or lighting the percentage is about 82-85%. During the day the voltage rise is relatively linear and will output values evenly from the lowest 18% up to highest 85%.

Photoresistor Settings.jpg


Optional settings

Use of formulas

Use of value names