elrincondearni

LDR Arduino

Oct 30th, 2014
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1.  
  2. #include <LiquidCrystal.h>
  3.  
  4.  
  5. LiquidCrystal lcd(12, 11, 8, 7, 6, 5);
  6. int ldr = 5;
  7. int valor;
  8. int led=9;
  9.  
  10. void setup() {
  11.   pinMode(ldr, INPUT);
  12.   lcd.begin(16,2);
  13.   Serial.begin(9600);
  14. }
  15.  
  16. void loop() {
  17.   lcd.setCursor(0, 0);
  18.   valor=analogRead(ldr);
  19.   if (valor>200){
  20.     lcd.write("Hay luz, led off");
  21.     analogWrite(led, 0);
  22.   }
  23.   if (valor<=200 && valor>=60){
  24.     lcd.write("Sombra, led 50%");
  25.     analogWrite(led, 123);
  26.   }
  27.   if (valor<60) {
  28.     lcd.write("No luz, led 100%");
  29.     analogWrite(led, 255);
  30.   }
  31.   delay(20);
  32.   lcd.clear();  
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment