Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:examples:sensor:photoresistor [2015/11/10 08:51] heikopikneren:examples:sensor:photoresistor [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Photoresistor ====== ====== Photoresistor ======
  
-//Necessary knowledge: [HW] [[en:hardware:homelab:sensor]], [HW] [[en:hardware:homelab:digi]], [ELC] [[en:electronics:voltage_divider]], [AVR] [[en:avr:adc]], [LIB] [[en:software:homelab:library:adc]], [LIB] [[en:software:homelab:library:module:lcd_graphic]], [PRT] [[en:examples:setup:eclipse]]//+//Necessary knowledge:  
 +[HW] [[en:hardware:homelab:digi]], 
 +[ELC] [[en:electronics:voltage_divider]],  
 +[AVR] [[en:avr:adc]],  
 +[LIB] [[en:software:homelab:library:adc]], [LIB] [[en:software:homelab:library:module:lcd_graphic]],  
 +[LIB] [[en:software:homelab:library:module:sensor]]//
  
 ===== Theory ===== ===== Theory =====
Line 20: Line 25:
 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 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. 
  
-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 1m2. 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:   +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:   
  
  
Line 81: Line 86:
  
 <code c> <code c>
 +// HomeLab photoresistor demonstration
 +// LCD screen displays the approximate illuminance in lux
 #include <stdio.h> #include <stdio.h>
 #include <math.h> #include <math.h>
Line 96: Line 103:
  // Initializing the LCD  // Initializing the LCD
  lcd_gfx_init();  lcd_gfx_init();
 +
 +        // Setting LCD backlight to work
 +        lcd_gfx_backlight(true);
  
  // Clearing the LCD.  // Clearing the LCD.
  lcd_gfx_clear();  lcd_gfx_clear();
  
- //Cursor on the position x=3, y=1 + //Cursor on the position 
- lcd_gfx_goto_char_xy(3, 1);+ lcd_gfx_goto_char_xy(3, 2);
  
  // Name of the program  // Name of the program
Line 110: Line 120:
  
  // Endless loop.  // Endless loop.
- while (true)+ while (1)
  {  {
  // Reading the average value of the photoresistor  // Reading the average value of the photoresistor
- adc_value = adc_get_average_value(1, 10);+ adc_value = adc_get_average_value(13, 10); 
 + // HomeLab II 
 + //adc_value = adc_get_average_value(1, 10);
  
  // Calculating the voltage in the input of the ADC  // Calculating the voltage in the input of the ADC
- voltage = 5.0 * ((double)adc_value / 1024.0);+ // HomeLab II  
 + //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 
- // Calculating the intensity of light in lux+ resistance = (33.0) / voltage - 10.0; 
 +  
 + // Calculating the intensity of light in lux
  illuminance = 255.84 * pow(resistance, -10/9);  illuminance = 255.84 * pow(resistance, -10/9);
 + // Dividing variable into two integer variable
 + // to display it on the screen
 + int8_t illu = illuminance;
 +    int16_t illudp = trunc((illuminance - illu) * 1000);
  
- // Converting the intensity of light to text + // Converting the intensity of light to text  
- sprintf(text, "%0.1f lux   ", illuminance);+ sprintf(text, "%3u.%3u lux   ", illu,illudp); 
  
  // Displaying it on the LCD  // Displaying it on the LCD
en/examples/sensor/photoresistor.1447145517.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0