Saturday, January 19, 2013

Second Build - Arduino Uno Photocell LED Controller

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

1 comment:

  1. [...] 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