This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:practical:hardware:itt:avr:photoresistor [2025/09/02 09:46] – raivo.sell | en:iot-open:practical:hardware:itt:avr:photoresistor [2025/09/02 11:25] (current) – raivo.sell | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| [{{ : | [{{ : | ||
| - | A photoresistor is a sensor whose electrical resistance is altered depending on the light intensity falling on it. The more intense the light, the more free carriers are formed and therefore the lower the resistance of the element. Two exterior metal contacts of the photoresistor reach through the ceramic base material to the light-sensitive membrane, which determines the electrical resistance properties with its geometry and material properties. Since photo-sensitive material itself has high resistance, with a narrow, curvy track between the electrodes, low total resistance at average light intensity is gained. Similar to the human eye, the photoresistor is sensitive to a certain range of wavelengths and needs to be considered when selecting a photo element, otherwise it may not react to the light source used in the application. The following is a simplified list of wavelengths of visible light segmented by colours: | + | A photoresistor is a sensor whose electrical resistance is altered depending on the light intensity falling on it. The more intense the light, the more free carriers are formed and therefore the lower the resistance of the element. Two exterior metal contacts of the photoresistor reach through the ceramic base material to the light-sensitive membrane, which determines the electrical resistance properties with its geometry and material properties. Since photo-sensitive material itself has high resistance, with a narrow, curvy track between the electrodes, low total resistance at average light intensity is gained. Similar to the human eye, the photoresistor is sensitive to a certain range of wavelengths and needs to be considered when selecting a photo element; otherwise, it may not react to the light source used in the application. The following is a simplified list of wavelengths of visible light segmented by colours: |
| ^ Colour | ^ Colour | ||
| Line 15: | Line 15: | ||
| | Red | 610 – 700 | | | Red | 610 – 700 | | ||
| - | A range of working | + | A range of working |
| - | + | For characterizing light intensity, a physical concept called light intensity (E) is used, which shows the quantity of light reaching any given surface. | |
| - | For characterizing light intensiveness | + | |
| Line 30: | Line 29: | ||
| ===== Practice ===== | ===== Practice ===== | ||
| - | The HomeLab is equipped with VT935G photoresistor. One pin of the photoresistor is connected to power supply and second pin to the analogue-digital converter | + | The HomeLab is equipped with a VT935G photoresistor. One pin of the photoresistor is connected to the power supply, and the second pin to the analogue-digital converter channel 1. Between this pin and the ground resistor is also connected, which forms a voltage divider with the photoresistor. Since the electrical resistance of the photoresistor |
| | | ||
| - | The sensor VT935G is not meant to be a specific measuring device. It is meant to be more a device to specify overall lighting conditions – is there a lighted lamp in the room or not. In this case one has to just measure the resistance of the sensor in the half dark room, note it in the program and compare measured values – is it lighter or darker. | + | The sensor VT935G is not meant to be a specific measuring device. It is meant to be more a device to specify overall lighting conditions – is there a lighted lamp in the room or not. In this case, one has to just measure the resistance of the sensor in a half-dark room, note it in the program, and compare |
| - | The exercise here is a little bit more complex as the light intensity is measured | + | The exercise here is a little bit more complex, as the light intensity is also measured |
| - | [{{ : | + | The example source code measures the light intensity, calculates it using ADC, and displays the intensity of light on the LCD. |
| - | There is an approximate formula showing the relationship between the intensity of light and electrical resistance in the sensor datasheet. As seen on the graph (on the right), with using logarithm scale, the resistance and intensity of light are almost in linear relationship and form a in-line formula, because following conversion applies: | + | In the example program, variables of voltage, resistance, and intensity are defined using type //double// of floating-point variables. The variables which should be used as floating-point variables must always contain a decimal point (it can also be just 0, because then the compiler understands it correctly). |
| - | + | ||
| - | log(a/b) = log(a) - log(b) | + | |
| - | + | ||
| - | The relation is characterised by the ascent of the factor γ (ascend of the line), which is 0,9 on VT935G sensor. We have also data on one of the points on that line: resistance 18.5 kΩ (R< | + | |
| - | + | ||
| - | log(E< | + | |
| - | E< | + | |
| - | + | ||
| - | This gives the formula for calculating the intensity of light when the resistance is known. The resistance can not be measured directly with microcontroller. For this the photoresistor is in the voltage divider. The output voltage of this voltage divider is converted to a specific variable by the analogue-digital converter (ADC). To find the resistance, the output voltage (U< | + | |
| - | The formula is following: | + | |
| - | + | ||
| - | U< | + | |
| - | + | ||
| - | From the formula for voltage divider(check the chapter on voltage divider) the resistance of the upper photoresistor (R< | + | |
| - | + | ||
| - | R< | + | |
| - | + | ||
| - | In the following calculation of voltage and resistance, the known factors are replaced with numbers and indexes have been removed: | + | |
| - | + | ||
| - | U = 5 * (ADC / 1024) \\ \\ | + | |
| - | R = (10 * 5) / U - 10 \\ \\ | + | |
| - | + | ||
| - | For finding the intensity of light, simplifying conversions can be done: | + | |
| - | + | ||
| - | E = 10< | + | |
| - | = 10< | + | |
| - | = (18.5< | + | |
| - | + | ||
| - | + | ||
| - | By calculating the constant in front of the variable of the field R, the expression remains follows: | + | |
| - | + | ||
| - | E = 255,84 * R< | + | |
| - | + | ||
| - | These formulas help only if the photoresistor on the module of the HomeLab is used. If circuit is used equipped with different components, respective variables need to be changed. Next, source code of the example program | + | |
| - | + | ||
| - | In the example program | + | |
| <code c> | <code c> | ||
| Line 115: | Line 78: | ||
| { | { | ||
| // Reading the average value of the photoresistor | // Reading the average value of the photoresistor | ||
| - | adc_value = adc_get_average_value(13, | + | adc_value = adc_get_average_value(1, |
| - | // HomeLab II | + | |
| - | //adc_value = adc_get_average_value(1, | + | |
| // Calculating the voltage in the input of the ADC | // Calculating the voltage in the input of the ADC | ||
| - | // HomeLab II | + | voltage = 5.0 * ((double)adc_value / 1024.0); |
| - | //voltage = 5.0 * ((double)adc_value / 1024.0); | + | |
| - | // HomeLab III | + | |
| - | voltage = 2.0625 * ((double)adc_value / 2048.0); | + | |
| // Calculating the resistance of the photoresistor | // Calculating the resistance of the photoresistor | ||
| // in the voltage divider | // in the voltage divider | ||
| - | // HomeLab II | + | resistance = (10.0 * 5.0) / voltage - 10.0; |
| - | //resistance = (10.0 * 5.0) / voltage - 10.0; | + | |
| - | // HomeLab III | + | |
| - | resistance = (33.0) / voltage - 10.0; | + | |
| // Calculating the intensity of light in lux | // Calculating the intensity of light in lux | ||
| illuminance = 255.84 * pow(resistance, | illuminance = 255.84 * pow(resistance, | ||
| - | // Dividing variable into two integer | + | // Dividing |
| // to display it on the screen | // to display it on the screen | ||
| int8_t illu = illuminance; | int8_t illu = illuminance; | ||
| Line 151: | Line 106: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | ==== Task to be implemented ==== | ||
| + | - Make a three-level light indicator, either dark, normal, or intense light, and show the result with three LEDs (green, yellow, and red). | ||
| + | |||