Saturday, January 19, 2013
Second Build - Arduino Uno Photocell LED Controller
Here's the Arduino code to control this, I'm using A0 for the photocell and the LED requires a PWM pin for this application so I used ~11. The photocell detects if the light source drops below a certain level and turns on the LED if so.
[sourcecode language="java"]
int ledPin = 11;
int pcPin = 0;
int pcIn;
void setup(void) {
Serial.begin(9600);
}
void loop(void) {
pcIn = analogRead(pcPin);
Serial.print("Analog reading = ");
Serial.println(pcIn);
pcIn = 1023 - pcIn;
if (pcIn > 400) analogWrite(ledPin, 255);
else analogWrite(ledPin, 0);
delay(100);
}
[/sourcecode]
Here's some video footage of it in action:
http://www.youtube.com/watch?v=55GxkP6wnqM
Labels:
Arduino,
Arduino Uno,
Code,
Hardware,
Hardware Hacking,
Pics
Subscribe to:
Post Comments (Atom)
[...] Here's the Arduino code to control this, I'm using A0 for the photocell and the LED requires a PWM pin for this application so I used ~11. The photocell detects if the light source drops below a ce... [...]
ReplyDelete