Advertisement
franciscominajas

FOTOMETRO

Nov 24th, 2019
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const long A = 1000;     //Resistencia en oscuridad en KΩ
  2. const int B = 15;        //Resistencia a la luz (10 Lux) en KΩ
  3. const int Rc = 10;       //Resistencia calibracion en KΩ
  4. const int LDRPin = A0;   //Pin del LDR
  5.  
  6. int V;
  7. int ilum;
  8.  
  9. void setup()
  10. {
  11.    Serial.begin(115200);
  12. }
  13.  
  14. void loop()
  15. {
  16.    V = analogRead(LDRPin);        
  17.  
  18.    //ilum = ((long)(1024-V)*A*10)/((long)B*Rc*V);  //usar si LDR entre GND y A0
  19.    ilum = ((long)V*A*10)/((long)B*Rc*(1024-V));    //usar si LDR entre A0 y Vcc (como en el esquema anterior)
  20.  
  21.    //Serial.println(ilum);
  22.    if ( ilum <210 && ilum >185)
  23.    {
  24.       Serial.println("0%");  
  25.    }
  26.    else if( ilum <185 && ilum >170)
  27.    {
  28.       Serial.println("20%");
  29.    }
  30.    else if( ilum <170 && ilum >150)
  31.    {
  32.       Serial.println("40%");
  33.    }
  34.    else if( ilum <150 && ilum >134)
  35.    {
  36.       Serial.println("60%");
  37.    }
  38.    else if( ilum <134 && ilum >99)
  39.    {
  40.       Serial.println("80%");
  41.    }
  42.    else if( ilum <98)
  43.    {
  44.       Serial.println("100%");
  45.    }
  46.    delay(1000);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement