To come in
Sewerage and drainpipes portal
  • Inventor of the first printing press
  • New in the methodological literature of correctional and developmental education We work according to new standards
  • Signs of the presence in the house of spirits and ghosts
  • Educational system for the prevention and prophylaxis of offenses and crimes in the environment of Nesov - Educational work - Regional
  • What does tolerance mean: definition and meaning of the word What does tolerant mean?
  • Heading: Children's contests How the active participation of children in the Olympiads can help a teacher pass certification
  • Arduino light sensor connection. Photoresistor and LEDs on Arduino

    Arduino light sensor connection.  Photoresistor and LEDs on Arduino

    The electrical resistance of which changes under the influence of light rays falling on the light-sensitive surface and does not depend on the applied voltage, like a conventional resistor.

    Photoresistors are most commonly used to detect the presence or absence of light, or to measure the intensity of light. In the dark, their resistance is very high, sometimes reaching 1 MΩ, but when the LDR sensor is exposed to light, its resistance drops sharply, down to several tens of ohms, depending on the light intensity.

    Photoresistors have a sensitivity that changes with the wavelength of light. They are used in many devices, although they are inferior in popularity to photodiodes and phototransistors. Some countries have banned LDRs due to their lead or cadmium content for environmental reasons.

    Definition: A photoresistor is a photosensitive element whose resistance decreases in intense light and increases in its absence.

    Photoresistor characteristics

    Types of photoresistors and principle of operation

    Based on the materials used in production, photoresistors can be divided into two groups: with internal and external photoelectric effect. In the production of photoresistors with internal photoelectric effect, unalloyed materials such as silicon or germanium are used.

    The photons that hit the device cause electrons to move from the valence band to the conduction band. As a result of this process, a large number of free electrons appear in the material, thereby improving electrical conductivity and, consequently, decreasing resistance.

    Photoresistors with external photoelectric effect are made from materials with the addition of an impurity called a dopant. The dopant creates a new energy band on top of the existing valence band, populated by electrons. These electrons require less energy to make the transition to the conduction band due to the smaller energy gap. The result is that the photoresistor is sensitive to different wavelengths of light.

    Despite all this, both types show a reduction in resistance when illuminated. The higher the light intensity, the more the resistance drops. Therefore, the resistance of the photoresistor is an inverse, non-linear function of light intensity.

    The photoresistor in the diagrams is indicated as follows:

    Photoresistor sensitivity versus wavelength

    The sensitivity of the photoresistor depends on the wavelength of the light. If the wavelength is outside the operating range, then the light will have no effect on the LDR. We can say that LDR is not sensitive in this range of light wavelengths.

    Different materials have different unique spectral waveform response curves versus sensitivity. Externally light-dependent resistors are generally designed for longer wavelengths, with a tendency towards infrared (IR). When working in the IR range, care must be taken to avoid overheating, which can affect measurements due to thermal effect changes in the resistance of the photoresistor.

    The following figure shows the spectral response of photoconductive detectors made of various materials.

    Photoresistor sensitivity

    Photoresistors have a lower sensitivity than photodiodes and phototransistors. Photodiodes and phototransistors are semiconductor devices that use light to control the flow of electrons and holes through a PN junction, while photoresistors lack this PN junction.

    If the luminous flux is at a stable level, then the resistance can still change significantly due to temperature changes, since LDRs are also sensitive to temperature changes. This quality of the photoresistor makes it unsuitable for accurately measuring light intensity.

    Photoresistor inertness

    Another interesting property of the photoresistor is that there is an inertness (delay time) between changes in illumination and changes in resistance.

    In order for the resistance to drop to a minimum in full illumination, it takes about 10 ms of time, and about 1 second for the resistance of the photoresistor to rise to a maximum after it is darkened.

    For this reason, LDR cannot be used in devices where sudden changes in lighting must be taken into account.

    Photoresistor design and properties

    For the first time, photoconductivity was discovered in Selene, later other materials with similar properties were discovered. Modern photoresistors are made from lead sulfide, lead selenide, indium antimonide, but most often from cadmium sulfide and cadmium selenide. Popular cadmium sulfide LDRs are referred to as CDS photoresistors.

    To make a cadmium sulfide photoresistor, highly purified cadmium sulfide powder is mixed with inert binders. Then, this mixture is pressed and sintered. In a vacuum, a photosensitive layer in the form of a winding path is applied to the base with electrodes. Then, the base is placed in a glass or plastic shell to prevent contamination of the photosensitive element.

    The spectral response curve of cadmium sulfide matches the human eye. The peak sensitivity wavelength is about 560-600 nm, which corresponds to the visible part of the spectrum. It should be noted that devices containing lead or cadmium are not RoHS compliant and are prohibited for use in countries that adhere to RoHS laws.

    Application examples of photoresistors

    Photoresistors are most often used as light sensors when it is required to detect the presence or absence of light or to record the intensity of light. Examples are street light switches and photoexposure meters. As an example of using a photoresistor, we give a photo relay circuit for street lighting.

    Photo relay for street lighting

    This photo relay circuit automatically turns on street lighting when night falls and turns off when it gets brighter. In fact, you can use this scheme to implement any type of automatic night lighting.

    When the photoresistor (R1) is illuminated, its resistance decreases, the voltage drop across the variable resistor R2 will be high, as a result of which the transistor VT1 opens. The VT1 collector (BC107) is connected to the base of the VT2 transistor (SL100). Transistor VT2 is closed and the relay is de-energized. When night falls, the LDR resistance increases, the voltage across the variable resistor R2 drops, the transistor VT1 closes. In turn, the transistor VT2 opens and supplies voltage to the relay, which turns on the lamp.

    Photoresistors are made of semiconductor materials that change their resistance depending on the degree of illumination. Their main difference from other photovoltaic devices is the high stability of the parameters and the linearity of the change in resistance in a fairly wide range. The latter property makes it possible to use photoresistors not only in digital automation, but also in analog technology, for example, as galvanically isolated volume controllers.

    Photoresistors are relatively inertial elements with a much lower (units of kilohertz) response rate compared to photodiodes and phototransistors. After sharp changes in illumination, their resistance does not change abruptly, but "floats" for some time. This must be taken into account in practical work and to withstand small pauses in order to adapt to light. How "small" is an experiment will tell you.

    Depending on the spectral sensitivity, photoresistors are divided into two large groups: for work in the visible and infrared parts of the spectrum. They have the same electrical wiring diagrams (Fig. 3.44, a… m). The only thing that you need to know in advance from the datasheet is the maximum allowable operating voltage. In particular, the photoresistors SF2-5, SFZ-4A / B, SFZ-5 cannot be powered more than 1.3 ... 2 V. The vast majority of photoresistors can operate at voltages of 5 ... 50 V. Their dark resistance is 1 ... 200 MΩ , and in the illuminated state - two to three orders of magnitude less.

    Rice. 3.44. Schemes for connecting photoresistors to MK (beginning) -.

    a) resistors /? U, form a voltage divider. When the photoresistor is illuminated, its resistance decreases. Resistor J serves as protection in the event of a full closure of the trimming resistor and an erroneous transfer of the MKV line to the output mode with a HIGH level. If the resistor R2 is constant, then the resistor R3 can be replaced with a jumper;

    c) connecting the photoresistor /? 2k MK with reference to the common wire, and not to the power circuit. When the photoresistor R2 is illuminated, the voltage at the MK input decreases;

    Rice. 3.44. Schemes for connecting photoresistors to MK (continued):

    d) economical "Turchenkov relay" on germanium transistors VTI, K72 of different conductivity. The response threshold is poured into the mouth resistor;

    e) the photoresistor RI determines the base current of the UT1 transistor, since it enters the upper arm of the divider RI, R2. It is necessary to set the variable resistor slider in such a position that the base current of the UT1 transistor does not exceed the norm when the photoresistor is brightly illuminated;

    f) in the initial state, the photoresistor /? 2 is illuminated, the UT1 transistor is closed, the NI LED is off. When the illumination level of the photoresistor drops to a certain threshold (regulated by the resistor R3), the transistor opens, the LED lights up and a LOW level is set at the MK input;

    g) a recorder of short flashes of light or a receiver of pulse-modulated signals. The VTI transistor is in cut-off mode. Capacitor C / eliminates false alarms from slow changes in background illumination, for example, when the day changes at night;

    h) the VTI transistor increases the sensitivity of the photosensor R2, which allows using the usual line of the MK port, and not just the ADC input. The resistor sets the position of the operating point of the UT1 transistor \

    i) if both photoresistors R2 are illuminated, then a LOW level is present at the input of the MC (controlled by resistor R1). If one (any) of the photo resistors is darkened, then the total “photoresistance” will sharply increase and a HIGH level will appear at the input of the MC. Photoresistors perform the logical function "light AND";

    Rice. 3.44. Schemes for connecting photoresistors to MK (end):

    j) resistor R3 is used to regulate the operation threshold of the op-amp DAI (voltage comparator). The resistance of the resistor R2 is selected approximately the same as RI in the "inactive" state. If the photoresistor is significantly removed, its connecting wires should be shielded;

    l) capacitors C /, C2 increase the stability of measurements, eliminate impulse noise and create a small hysteresis with sharp fluctuations in illumination;

    m) an internal analog comparator MK is used to assess the level of illumination. The method of comparison of the measured voltage with the "saw" is used, which is produced by the MC itself at the negative terminal of the comparator (the input line temporarily becomes the output).

    Photodiodes in circuits on MK

    Photodiodes belong to the class of semiconductor devices, the operation of which is based on an internal photoelectric effect. When the p-A7 junction is irradiated with photons, the generation of current carriers inside the semiconductor occurs. A change in current is equivalent to a change in resistance, which is easy to record and measure.

    Photodiodes are widely used to register light emissions. Their advantage, in comparison with photoresistors and phototransistors, is their high speed and good sensitivity.

    There are two main modes of photodiode operation:

    Diode (photodiode, photoresistor) with reverse bias;

    Generator (photovoltaic, photovoltaic) without bias.

    Diode mode is used more often and has a wide range

    changes in reverse resistance and good performance. The generator mode has the following disadvantages: large equivalent capacity and high inertia. The advantage is a low level of intrinsic noise.

    Photodiodes are manufactured by the following companies: Vishay, OSRAM, Hamamatsu Photonics, Quartz, etc. Typical parameters: wavelength 850 ... 950 nm, current sensitivity 10 ... 80 μA, beam width 15 ... 65 °, rise / fall time 2 ... 100 ns , working temperature -55 ... + 100 ° С. The sensitivity of photodiodes decreases with increasing temperature and voltage. The dark current increases 2 ... 2.5 times for every 10 ° C, which is why temperature compensation is often introduced into the circuit.

    In Fig. 3.45, a ... g shows the diagrams of direct connection of photodiodes to the MC. In Fig. 3.46, a ... e shows circuits with transistor amplifiers. In Fig. 3.47, and ... about - with amplifiers on microcircuits.

    b) connecting the BLI photodiode to the power supply circuit. Pressing the SI switch simulates the illuminated state of the photodiode during test checks;

    c) increasing the overall sensitivity due to parallel connection of several BLI… Bin photodiodes. Photodiodes perform the logical function "light OR";

    d) parallel connection of several photodiodes with reference to a common wire;

    e) sequential switching on of photodiodes according to the "light I" scheme. Allows you to detect the moment of dimming of one of several illuminated photodetectors on the conveyor;

    f) sequential connection of several photodiodes with reference to a common wire;

    g) bridge circuit for switching on the BLI photodiode with increased sensitivity and hysteresis (R6). Pre-balancing of the bridge with resistor R3 is required.

    a) the BL1 photodiode replaces the base resistor of the transistor amplifier;

    b) the blinking NI LED serves as ... a photodetector. In the initial state, the NI generates electrical (not light!) Pulses with a "blinking" frequency of about 2 Hz. With external lighting, the generation is disrupted, which is fixed by the MC through the VTI transistor

    c) the key on the transistor VT1 increases noise immunity and increases the steepness of the signal edges from the BLL photosensor. Capacitor C / eliminates interference from fluctuations in illumination;

    d) opto-isolated frequency mixer. A signal with a difference "light" modulation frequency "/, - / 2" from two LEDs HL1 (/ j) and HL2 (f2) arrives at the input of the MC. The loop / 1 / must be tuned to the difference frequency;

    e) increasing the sensitivity due to the parallel connection of two VI, BL2 photodiodes. The VTI transistor is in cutoff and does not respond to slow light drift;

    f) instead of op-amp DAI, you can use an analog comparator MK. The reception speed of the "laser" photodiode is up to 5 Mbit / s via a fiber-optic cable Yum ... 1 km long.

    a) using a precision amplifier DA1 (Analog Devices) to ensure long-term stability of signals from the BLI photosensor

    b) non-standard switching on of the NI IR LED as a photodetector of the infrared wavelength range. The resistor regulates the gain of the stage on the DAI op amp

    c) amplifier-shaper on the "television" microcircuit DA1. The resistor adjusts the sensitivity of the BLI photosensor.

    d) bipolar power supply of the op-amp DA /. The CI capacitor eliminates the “ringing” on the signal fronts, which occurs during a sharp change in illumination. This is standard practice for other circuits as well;

    e) to reduce external noise, the DA 1.2 transient amplifier (this is a current-voltage converter) is covered by feedback through the DAI.3 integrator. The power supply to the op-amp is supplied from the MK output line. The 0.5 V reference forms a DAL follower /;

    Rice. 3.47. Schemes for connecting photodiodes to MK through amplifiers on microcircuits

    (continuation):

    f) VC, 5L2 photodiodes must be illuminated one by one, otherwise their total resistance may turn out to be so low that an overload on the power supply current will be triggered;

    g) capacitor C2 eliminates "ringing" with a large intrinsic capacity of the photodiode VI \

    h) a color meter based on a BL1 photodiode (Advances Photonics), which has a “bell-shaped” sensitivity in the range of 150 ... 400 nm. The jumper ^ S / sets the gain;

    i) stable parameters of photoreception in the infrared range are provided by a precision microcircuit Z) / 1 / (Analog Devices), a filter C4, R4 ... R6 and a VDI Zener diode.

    j) a bunch of "amplifier-detector-shaper" on the DAI op-amp with threshold adjustment (R6) \ O

    Rice. 3.47. Schemes for connecting photodiodes to MK through amplifiers on microcircuits

    (the ending):

    l) the comparator on the DA1 microcircuit provides high sensitivity and noise immunity. Resistor J adjusts the "light" threshold for a specific type of photodiode BL1 \

    m) the resistor adjusts the sensitivity and sets the operating point of the logic element DDI (preferably with the characteristic of the Schmitt trigger, for example, K561TL2);

    m) BL1 - three-color RGB sensor (Laser Components), DAI - four-channel transimpedance amplifier (Promis Electro Optics). One of the amplifier's four analog channels is not used. The signals from the MC outputs set the operating modes and amplification DA1 (o) a highly sensitive recorder of photo- or radiation radiation on a specialized pin-photodiode VI (similar ones are manufactured by Hamamatsu Photonics). The DA 1.1 element performs the function of a transimpedance, and DA1.2 - a conventional signal amplifier.

    Phototransistors in circuits on MK

    A phototransistor is a photosensitive semiconductor device similar in structure to a bipolar or field-effect transistor. The difference lies in the fact that a transparent window is provided in its body through which the light flux enters the crystal. In the absence of external lighting, the transistor is closed, the collector current is negligible. When the rays of light hit the /? - A7-junction of the base, the transistor opens and its collector current sharply increases.

    Phototransistors, in contrast to photoresistors, have high speed, and, unlike photodiodes, have amplifying properties (Table ZLO).

    The phototransistor, in a first approximation, can be represented as an equivalent photodiode connected in parallel with the collector junction of a conventional transistor. The photocurrent gain is directly proportional to / 7213. therefore, the sensitivity of the phototransistor is as many times higher than that of the photodiode.

    The main parameter to watch out for when designing phototransistor circuits is the collector current. In order not to exceed its norm, it is necessary to put sufficiently large resistances in the collector / emitter.

    Phototransistors are produced by the following companies: Vishay, Kingbright, Avago Technologies, etc. Typical parameters: wavelength 550 ... 570 or 830 ... 930 nm, collector current in the illuminated state 0.5 ... 10 mA, half sensitivity angle 15 ... 60 °, rise / fall time 2 ... 6 μs, operating temperature -55 ... + 100 ° С, conductivity p-p-p.

    There are two- and three-pin phototransistors. They differ from each other primarily by the absence / presence of a tap from the base.

    In two-pin phototransistors, only the collector and emitter are accessible from the outside. This makes it difficult to stabilize the operating point and makes the device dependent on the ambient temperature, especially in low light.

    Two-pin phototransistors and small-sized photodiodes are visually similar as "twin brothers". Finding out "what is what" helps the continuity of the conclusions with an ohmmeter. The test voltage at its terminals must be at least 0.7 V. If the resistance in one direction is much higher than in the other, then this is a photodiode. If a large resistance is ringing in two directions, then this is a phototransistor (or a failed photodiode).

    Three-pin phototransistors are less common than two-pin ones. To connect them, the usual transistor circuitry is used, namely, the operating point is stabilized using dividers on resistors, feedbacks, thermal compensation, etc. are introduced.

    In Fig. 3.48, a ... e shows the diagrams of direct connection of phototransistors to MK. In Fig. 3.49, a ... h show circuits with transistor amplifiers, in Fig. 3.50, a ... g - with amplifiers on microcircuits.

    Rice. 3.48. Diagrams for direct connection of phototransistors to MK:

    a) phototransistor 5L / is switched on according to the amplifier circuit with a common emitter. It is allowed to operate in the collector microcurrent mode (large resistance of the resistor RI), but this deteriorates the temperature stability. Instead of the ADC input, MKs often use the usual digital line of the port with a threshold latching of the "on light" / "no light" state;

    b) parallel connection of phototransistors BL1, 5L2 increases the light sensitivity. Phototransistors perform a logical OR function for signals from different light sources. Capacitor C / reduces impulse noise. There can be more than two paralleled phototransistors;

    c) a photodetector of pulsed and modulated light signals. The device does not react to slow changes in lighting due to the separating capacitor C /. Instead of a resistor, you can use an internal "pull-up" resistor MK;

    d) BLI phototransistor is switched on according to the emitter follower circuit. Capacitor C / reduces pulsed "light" noise and powerful electrical interference that can "leak" to the MK input when the phototransistor is closed;

    e) a three-pin BLI phototransistor, the base tap is used to provide feedback through the VTI transistor. The RI, C1 filter blocks the signals of the luminous flux with a modulation frequency below 100 Hz (to eliminate the sensor triggering from the "flickering" of incandescent lamps);

    f) the capacitor C / and the transistor VT1 organize a "light HPF" to suppress the signals of the luminous flux with a modulation frequency below 80 Hz. This prevents interference caused by the "flickering" of 50 Hz incandescent lamps from entering the MC.

    a) the input node of the "light gun" from the video game console "Dendy". The phototransistor BL1 is directed to the TV screen. Resistor /? 2 adjust the reception range;

    b) the VTI field-effect transistor matches the resistances RI and R2 \

    c) a two-stage amplifier based on transistors of different conductivity KG /, KT'2 provides increased sensitivity of the VI \

    d) an improved version of the photosensor for the "light gun" with auto adjustment for different background brightness. VTI elements, R1, R2, form a dynamic current stabilizer;

    e) resistor R2 is chosen such a position so that the VTI transistor is open in the absence of illumination of the phototransistor BLL Capacitor C1 filters noise;

    f) Schmitt trigger on field-effect transistors VTI, KT'2 determines the response threshold of the photosensor BL1. Capacitor C1 eliminates impulse "light" noise;

    g) VD1 diodes, increase the noise immunity of the amplifier on the VTI \ 0 transistor

    h) a three-stage amplifier based on KG / ... transistors with visual indication of the receipt of parcels from the infrared sensor ^ L / LED HL1.

    Rice. 3.50. Wiring diagrams for connecting phototransistors to MK through amplifiers on microcircuits:

    a) phototransistor sensor BLI with an integral comparator DAI wc with a wide range of parameters regulation using two variable resistors R2, R3 \

    b) Schmitt trigger on a logic chip DZ) / improves noise immunity and increases the steepness of the edges of the signals coming from the VI \

    c) the phototransistor ^ L / is connected to an external integral comparator DA1 to increase the accuracy of operation. Capacitor C / increases the slope of the signal edges;

    d) a band-pass filter on a DA / tone decoder chip (National Semiconductor) processes the pulsed-modulated light signals received by the BLI phototransistor. The center frequency of the filter is determined by the formula / ^ „[kHz] = 1 / (/? 2 [kOhm] -C4 [μF]). The filter bandwidth is inversely proportional to the capacitance of the capacitor C2. Resistor /? / Sets the optimal input signal level for DAI in the range of 100… 200 mV.

    Light sensors (lighting), built on the basis of photoresistors, are quite often used in real Arduino projects. They are relatively simple, not expensive, and easy to find and buy from any online store.

    The Arduino photoresistor allows you to control the level of illumination and respond to its change. In this article, we will look at what a photoresistor is, how a light sensor based on it works, how to properly connect a sensor to Arduino boards.

    Photoresistor, as the name suggests, has a lot to do with resistors that are often found in almost any electronic circuit. The main characteristic of a conventional resistor is its resistance value. Voltage and current depend on it, with the help of a resistor we set the required operating modes of other components. As a rule, the resistance value of a resistor under the same operating conditions practically does not change.

    Unlike a conventional resistor, it can change its resistance depending on the level of ambient light. This means that the parameters in the electronic circuit will constantly change, first of all we are interested in the voltage falling across the photoresistor. By fixing these voltage changes on the analog pins of the Arduino, we can change the logic of the circuit's operation, thereby creating devices that adapt to the external conditions.

    Photoresistors are actively used in a wide variety of systems. The most common application is street lights. If night falls on the city or it becomes cloudy, the lights turn on automatically. You can make an economical light bulb for the house from a photoresistor, which does not turn on according to a schedule, but depending on the lighting. On the basis of the light sensor, you can even make a security system that will be triggered immediately after a closed cabinet or safe is opened and illuminated. As always, the scope of any Arduino sensors is limited only by our imagination.

    What photoresistors can be bought in online stores

    The most popular and affordable sensor option on the market is mass production models of Chinese companies, clones of VT products. To get started with photoresistors, the simplest option is quite suitable.

    A beginner arduino player can be advised to buy a ready-made photo module, which looks like this:

    This module already has all the necessary elements for a simple connection of the photoresistor to the arduino board. In some modules, a circuit with a comparator is implemented and a digital output and a trimmer for control are available.

    A Russian radio amateur can be advised to turn to a Russian FR sensor. Available for sale FR1-3, FR1-4, etc. - were produced back in the union times. But, despite this, FR1-3 is a more accurate detail. It follows from this that the difference in price is not more than 400 rubles. FR1-3 will cost more than a thousand rubles apiece.

    The modern marking of models produced in Russia is quite simple. The first two letters are PhotoResistor, the numbers after the dash indicate the development number. FR-765 - photoresistor, development 765. Usually marked directly on the body of the part

    For the VT sensor, the resistance range is indicated in the marking diagram. For example:

    • VT83N1 - 12-100kOhm (12K - lit, 100K - in the dark)
    • VT93N2 - 48-500kOhm (48K - lit, 100K - in the dark).

    Sometimes the seller provides a special document from the manufacturer to clarify information about the models. In addition to the parameters of work, the accuracy of the part is also indicated there. For all models, the sensitivity range is located in the visible part of the spectrum. Collecting light sensor you need to understand that accuracy of operation is a conditional concept. Even for models from one manufacturer, one batch, one purchase, it can differ by 50% or more.

    At the factory, the parts are tuned to a wavelength from red to green. At the same time, the majority “sees” infrared radiation. Highly precise details can even capture ultraviolet light.

    Advantages and disadvantages of the sensor

    The main disadvantage of photoresistors is their sensitivity to the spectrum. Depending on the type of incident light, the resistance can vary by several orders of magnitude. The disadvantages also include the low speed of reaction to changes in illumination. If the light is flashing, the sensor does not have time to respond. If the frequency of change is rather high, the resistor will stop "seeing" that the illumination is changing.

    The advantages include simplicity and affordability. The direct change in resistance depending on the light falling on it makes it possible to simplify the electrical wiring diagram. The photoresistor itself is very cheap, it is part of numerous Arduino kits and constructors, therefore it is available to almost any novice Arduino player.

    In projects arduino the photoresistor is used as a light sensor. Receiving information from him, the board can turn on or off relays, start motors, send messages. Naturally, in this case, we must correctly connect the sensor.

    The diagram for connecting the light sensor to the Arduino is pretty simple. If we use a photoresistor, then in the connection diagram the sensor is implemented as a voltage divider. One arm changes with the illumination level, the second supplies voltage to the analog input. In a controller microcircuit, this voltage is converted into digital data through an ADC. Because the resistance of the sensor when light hits it decreases, then the value of the voltage falling on it will decrease.

    Depending on which arm of the divider we put the photoresistor in, either an increased or decreased voltage will be applied to the analog input. In the event that one leg of the photoresistor is connected to ground, then the maximum voltage value will correspond to darkness (the resistance of the photoresistor is maximum, almost all the voltage drops across it), and the minimum value will correspond to good lighting (the resistance is close to zero, the voltage is minimum). If we connect the arm of the photoresistor to the power supply, then the behavior will be the opposite.

    The installation of the board itself should not be difficult. Since the photoresistor has no polarity, you can connect it either side, you can solder it to the board, connect it with wires using a circuit board, or use ordinary clips (crocodiles) for connection. The power source in the circuit is the arduino itself. Photoresistor connected with one foot to the ground, the other is connected to the ADC of the board (in our example - AO). We connect a 10 kOhm resistor to the same leg. Naturally, you can connect the photoresistor not only to the analog pin A0, but also to any other one.

    A few words about the additional 10K resistor. It has two functions in our circuit: to limit the current in the circuit and to form the desired voltage in the circuit with a divider. Current limiting is needed in a situation where a fully illuminated photoresistor sharply decreases its resistance. And voltage shaping is for predictable values ​​at the analog port. In fact, for normal operation with our photoresistors, a resistance of 1K is enough.

    By changing the value of the resistor, we can "shift" the sensitivity level to the "dark" and "light" sides. So, 10 K will give a quick switch of the onset of light. In the case of 1K, the light sensor will more accurately detect high light levels.

    If you are using a ready-made light sensor module, then the connection will be even easier. We connect the output of the VCC module to the 5V connector on the board, GND - to the ground. We connect the remaining pins to the arduino connectors.

    If there is a digital output on the board, then we send it to the digital pins. If analog - then analog. In the first case, we will receive a trigger signal - exceeding the illumination level (the trigger threshold can be adjusted using an adjustment resistor). From the analog pins, we will be able to receive a voltage value proportional to the real level of illumination.

    We connected the circuit with the photoresistor to the arduino, made sure that everything was done correctly. Now it remains to program the controller.

    It's pretty easy to sketch a light sensor. We only need to remove the current voltage value from the analog pin to which the sensor is connected. This is done using the analogRead () function known to all of us. Then we can perform some actions, depending on the light level.

    Let's write a sketch for a light sensor that turns on or off an LED connected as follows.

    The work algorithm is as follows:

    • Determine the signal level from the analog pin.
    • We compare the level with the threshold value. The maximum value will correspond to darkness, the minimum value will correspond to the maximum illumination. We will choose the threshold value equal to 300.
    • If the level is less than the threshold, it is dark, you need to turn on the LED.
    • Otherwise, turn off the LED.

    #define PIN_LED 13 #define PIN_PHOTO_SENSOR A0 void setup () (Serial.begin (9600); pinMode (PIN_LED, OUTPUT);) void loop () (int val = analogRead (PIN_PHOTO_SENSOR); Serial.println (val); if ( val< 300) { digitalWrite(PIN_LED, LOW); } else { digitalWrite(PIN_LED, HIGH); } }

    #define PIN_LED 13

    #define PIN_PHOTO_SENSOR A0

    void setup () (

    Serial. begin (9600);

    void loop () (

    Serial. println (val);

    if (val< 300 ) {

    digitalWrite (PIN_LED, LOW);

    ) else (

    digitalWrite (PIN_LED, HIGH);

    Covering the photoresistor (with our hands or with an opaque object), we can observe the switching on and off of the LED. By changing the threshold parameter in the code, we can force the light bulb to be turned on / off at different lighting levels.

    When mounting, try to position the photoresistor and LED as far apart as possible so that less light from the bright LED hits the light sensor.

    Light sensor and smooth change of backlight brightness

    You can modify the project so that depending on the level of illumination, the brightness of the LED changes. We will add the following changes to the algorithm:

    • We will change the brightness of the light bulb via PWM, sending values ​​from 0 to 255 to the pin with the LED using analogWrite ().
    • To convert the digital value of the light level from the light sensor (from 0 to 1023) into the PWM range of the LED brightness (from 0 to 255), we will use the map () function.

    Example sketch:

    #define PIN_LED 10 #define PIN_PHOTO_SENSOR A0 void setup () (Serial.begin (9600); pinMode (PIN_LED, OUTPUT);) void loop () (int val = analogRead (PIN_PHOTO_SENSOR); Serial.println (val); int ledPower = map (val, 0, 1023, 0, 255); // Convert the resulting value into a PWM signal level. The lower the illumination value, the less power we must supply to the LED through the PWM. analogWrite (PIN_LED, ledPower); // Change the brightness)

    #define PIN_LED 10

    #define PIN_PHOTO_SENSOR A0

    void setup () (

    Serial. begin (9600);

    pinMode (PIN_LED, OUTPUT);

    void loop () (

    int val = analogRead (PIN_PHOTO_SENSOR);

    Serial. println (val);

    int ledPower = map (val, 0, 1023, 0, 255); // Convert the received value to the PWM signal level. The lower the illumination value, the less power we must supply to the LED through the PWM.

    analogWrite (PIN_LED, ledPower); // Change the brightness

    In the case of another connection method, in which the signal from the analog port is proportional to the degree of illumination, it will be necessary to additionally “reverse” the value, subtracting it from the maximum:

    int val = 1023 - analogRead (PIN_PHOTO_RESISTOR);

    A photoresistor is a semiconductor radioelement that changes its resistance depending on the lighting. For visible light (sunlight or light from lighting lamps), cadmium sulfide or selenide is used. There are also photoresistors that detect infrared radiation. They are made from germanium with some admixtures of other substances.The property of changing its resistance under the influence of light is very widely used in electronics.

    Appearance and designation in the diagram

    Basically, photoresistors look like this



    The diagrams can be denoted as follows

    or so

    How the photoresistor works

    Let's take a look at one of the members of the photoresistor family.


    On it, as in all photocells, there is a window through which it “catches” the light.



    The main parameter of a photoresistor is its dark resistance. The dark resistance of a photoresistor is its resistance when there is no light falling on it. Judging by the reference book, the dark resistance of our ward is 15x10 8 ohms, or in words - 1.5 GΩ. One might even say - a complete cliff. Is it so? Let's take a look. To do this, I use my notebook and hide the photoresistor there:


    Even in the range of 200 megohms, the multimeter showed one. This means that the resistance of the photoresistor is well beyond 200 megohms.

    We remove our experimental from the book and turn on the light in the room. The result is immediately visible:


    106.7 ohms.

    Now I turn on my desk lamp. The room became even brighter. We look at the readings of the multimeter:


    76.2 ohms.

    I bring the photoresistor close to the table lamp:


    18.6 kohm

    We conclude: the more the light flux hits the photoresistor, the lower its resistance.

    New articles

    ● Project 13: Photoresistor. We process illumination by lighting or extinguishing LEDs

    In this experiment, we will get acquainted with an analog sensor for measuring illumination - a photoresistor (Fig.13.1).

    Required components:

    A common use of a photoresistor is to measure illumination. In the dark, his resistance is pretty great. When light strikes the photoresistor, the resistance falls in proportion to the illumination. The diagram for connecting the photoresistor to the Arduino is shown in Fig. 13.2. To measure the illumination, it is necessary to assemble a voltage divider, in which the upper arm will be represented by a photoresistor, the lower one - by an ordinary resistor of a sufficiently large rating. We will use a 10k resistor. We connect the middle arm of the divider to the analog input A0 of the Arduino.

    Rice. 13.2. Wiring diagram of photoresistor to Arduino

    Let's write a sketch of reading analog data and sending it to the serial port. The contents of the sketch are shown in Listing 13.1.

    Int light; // variable for storing photoresistor data void setup ()(Serial.begin (9600);) void loop ()(light = analogRead (0); Serial.println (light); delay (100);)
    Connection procedure:

    1. We connect the photoresistor according to the diagram in fig. 13.2.
    2. Load the sketch from Listing 13.1 into the Arduino board.
    3. We regulate the illumination of the photoresistor by hand and observe the output to the serial port of the changing values, remember the readings at full illumination of the room and at complete overlapping of the luminous flux.

    Now let's create a light indicator using an LED row of 8 LEDs. The number of LEDs lit is proportional to the current illumination. We assemble the LEDs according to the diagram in Fig. 13.3 using 220 ohm limiting resistors.

    Rice. 13.3. Wiring diagram of photoresistor and LEDs to Arduino


    The contents of the sketch for displaying the current illumination on the LED bar are shown in Listing 13.2.

    // Contact for connecting LEDs const int leds = (3, 4, 5, 6, 7, 8, 9, 10); const int LIGHT = A0; // Pin A0 for photoresistor input const int MIN_LIGHT = 200; // Lower illumination threshold const int MAX_LIGHT = 900; // upper illumination threshold // Variable for storing photoresistor data int val = 0; void setup (){ // Configure LED pins as output for (int i = 0; i<8 ;i++) pinMode(leds[i],OUTPUT); } void loop ()(val = analogRead (LIGHT); // Read the readings of the photoresistor // Using the map () function val = map (val, MIN_LIGHT, MAX_LIGHT, 8, 0); // we restrict so that it does not exceed the bounds val = constrain (val, 0, 8); // light the number of LEDs proportional to the illumination, // extinguish the rest for (int i = 1; i<9 ;i++) { if (i>= val) // light up the leds digitalWrite (leds, HIGH); else // turn off the LEDs digitalWrite (leds, LOW); ) delay (1000); // pause before next measurement }
    Connection procedure:

    1. We connect the photoresistor and LEDs according to the diagram in fig. 13.3.
    2. Load the sketch from Listing 13.2 into the Arduino board.
    3. We adjust the illumination of the photoresistor by hand and determine the current illumination level by the number of LEDs lit (Fig. 13.3).

    We take the lower and upper limits of illumination from the memorized values ​​when performing the experiment on the previous sketch (Listing 13.1). We scale the intermediate illumination value by 8 values ​​(8 LEDs) and light the number of LEDs proportional to the value between the lower and upper limits.

    Program listings