ezieragabriel / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

playground Learning PhotoResistor #1100

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. take the code from http://www.arduino.cc/playground/Learning/PhotoResistor
2. Put it in arduino
3. led didn't works

What is the expected output? What do you see instead?

Led 11 bright when we have light, but it didn't works

Please provide any additional information below.

The solution is change 

analogWrite(ledPin, analogRead(lightPin)/4);
to 
digitalWrite(ledPin, analogRead(lightPin)/4);

and better pin13 ;)

Original issue reported on code.google.com by igna...@turegano.it on 5 Nov 2012 at 10:47

GoogleCodeExporter commented 9 years ago
Which board are you using? 

Original comment by jaguar3s...@gmail.com on 6 Nov 2012 at 1:09

GoogleCodeExporter commented 9 years ago
DigitalWrite only makes the output fully HIGH or fully LOW. If you want the led 
to light up based on the amount of light the photoresistor is receiving, you 
need a pin with PWM and use analogWrite. Also instead of dividing the reading 
from the Photoresistor by 4, just MAP the values. 

analogWrite(ledpin, map(PRvalue, "lowest PR value" , "highest PR value", 0 
,255)); 

Original comment by mascoloa...@gmail.com on 8 Nov 2012 at 3:53

GoogleCodeExporter commented 9 years ago
 Digital pin 11 is a PWM pin. Changing it to digitalWrite will just turn the LED on all the time.

Original comment by s.fitzge...@arduino.cc on 2 Apr 2013 at 8:59