Advertisement
inagantid20

Exploring Photo Resistors Activity

Jun 15th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. /*
  2. *Divya Inaganti
  3. *June 14, 2017
  4. *How to use a photo resistor activity
  5. */
  6. const int photoPin= A0 ;
  7. int photoValue = 0;
  8. int lightVal= 0;
  9. void setup()
  10. {
  11. Serial.begin (9600);
  12. pinMode(photoPin, INPUT);
  13. }
  14. void loop()
  15. {
  16. photoValue= analogRead (photoPin);
  17. lightVal= map(photoValue, 0, 1020, 255, 0);
  18. lightVal= constrain(lightVal, 0, 255);
  19. Serial.print ("Photoresistor value = ");
  20. Serial.print(photoValue);
  21. Serial.print ("lightVal = ");
  22. Serial.println(lightVal);
  23. delay(100);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement