Week 4: Do Somehing With An Arduino
For Week 4, my main goal was to start and finish a project in the alotted time, since I had over-ambitious ideas for Weeks 2 and 3 and then ran out of time to complete them. I decided to build a simple circuit with a LED that turns on when it gets dark. I always forget to turn on my lights when it starts get darker in the afternoon and then I spend a considerable amount of time ruining my vision, so this mechanism would be very useful to me.
Model of circuit
Code snipet
const int LIGHT_SENSOR = D0;
const int LED = D7;
int analogValue;
void setup()
{
Serial.begin(115200);
pinMode(LED, OUTPUT);
pinMode(LIGHT_SENSOR, INPUT);
}
void loop()
{
analogValue = analogRead(LIGHT_SENSOR);
if(analogValue < 2000)
digitalWrite(LED, HIGH); // LED on
else
digitalWrite(LED, LOW); // LED off
Serial.println(analogValue);
}