Difference between revisions of "Photosensitive resistor"
Grovkillen (talk | contribs) m (→Introduction) |
Whatsupskip (talk | contribs) m (→Introduction) |
||
(10 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
= Introduction = | = Introduction = | ||
− | Instead of using a Lux/light sensor you may | + | Instead of using a Lux/light sensor you may use a analog photosensitive resistor, also known as a [https://en.wikipedia.org/wiki/Photoresistor 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 [https://learn.sparkfun.com/tutorials/voltage-dividers 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. |
− | |||
[[File:Photosensitive_resistor.jpg|320px]] | [[File:Photosensitive_resistor.jpg|320px]] | ||
Line 8: | Line 7: | ||
= Hardware = | = Hardware = | ||
− | There's a handful of different boards you may purchase | + | 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. <span style="color:red">Be sure that you buy a board that do have '''analog output''' and not only digital!</span> 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). |
[[File:Photoresistor_Mounted2.jpg|320px]] | [[File:Photoresistor_Mounted2.jpg|320px]] |
Latest revision as of 06:58, 1 December 2018
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.
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).
The ADS1115 is seen in the lower center of the picture (purple).
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%.