Advertisement
learnelectronics

Photoresistors for Beginners

Mar 1st, 2019
1,160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. //---------------------------------------------
  2. //       Photoresistors for beginners
  3. //              learnelectronics
  4. //               17 Feb 2019
  5. //      www.youtube.com/c/learnelectronics
  6. //            [email protected]
  7. //---------------------------------------------
  8.  
  9.  
  10. // Average light = 390
  11. //dark = 905
  12. //light = 90
  13.  
  14. void setup() {
  15.   // put your setup code here, to run once:
  16.  
  17.   Serial.begin(9600);
  18.   pinMode(3,OUTPUT);
  19.   pinMode(A0,INPUT);
  20.  
  21. }
  22.  
  23. void loop() {
  24.   // put your main code here, to run repeatedly:
  25.  
  26.   int lightRead = (analogRead(A0));
  27.   int ledOutput = map(lightRead, 1, 1023, 0, 254);
  28.   if (ledOutput < 95)
  29. {
  30.   ledOutput = 0;
  31. }
  32.   Serial.println(ledOutput);
  33.   analogWrite(3,ledOutput);
  34.   delay(50);
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement