Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------
- // Photoresistors for beginners
- // learnelectronics
- // 17 Feb 2019
- // www.youtube.com/c/learnelectronics
- //---------------------------------------------
- // Average light = 390
- //dark = 905
- //light = 90
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600);
- pinMode(3,OUTPUT);
- pinMode(A0,INPUT);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- int lightRead = (analogRead(A0));
- int ledOutput = map(lightRead, 1, 1023, 0, 254);
- if (ledOutput < 95)
- {
- ledOutput = 0;
- }
- Serial.println(ledOutput);
- analogWrite(3,ledOutput);
- delay(50);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement