ArduinoArduino UnoExact chip

Night light

A photoresistor on A0: the darker it is, the brighter the LED.

Night light in Argynix Lab

The code

sketch.inoC++
// A photoresistor module on A0: it reads higher in the dark.
// The LED on pin 9 is brighter the darker it gets. Select the sensor to set the light.

void setup() {
  pinMode(9, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int raw = analogRead(A0);
  analogWrite(9, map(raw, 0, 1023, 0, 255));
  Serial.print("darkness:");
  Serial.println(raw);
  delay(100);
}