Introduction: Bounce Effect Night Lamp

This effect can be explained as follows:
An array of 6 leds is arranged. The blinking starts from both the end, i.e.,0 and the 5th led and will continue till the 2nd and the3rd led respectively. Then the blinking will start in the backward direction, i.e., from the 2nd to 0 and 3rd to the 5th. This process will continue as long as the lights are off.

LDR(Light Dependent Resistance) is used to control the blinking of leds.

Step 1: Components Required:

1. Arduino Uno board (You may use any other also)

2. Leds x 6

3. Light Dependent Resistance(LDR)

4. Breadboard

5. Jumper wires

6. Resistors (1k)

7. USB cable

Step 2: Code

// Create array for LED pins
byte ledPin[]={4, 5, 6, 7, 8, 9};

int delayLed(50); //Delay between changes

int currentLed1=0;

int currentLed2=5;

int direction1=1;

int direction2=-1;

int sensePin=A0;

unsigned long changeTime;

void setup()

{ // put your setup code here, to run once:

for(int i=0, j=5;i<3 && j>2;i++, j--) //set all pins to output

{ pinMode(ledPin[i], OUTPUT);

pinMode(ledPin[j], OUTPUT); }

changeTime=millis();

}

void loop()

{ // put your main code here, to run repeatedly:

int val=analogRead(sensePin); //read the value of the LDR

if(val>1000) //setting condition for LDR

{ if((millis()-changeTime)> delayLed) //if it has been delayLed ms since last change

{

for(int i=0, j=5;i<6 && j>2; i++, j--) //turn of all LEDs

{

digitalWrite(ledPin[i], LOW);

digitalWrite(ledPin[j], LOW);

}

digitalWrite(ledPin[currentLed1], HIGH); //turn on the current LED

digitalWrite(ledPin[currentLed2], HIGH);

currentLed1+=direction1; //increment by the direction value

currentLed2+=direction2;

if (currentLed1==0) //to change the direction if we reach the end

{

direction1=1;

}

if(currentLed2==5 )

{

direction2=-1;

}

if(currentLed1==2)

{

direction1=-1;

}

if(currentLed2==3)

{

direction2=1;

}

changeTime=millis();

}

}

else

{

for(int i=0; i<6;i++)

{

digitalWrite(ledPin[i], LOW);

}

}

}

Step 3: Connections:

The connections for the night lamp are quite simple. Make sure you connect the leds to the correct Arduino pins.

Step 4: Run the Code

Now you have your own 'bounce effect' night lamp. You can modify as per requirements :)

Comments

author
vasu_dev (author)2016-06-13

Great work!!!

author
DIY Hacks and How Tos (author)2016-01-16

Fun lighting project.

About This Instructable

280views

6favorites

License:

More by shubaangi_95:Remote Controlled Robot Using Arduino Ultrasonic Range Finder Using ArduinoStone Paper Scissors
Add instructable to: