Created
January 29, 2017 20:11
-
-
Save agocs/2d9d92010934f1f9e56ac5755fa9de70 to your computer and use it in GitHub Desktop.
Arduino powered nightlight
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
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(9600); // Here, we're initializing communication from the arduino back to the computer | |
pinMode(3,OUTPUT); // Here, we're setting pin D3 as an output pin. | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
int sensorValue = analogRead(A2); // Reading the photosensor | |
Serial.println(sensorValue); // sending that value back to the computer just so we know | |
if (sensorValue < 500){ // if the sensor is seeing less than 500 units of light... | |
// we determined that 500 was roughly the threshold between bright and dark | |
digitalWrite(3, HIGH); // turn the light on | |
}else { // otherwise... | |
digitalWrite(3, LOW); // turn the light off | |
} | |
delay(500); // wait half a second and begin again. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment