Last active
May 6, 2018 13:01
-
-
Save jargnar/8c389961449244b172fc21ff77bf1aae to your computer and use it in GitHub Desktop.
Light it up - use photo resistor to light LED automatically in darkness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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