Purpose:
To make an LED change its brightness level according to how much light is hitting the light sensor
Equipment:
Light sensor
Equipment:
Light sensor
Led (any colour)
3 wires (any colour)
330 Ohm resistor
10k Ohm resistor
Program Details:
Arduino
Time to Program and Complete:
15 mins
Results:
We had no problems
Photo/Video Proof:
None right now
Program:
int lightPin = 0; -Creates a variable for lightPin to pin 0
int ledPin = 9; -Creates a variable for ledPin to pin 9
void setup() -Starting of the void setup()
{ -Start of void setup()
pinMode(ledPin, OUTPUT);- Tells if the ledPin is an Output or Input
} - End of void setup()
void loop() -Start of void loop()
{ -Start of void loop()
int lightLevel = analogRead(lightPin); -Creates a variable for lightLevel which stores value from the light sensor
lightLevel = map(lightLevel, 0, 900, 0, 255); -Converts lightLevel from 0-900 to 0-255
l = constrain(lightLevel, 0, 255); -Makes sures light level is from 0-255
analogWrite(ledPin, lightLevel); -ledPin is = to lightLevel
} -End of program
Program Modifications:
none
Helpful Tips:
Not really anything
References:
Aron Graca
Why no photo?
ReplyDelete