Night Lamp

Smart Night Lamp

Smart Night Lamp

Hardware

Arduino
Jumper wires
Breadboard

Components
1 – Bright RGB Cathode LED
1 – Photo Resistor
2 – 220 Ohm Resistors
1 – 330 Ohm Resistor
1 – 10K Ohm Resistor

Price of components is 100npr

Circuit diagram

Night Lamp
Night Lamp

Arduino Code

int photoSensorPin = A0;
int redLedPin = 3;
int greenLedPin = 5;
int blueLedPin = 6;
int redLedVal = 0;
int greenLedVal = 0;
int blueLedVal = 0;
boolean isLedOn = false;

int brightness = 1023;
int darkThreshold = 50;
int changeColorTime = 900000;

long lastUpdate=0;

void setup()
{
randomSeed(analogRead(1));
}

void loop()
{
getBrightness();
if (brightnesslastUpdate+changeColorTime)
{
LedOn();
isLedOn = true;
lastUpdate = millis();
}
}
else {
LedOff();
isLedOn = false;
}

delay(1000);
}

int getBrightness()
{
brightness = analogRead(photoSensorPin);
return brightness;
}

void LedOn()
{
redLedVal = random(1,128);
greenLedVal = random(1,128);
blueLedVal = random(1,128);

analogWrite(redLedPin,redLedVal);
analogWrite(greenLedPin,greenLedVal);
analogWrite(blueLedPin,blueLedVal);
}

void LedOff(){

analogWrite(redLedPin,0);
analogWrite(greenLedPin,0);
analogWrite(blueLedPin,0);
}