Nightlinght

I'm sure others have done this, but I made a night light with a photo resistor and some nice white LEDs that I have. It works pretty well. Here is the code and a short video of it.

int lightPin = 0; //Photo resistor analog read pin
int ledPin1 = 13;   //the pins the LEDs are connected to
int ledPin2 = 12;
int ledPin3 = 11;
int ledPin4 = 10;
int ledPin5 = 9;
int ledPin6 = 8;
int ledPin7 = 7;
int ledPin8 = 6;
int ledPin9 = 5;
int ledPin10 = 4;
  
void setup()
{
  pinMode(ledPin1, OUTPUT); //sets the led pin to outputs
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin8, OUTPUT);
  pinMode(ledPin9, OUTPUT);
  pinMode(ledPin10, OUTPUT);
  
Serial.begin(9600); //Sets the baud rate for the serial read
}
 
void loop()
{
 int lightLevel = analogRead(lightPin); //Read the light pin
                                       
 Serial.println(lightLevel); delay(1000);//print light pin and delay time


  if(analogRead(lightPin) < 650){ //if light pin is above 650 lights off
    digitalWrite(ledPin1, HIGH); //note that you can adjust the value 
    digitalWrite(ledPin2, HIGH);// so that it fits your needs
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin4, HIGH);
    digitalWrite(ledPin5, HIGH);
    digitalWrite(ledPin6, HIGH);
    digitalWrite(ledPin7, HIGH);
    digitalWrite(ledPin8, HIGH);
    digitalWrite(ledPin9, HIGH);
    digitalWrite(ledPin10, HIGH);
  }else{ //otherwise 
    digitalWrite(ledPin1, LOW); 
    digitalWrite(ledPin2, LOW);
   digitalWrite(ledPin3, LOW);
  digitalWrite(ledPin4, LOW);
 digitalWrite(ledPin5, LOW);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPin7, LOW);
digitalWrite(ledPin8, LOW);
digitalWrite(ledPin9, LOW);
digitalWrite(ledPin10, LOW);

  } 
}

Nice!

Now, you should be able to take what you've made and apply PWM to make an ambient light sensor. The darker it gets, the brighter the light. You might not be able to use as many LEDs since there are 6 PWM channels - but there are of course, ways around this problem.

Nice work!

Thanks. I'm petty new to all of this so I'm trying to start out slowly. I would like to keep expanding the project though. I'm thinking a push button may be the next thing to implement.

I built a "smart" night light with an ATtiny85 and a motion sensor hacked from an air freshener. It is normally PWM LED at a dim level. If it "sees" you, it goes full bright. After 30 seconds of not "seeing" anyone, it goes to a dim level again.

flyboy:
I built a "smart" night light with an ATtiny85 and a motion sensor hacked from an air freshener. It is normally PWM LED at a dim level. If it "sees" you, it goes full bright. After 30 seconds of not "seeing" anyone, it goes to a dim level again.

That's a cool idea too. I need to get a bunch of bread boards so I can make these little projects and set them aside for later rather than pulling them apart each time.