Pumpkin-Sky Lamp by Catalina Cortázar

Pumpkin-Sky Lamp

The concept is a lamp that interacts with the environment.

The lamp consists on a black-pumpkin, as night, which has blue LEDs and one RGB Led.
Every time the light of the room is turned off, when it becomes dark, the blue LEDs light up and there is one Led that is purple.

When the PIR motion sensor is activated, when someone is near the lamp, all of the LEDs become blue and they start blinking.

When the room light is turn on, and the room lights up, the lamp turns off.

CODE:

int timer = 500;
int sensorPin = A2;
int sensorValue = 0;
int pinArray [] = {
5, 6, 9, 10, 11};  //nombrando los pins que usaremos –  usando un array
int count = 0; //vamos a ir contando de 1 a 5, de acuerdo a las posicion de los led en el array, primero el 5, ultimo el 11
int timerKR = 200;

int photocellPin =A0;     // el photocell se conecta a A0
int photocellReading;
int LEDpin [] = {2, 3, 4};

// connect los que cambian de color
int LEDbrightness;
int LEDbrightnessR;
int LEDbrightnessG;
int LEDbrightnessB;

int counter = 0;

void setup () {
Serial.begin (9600);
for (count = 0; count< 5; count++) {
pinMode(pinArray[count], OUTPUT); //estamos declarando cada pin del array = count o sea, el pinArray = 5 es el count 0 como  output para que prendan la luz
}

for (counter = 0; counter< 3; counter++) {
pinMode(LEDpin[counter], OUTPUT);

}

pinMode(sensorPin, INPUT);
delay (2000); // se demora dos segundos en empezar

pinMode(photocellPin, INPUT);
delay (2000); //

}

void loop (){

photocellReading = analogRead(photocellPin);

photocellReading = 1023 – photocellReading;

LEDbrightnessR = map(photocellReading, 0, 1023, 0, 255);
LEDbrightnessG = map(photocellReading, 0, 1023, 0, 255);
LEDbrightnessB = map(photocellReading, 0, 1023, 0, 255);

sensorValue = analogRead(sensorPin);
Serial.println (sensorValue);

delay (10);

if( (LEDbrightnessR && LEDbrightnessG && LEDbrightnessB >200 )&& (sensorValue > 100) ){

for (count=0; count<5; count++) {

digitalWrite(pinArray[count],HIGH); //se van prendiendo hasta llegar al ultimo el numero 11
delay(timerKR);

}

analogWrite(4, LEDbrightnessR);
analogWrite(3, LEDbrightnessG);
analogWrite(2, LEDbrightnessB);

}

if ( (LEDbrightnessR && LEDbrightnessG && LEDbrightnessB >200 )&& (sensorValue < 100 )){

analogWrite(4,0);
analogWrite(3, 0 ); //0
analogWrite(2, 157); //157

delay(1000 );

analogWrite(4, LOW);
analogWrite(3, LOW);
analogWrite(2, LOW);
delay(100);

for (count=0; count<5; count++) {

digitalWrite(pinArray[count],HIGH); //se van prendiendo hasta llegar al ultimo el numero 11
delay(timerKR);
digitalWrite(pinArray[count+1],HIGH);
//digitalWrite(pinArray[count+2],HIGH);
delay(timerKR);
digitalWrite(pinArray[count],LOW);
delay(timerKR); //en el ejemplo multiplican el timer por dos para que se demore en empezar luego el otro sentido
}
for (count=5; count>=0; count–) {

digitalWrite(pinArray[count],HIGH); //se van prendiendo al revez desde el ultimo count 5 (pin11) hasta llegar al cero
delay(timerKR);

digitalWrite(pinArray[count-1],HIGH);
delay(timerKR);
digitalWrite(pinArray[count],LOW);
delay(timerKR);
}

}

delay(timer);

//fin sensor motion

if (LEDbrightnessR && LEDbrightnessG && LEDbrightnessB < 200){

analogWrite(4, LOW);
analogWrite(3,  LOW);
analogWrite(2,  LOW);

for (count=0; count<5; count++) {

digitalWrite(pinArray[count],LOW); //se van prendiendo hasta llegar al ultimo el numero 11
delay(timerKR);

}

//Serial.println(LEDbrightnessR);
//Serial.print(LEDbrightnessG);
//Serial.print(LEDbrightnessB);
delay(100);

}

}