Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const long A = 1000; //Resistencia en oscuridad en KΩ
- const int B = 15; //Resistencia a la luz (10 Lux) en KΩ
- const int Rc = 10; //Resistencia calibracion en KΩ
- const int LDRPin = A0; //Pin del LDR
- int V;
- int ilum;
- void setup()
- {
- Serial.begin(115200);
- }
- void loop()
- {
- V = analogRead(LDRPin);
- //ilum = ((long)(1024-V)*A*10)/((long)B*Rc*V); //usar si LDR entre GND y A0
- ilum = ((long)V*A*10)/((long)B*Rc*(1024-V)); //usar si LDR entre A0 y Vcc (como en el esquema anterior)
- //Serial.println(ilum);
- if ( ilum <210 && ilum >185)
- {
- Serial.println("0%");
- }
- else if( ilum <185 && ilum >170)
- {
- Serial.println("20%");
- }
- else if( ilum <170 && ilum >150)
- {
- Serial.println("40%");
- }
- else if( ilum <150 && ilum >134)
- {
- Serial.println("60%");
- }
- else if( ilum <134 && ilum >99)
- {
- Serial.println("80%");
- }
- else if( ilum <98)
- {
- Serial.println("100%");
- }
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement