Advertisement
edofhell

Lys styring 0.73

Jun 12th, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. int LDR = 0; //analog pin to which LDR is connected, here we set it to 0 so it means A0
  2. int LDRValue = 0; //that’s a variable to store LDR values
  3. int light_sensitivity = 500; //This is the approx value of light surrounding your LDR
  4.  
  5. void setup()
  6. {
  7. Serial.begin(9600); //start the serial monitor with 9600 buad
  8. pinMode(13, OUTPUT); //we mostly use 13 because there is already a built in yellow LED in arduino which shows output when 13 pin is enabled
  9. }
  10.  
  11. void loop()
  12. {
  13. LDRValue = analogRead(LDR); //reads the ldr’s value through LDR
  14. Serial.println(LDRValue); //prints the LDR values to serial monitor
  15. delay(50); //This is the speed by which LDR sends value to arduino
  16.  
  17. if (LDRValue < light_sensitivity)
  18. {
  19. digitalWrite(13, HIGH);
  20. digitalWrite(9, HIGH); //Relæ 1
  21. }
  22.  
  23. else
  24.  
  25. {
  26. digitalWrite(13, LOW);
  27. digitalWrite(9, LOW); //Relæ 1
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement