Smart Night Lamp

Hello All,

I was hoping for some advice on making a photoresistor rgb led project. I do not know how which resistors to use and the current rgb led coding doesn’t work. Need HELP! :confused:

Need DETAILS

I was hoping to use this i found http://runtimeprojects.com/2016/05/a-smart-night-lamp-for-kids/ (Thank you to the creator) but to put it onto the sparkfun red board and half bread board. I’ve tried putting it on and using the code but it doesn’t work. >:(

(deleted)

but it doesn't work.

What does it do?
Just rely on benefits?

I was hoping to use his schematics for final project, the only thing I did was tried to use 330 resistor instead of 220. I changed the interval of lightning change, because his schematics was for a nightlamp.

(deleted)

Uh do you want me to take a picture of it? and the code?

const int photoSensorPin = A0;
const int redPin = 11;
const int greenPin = 10;
const int bluePin = 9;
int redLedVal = 255
int greenLedVal = 0;
int blueLedVal = 0;
boolean isLedOn = true;

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

long lastUpdate=0;
void setup()
{
randomSeed(analogRead(1));
setColourRgb(0,0,0);
}

void loop()
{
getBrightness();
if (brightness<darkThreshold){ if (!isLedOn) { LedOn(); isLedOn = true; lastUpdate = millis(); } else if (millis()>lastUpdate+changeColorTime)
{
LedOn();
isLedOn = true;
lastUpdate = millis();
unsigned int rgbColour[3];
}
}
else {
LedOff();
isLedOn = true;
}

delay(6000);
}

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);

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

// Start off with red.
rgbColour[0] = 255;
rgbColour[1] = 0;
rgbColour[2] = 0;

// Choose the colours to increment and decrement.
for (int decColour = 0; decColour < 3; decColour += 1) {
int incColour = decColour == 2 ? 0 : decColour + 1;

// cross-fade the two colours.
for(int i = 0; i < 255; i += 1) {
rgbColour[decColour] -= 1;
rgbColour[incColour] += 1;

setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);
delay(6000);
}
}
}

void setColourRgb(unsigned int red, unsigned int green, unsigned int blue) {
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}

I don’t know if this is correct or not. :o

https://circuits.io/circuits/4435466-the-unnamed-circuit/edit#breadboard heres the link to my schematic i couldn't find a red board, so I umprovised.

(deleted)

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Try this code, it just makes the LEDs flash ON 1Sec, OFF 1Sec.

int pwm1 = 3;
int pwm2 = 5;
int pwm3 = 6;

void setup() {
  // setup output pins
  pinMode(pwm1, OUTPUT);
  pinMode(pwm2, OUTPUT);
  pinMode(pwm3, OUTPUT);

}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(pwm1, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(pwm2, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(pwm3, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(pwm1, LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(pwm2, LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(pwm3, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

Thanks.. Tom.. :slight_smile:
PS. The code you posted does not compile, ; missing for a start.

Hi,
OPs circuit.3960e6e8f0092cc90d92fe7f74ba93bfbc31d11a.png
You circuit shows pins 3,5 and 6 as output to the LEDs.
YOUR code uses 9, 10 and 11.

The image of the protoboard you linked shows 9,10 and 11.

My code uses 3,5 and 6.

Which pins are your LEDs connected too?

Thanks… Tom… :slight_smile: