Advertisement
makispaiktis

ArduinoBasics - 5. Photoresistor controlling LED light

Mar 21st, 2021 (edited)
909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int light;
  2. int ledPin = 11;
  3.  
  4. void setup()
  5. {
  6.   Serial.begin(9600);
  7.   pinMode(A0, INPUT);
  8.   pinMode(ledPin, OUTPUT);
  9. }
  10.  
  11. void loop()
  12. {
  13.   light = analogRead(A0);
  14.   Serial.print("Light is = ");
  15.   Serial.println(light);
  16.   // Light can take values from 54 to 974
  17.   light = map(light, 0, 1023, 0, 255);
  18.   Serial.print("Regularised light is = ");
  19.   Serial.println(light);
  20.   analogWrite(ledPin, light);
  21.   delay(200);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement