Skip to content

Instantly share code, notes, and snippets.

@jargnar
Last active May 6, 2018 13:01
Show Gist options
  • Save jargnar/8c389961449244b172fc21ff77bf1aae to your computer and use it in GitHub Desktop.
Save jargnar/8c389961449244b172fc21ff77bf1aae to your computer and use it in GitHub Desktop.
Light it up - use photo resistor to light LED automatically in darkness
#define LED 8
#define PHOTORESISTOR A0
#define THRESHOLD 200
void setup()
{
Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(PHOTORESISTOR, INPUT_PULLUP);
Serial.println("Hello, Arduino");
}
void loop()
{
int darkness = analogRead(PHOTORESISTOR);
if (darkness > THRESHOLD) {
digitalWrite(LED, HIGH);
delay(20);
digitalWrite(LED, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment