Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. int Pr = 0; // will be used for analog 0.
  2. int PrValue = 0; // value of output
  3. int Pr_Input = 100; // value of when light is on
  4. int Y = 0; // map PrValue into light value
  5.  
  6. void setup() {
  7. Serial.begin(9600); //start serial Monitor
  8. pinMode(3, OUTPUT); // pin 3 as output
  9. }
  10.  
  11. void loop() {
  12. PrValue = analogRead(Pr);
  13. Serial.println(PrValue); //prints photoresistor value
  14. delay(100); // value updated every 0.1 second.
  15.  
  16. if (PrValue < Pr_Input) { // if sensor value is less than xx, light will turn on.
  17. Y = map(PrValue, 0, 300, 255, 0);
  18. analogWrite(3, Y);//LED on
  19. delay(15);
  20. }
  21. else {
  22. analogWrite(3, LOW); // LED off
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement