This is a Arduino controlled night light.


1 x LED
5 x jumper wires
1 x arduino
1 x photocell
1 x breadboard
1 x 10k ohm resistor

Here is the code, don't type the stuff after the //, the code will get too long:

// These constants won't change:
const int sensorPin = A0;    // pin that the sensor is attached to
const int ledPin = 9;        // pin that the LED is attached to

// variables:
int sensorValue = 0;         // the sensor value
int sensorMin = 1023;        // minimum sensor value
int sensorMax = 0;           // maximum sensor value

void setup() {
  // turn on LED to signal the start of the calibration period:
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);

  // calibrate during the first five seconds
  while (millis() < 5000) {
    sensorValue = analogRead(sensorPin);

    // record the maximum sensor value
    if (sensorValue > sensorMax) {
      sensorMax = sensorValue;

    // record the minimum sensor value
    if (sensorValue < sensorMin) {
      sensorMin = sensorValue;

  // signal the end of the calibration period
  digitalWrite(13, LOW);

void loop() {
  // read the sensor:
  sensorValue = analogRead(sensorPin);

  // apply the calibration to the sensor reading
  sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);

  // in case the sensor value is outside the range seen during calibration
  sensorValue = constrain(sensorValue, 0, 255);

  // fade the LED using the calibrated value:
  analogWrite(ledPin, sensorValue);
<p>Thank you so much, it helped me a lot!</p>
<p>You're welcome!</p>
<p>Do you mind sharing your circuit diagram too?</p>
<p>I have not made one yet.</p><p>But thanks for asking, and vote for it (the project) on the sensor contest!!</p>

About This Instructable




More by origamiAirControl:how to draw a bird Nutball glider Arduino radar 
Add instructable to: