
Download Arduino IDE and continue with the setup.


// Blink - pin 13 again, but on the Nano the LED sits right next to the
// "L" silkscreen on the board.
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}// nightlight.ino - an LDR on A6 turns the LED on when the room goes dark.
//
// A6 and A7 exist on the Nano and not on the Uno. They are analogue INPUT
// ONLY: digitalRead, digitalWrite and pinMode do nothing on them. Reading
// them with analogRead is the only thing they do, and that is all we need.
//
// Wiring: 5V -> LDR -> A6, and A6 -> 10k resistor -> GND.
// (a voltage divider: the junction is what A6 measures)
// LED on pin 9 -> 330 ohm resistor -> GND, as usual.
const int LDR_PIN = A6;
const int LED_PIN = 9;
const int DARK_THRESHOLD = 400; // tune this to your room, see below
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
int light = analogRead(LDR_PIN); // 0 = dark, 1023 = bright
Serial.println(light);
if (light < DARK_THRESHOLD) {
digitalWrite(LED_PIN, HIGH);
} else {
digitalWrite(LED_PIN, LOW);
}
delay(100);
}