| Next revision | Previous revision |
| pt:examples:sensor:photoresistor [2015/12/15 14:01] – Criação deste novo documento. artica | pt:examples:sensor:photoresistor [2020/07/20 09:00] (current) – external edit 127.0.0.1 |
|---|
| ====== Fotoresistência ====== | ====== Fotoresistor ====== |
| |
| //Conhecimento necessário: | //Conhecimento necessário: |
| ===== Teoria ===== | ===== Teoria ===== |
| |
| [{{ :examples:sensor:photoresistor:sensor_photoresistor_designator.png?150|Símbolo eléctrico de uma fotoresistência}}] | [{{ :examples:sensor:photoresistor:sensor_photoresistor_designator.png?150|Símbolo eléctrico de um fotoresistor}}] |
| [{{ :examples:sensor:photoresistor:sensor_photoresistor.jpg?150|Uma Fotoresistência}}] | [{{ :examples:sensor:photoresistor:sensor_photoresistor.jpg?150|Um fotoresistor}}] |
| |
| A photoresistor is a sensor which electrical resistance is altered depending on the light intensity falling on it. The more intense is the light the more free carriers are formed and therefore the lower gets the resistance of the element. Two exterior metal contacts of the photoresistor are reaching 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 narrow, curvy track between the electrodes, low total resistance at average light intensity is gained. Similarly to the human eye, the photoresistor is sensitive at 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. Following is simplified list of wavelengths of visible light segmented by colours: | Um fotoresistor é um sensor de resistência eléctrica que é alterada dependendo da intensidade da luz que incide sobre ele. Quanto mais intensa a luz é mais transportadores livres são formados e, por conseguinte, menos resistência tem o elemento. Os dois contactos metálicos exteriores do fotoresistor são atingidos através do material de base cerâmica para a membrana sensível à luz, que determina as propriedades de resistência elétrica de acordo com as suas propriedades e geometria do material. Como o material foto sensível em si tem alta resistência, um caminho estreito entre entre os eletrodos, é adquirida baixa resistência total a uma intensidade média de luz. De modo semelhante ao olho humano, o fotoresistor é sensível a uma determinada gama de comprimentos de onda que tem de ser considerada quando se selecciona um foto elemento, caso contrário pode não reagir à fonte de luz utilizada na aplicação. Segue-se a lista simplificada de comprimentos de onda de luz visível segmentado por cores: |
| |
| ^ Colour ^ Range of wavelength (nm) ^ | ^ Colour ^ Range of wavelength (nm) ^ |
| | Red | 610 – 700 | | | Red | 610 – 700 | |
| |
| A range of working temperature is set for photoresistor. Wishing the sensor to work at different temperatures, precising conversions must be executed, because the resisting properties of the sensors are depending on the temperature of the ambient. | A gama de temperatura de trabalho está marcada para fotoresistor. Se desejarmos que o sensor de trabalhe a temperaturas diferentes, conversões precisas devem ser executadas, porque as propriedades de resistência dos sensores dependem da temperatura do ambiente. |
| |
| For characterizing light intensiveness physical concept called light intensity (E) is used, this shows the quantity of light reaching any given surface. Measuring unit is lux (lx), where 1 lux represents, the even flow of light 1 lumen, falling on a surface of 1 m<sup>2</sup>. Hardly ever in reality falls light (living area) on a surface evenly and therefore light intensity is reached generally as a average number. Below are few examples of light intensity for comparison: | Para caracterizar o conceito físico de intensidade de luz, a chamada simplesmente intensidade da luz (E) é usada. Esta representa a quantidade de luz que atinge qualquer superfície. A sua unidade de medição é lux (lx), em que 1 lux representa, a distribuição uniforme de um fluxo de luz de 1 lúmen, que cai sobre uma superfície de 1 m<sup>2</sup>. Quase nunca na realidade a luz cai de forma uniforme numa superfície e, portanto, a intensidade de luz é geralmente uma média. Abaixo estão alguns exemplos de intensidade de luz para comparação: |
| |
| |
| | Direct sun light | 10000 | | | Direct sun light | 10000 | |
| |
| ===== Practice ===== | ===== Prática ===== |
| 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 (HomeLab II channel 1, HomeLab III channel 13). 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 is decreasing as the light intensity falling on it grows, the measured voltage on the pin of the microcontroller grows as light intensity grows. It is worth to take into account that the photoresistor used in the HomeLab reacts most on orange and yellow light. | O HomeLab está equipado com um fotoresistor VT935G. Um pin do fotoresistor está conectado à fonte de alimentação e um segundo pin ao conversor analógico-digital (HomeLab II canal 1, HomeLab III canal 13). Entre este pin e a terra, a resistência está também ligada, o qual forma um divisor de tensão com o fotoresistor. Uma vez que a resistência eléctrica do fotoresistor diminui à medida que a intensidade da luz que incide sobre ele cresce, a tensão medida no pin do microcontrolador cresce à medida que a intensidade da luz aumenta. Vale a pena ter em conta que o fotoresistor utilizado no HomeLab reage mais em luz laranja e amarela. |
| | |
| 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 exercise here is a little bit more complex as the light intensity is measured also in lux. For doing this, exists an approximate formula and floating-point variables. In the C-language are floating-point variables //float-// and //double//-type variables, which can be used to present fractions. Their flaw is high demand of resources. Computers have special hardware to calculate floating-point variables, in the 8-bit AVR microcontroller calculations are executed in software which demands a lot of memory and time. If the flaws are not critical, the floating-point variables are worth using. | O sensor VT935G não se destina a ser um aparelho de medição específico. Ele foi criado para ser mais um dispositivo para especificar as condições gerais de iluminação - há uma lâmpada acesa na sala ou não. Neste caso é preciso apenas medir a resistência do sensor ao ambiente em meia luz, observar os valores no programa e comparar com valores posteriormente medidos - é mais claro ou mais escuro? |
| |
| | O exercício aqui é um pouco mais complexo pois a intensidade da luz é medida também em lux. Para fazer isto, existe uma fórmula de aproximação e variáveis floating point. Na linguagem C são as variáveis do tipo //float-// e //double//, que podem ser utilizadas para apresentar fracções. A sua desvantagem é consumirem muitos recursos. Os computadores têm um hardware especial para calcular variáveis destes tipos. No controlador AVR de 8 bits os cálculos são executadas em software o que exige muita memória e tempo. Se esta desvantagem não é crítica, vale a pena usar estes tipos. |
| |
| [{{ :examples:sensor:photoresistor:sensor_photoresistor_vt935g_slope.png?260|Relationship between resistance (R) of VT935G and intensity of light (E)}}] | |
| |
| 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: | [{{ :examples:sensor:photoresistor:sensor_photoresistor_vt935g_slope.png?260|Relação entre a resistência (R) do VT935G e a intensidade de luz (E)}}] |
| | |
| | Existe uma fórmula aproximada que mostra a relação entre a intensidade da luz e da resistência eléctrica na datasheet do sensor. Como pode ser visto no gráfico (à direita), com a utilização da escala logarítmica, a resistência e a intensidade da luz estão quase em relação linear, a seguinte conversão pode aplicar-se: |
| |
| log(a/b) = log(a) - log(b) | 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<sub>A</sub>) at 10 lx intensity of light (E<sub>A</sub>). Hence we have the coordinates of one point as well as the ascent of the line and for calculating any other point, we only need one coordinate. Meaning, if sensors' resistance (R<sub>B</sub>) is measured, it is possible to calculate from the equation of line, the intensity of light E<sub>B</sub>) that falls on the sensor. Finding E<sub>B</sub> from the equation of line: | A relação é caracterizada pelo crescimento do factor γ (declive da linha), que é de 0,9 no sensor VT935G. Temos também dados num dos pontos da linha: resistência de 18,5 kΩ (R<sub>A</sub>) em intensidade da luz de 10 lx (E<sub>A</sub>). Assim, temos as coordenadas de um ponto, bem como o declive da linha e para o cálculo de qualquer outro ponto, precisamos apenas de uma coordenada. Ou seja, se a resistência dos sensores (R<sub>B</sub>) é medida, é possível calcular a partir da equação, a intensidade da luz (E<sub>B</sub>) que cai sobre o sensor. Encontrar E<sub>B</sub> a partir da equação de linha é: |
| |
| log(E<sub>B</sub>) = log(R<sub>A</sub>/R<sub>B</sub>) / γ + log(E<sub>A</sub>) \\ \\ | log(E<sub>B</sub>) = log(R<sub>A</sub>/R<sub>B</sub>) / γ + log(E<sub>A</sub>) \\ \\ |
| E<sub>B</sub> = 10<sup>log(R<sub>A</sub>/R<sub>B</sub>) / γ + log(E<sub>A</sub>)</sup> | E<sub>B</sub> = 10<sup>log(R<sub>A</sub>/R<sub>B</sub>) / γ + log(E<sub>A</sub>)</sup> |
| |
| 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<sub>2</sub>) of the voltage divider must be calculated first, using the ADC value, also comparison voltage (U<sub>ref</sub>) of the converter must be taken into account: | Isto dá a fórmula para calcular a intensidade da luz quando a resistência é conhecida. A resistência não pode ser medida diretamente com o microcontrolador. Para isso, o fotoresistor está ligado ao divisor de tensão. A tensão de saída do divisor de tensão é convertida para uma variável específica pelo conversor analógico-digital (ADC). Para determinar a resistência, a tensão de saída (U<sub>2</sub>) do divisor de tensão deve ser calculada em primeiro lugar, usando o valor do ADC, e a tensão de comparação (U<sub>ref</sub>) do conversor deve ser tida em conta. A fórmula é seguinte: |
| The formula is following: | |
| |
| U<sub>2</sub> = U<sub>ref</sub> * (ADC / 1024) | U<sub>2</sub> = U<sub>ref</sub> * (ADC / 1024) |
| |
| From the formula for voltage divider(check the chapter on voltage divider) the resistance of the upper photoresistor (R<sub>1</sub>) can be found: | Da fórmula para o divisor de tensão (veja o capítulo sobre divisor de tensão) a resistência do fotoresistor superior (R<sub>1</sub>) pode ser encontrada: |
| |
| R<sub>1</sub> = (R<sub>2</sub> * U<sub>1</sub>) / U<sub>2</sub> - R<sub>2</sub> | R<sub>1</sub> = (R<sub>2</sub> * U<sub>1</sub>) / U<sub>2</sub> - R<sub>2</sub> |
| |
| In the following calculation of voltage and resistance, the known factors are replaced with numbers and indexes have been removed: | No seguinte cálculo de tensão e resistência, os factores conhecidos substituídos com números e índices foram removidos: |
| |
| U = 5 * (ADC / 1024) \\ \\ | U = 5 * (ADC / 1024) \\ \\ |
| R = (10 * 5) / U - 10 \\ \\ | R = (10 * 5) / U - 10 \\ \\ |
| |
| For finding the intensity of light, simplifying conversions can be done: | Para encontrar a intensidade de luz, conversões simplificadas podem ser feitas: |
| |
| E = 10<sup>log(18.5/R) / 0.9 + 1</sup> = 10<sup>log(18.5/R) * 10/9</sup> * 10<sup>1</sup> = \\ \\ | E = 10<sup>log(18.5/R) / 0.9 + 1</sup> = 10<sup>log(18.5/R) * 10/9</sup> * 10<sup>1</sup> = \\ \\ |
| = (18.5<sup>10/9</sup> / R<sup>10/9</sup>) * 10 = 18.5<sup>10/9</sup> * 10 * R<sup>-10/9</sup> | = (18.5<sup>10/9</sup> / R<sup>10/9</sup>) * 10 = 18.5<sup>10/9</sup> * 10 * R<sup>-10/9</sup> |
| |
| | Ao calcular a constante em frente da variável de campo R, a expressão permanece a seguinte: |
| By calculating the constant in front of the variable of the field R, the expression remains follows: | |
| |
| E = 255,84 * R<sup>-10/9</sup> | E = 255,84 * R<sup>-10/9</sup> |
| |
| 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 is presented, which measures and calculates using ADC and displays the intensity of light on the LCD. | Estas fórmulas ajudam apenas se o fotoresistor no módulo do HomeLab é usado. Se o circuito utilizado é equipado com componentes diferentes, as respectivas variáveis precisam de ser alteradas. De seguida, o código-fonte do programa de exemplo é apresentado. Este mede e calcula usando o ADC e exibe a intensidade da luz no LCD. |
| |
| 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 be also just 0, because then the compiler understands it correctly). | No programa de exemplo as variáveis de tensão, resistência e intensidade são definidas usando o tipo //double// de variáveis floating point. As variáveis que devem ser usadas como variáveis tipo floating point devem conter sempre um ponto decimal (pode ser também apenas 0, pois o compilador também o entende corretamente). |
| |
| <code c> | <code c> |