Hate waking up in the dark? Me too.  I found a cheap 24 LED lamp and thought it would be fairly easy to make it turn on slowly using my Arduino, which should help banish some of those "waking up in the dark" winter blues.

You'll need:
- a "camping" LED lamp- I used one like this one
- an Arduino or other programmable microcontroller
- a timeswitch
- a "wall-wart" power supply
- transistors capable of switching about 500mA

Step 1: Pulse Width What Now?

A little background:

LEDs aren't like incandescent lightbulbs in the way they dim.  If you supply an incandescent lightbulb with a reduced voltage, it doesn't put out as much light.  LEDs don't work quite like this, and tend to turn on suddenly with a small increase in voltage.  The usual way of dimming LEDs is to turn them on and off very quickly- this is known as pulse-width modulation (PWM), because by varying the amount of time the LED is switched on (the pulse width) you can control precisely how bright it appears.

All we need to do is write a simple program that will turn on the LEDs dimly at first, with short pulses separated by longer periods of being switched off, and gradually increase the length of each pulse so making the LEDs appear brighter.

This gets a little bit more complicated when you involve the human eye.  It turns out, if you halve the amount of light an LED is actually producing, it appears more than half as bright.  The human eye perceives a very small difference in low light levels as significant, but doesn't notice small differences between higher light levels.  This means if we were to brighten the LEDs uniformly (starting at 10% brightness, then 20%, then 30% and so on) to a human observer it looks like it gets brighter very quickly at first, then slowly increases through higher levels of brightness.  To compensate for this we need to switch the LEDs on more slowly at first, then accelerate through higher light levels.

If that all sounds overly complicated to just turn some lights on, don't worry- I've done the maths so you don't have to!
<p>it's another interesting project to consider! Usually LED bulbs are powered via a driver but here in the schema I see no any driver and all bulbs in the lamp are connected to the transistors directly... How did the lamp operate before yours modernization? What kind of LED bulbs are supported?</p>
<p>Is there a line of code that can be added to stop the &quot;pulsepin&quot; going &quot;HIGH&quot; at power up?</p><p>When I power up the Arduino the LED flashes at full strength before starting the ramp up.</p><p>Kind of ruins the point of the project.</p>
Can you use analogWrite to adjust the brightness levels instead? Would the flickering be less noticeable? Here's a sketch without using delay. You can add other features to the lamp. I'm working on a sunrise simulator.
Wow! I am impressed!<br><br>I am working on a prototype that consists in a sensor (I don't know yet what sensor, maybe pressure sensor or light sensor) that switches on a set of LEDs that gradually light up (during 6 min more or less). At the end, there is a second sensor to switch off the light when wanted. <br><br>I am familiar with Arduino and I am able to understand more or less the easy code but I am not able to write it. So your code is exactly what I was looking for, thanks so much!<br><br>But I have some questions on how to addapt it:<br><br>- Which value should I write at the sunrisespeed to increase the time to 6 minutes? I messed up the maths...<br><br>and<br><br>- How do I mention the sensors to switch on and off the light at the code?<br><br><br>If you could respond in a short time I would really appreciate it!<br>Thanks a lot for your help!
Making it switch on over a different time period is easy. It spends (0.005 * sunrisespeed) seconds at each brightness level, so (0.3 * sunrisespeed) seconds over the whole sequence. If you want this to take 6 minutes, that would be 360 seconds, and 360/0.3 is 1200.<br> <br> (A simpler way to work this out is that I want mine to take 25 minutes and have sunrisespeed at 5000. 6 minutes is about a quarter of 25, so we want a quarter of 5000, or 1250.)<br> <br> Making it respond to buttons is a bit more involved: you have to make the Arduino code check the values of input pins and start or stop the loop according to their values. How to do that depends on the switch or sensor you are using- if you already have an Arduino and the sensors you want to use I suggest finding a tutorial on using that type of button as an input and writing some examples.
Thank you PKM!<br>I think I will manage with that!
Hi...this works perfectly but I want the light to stay on full brightness at the end of the lookup table...I was good with BASIC but not sure how to add this to the ardunio code...any ideas please...Gerry
You could make it stay on indefinitely after turning on by replacing the loop function with<br> <pre> void loop() { for (i=0; i&lt;steps; i++) { duty = lookup[i] * 5; for (j=0; j&lt;sunrisespeed; j++) { // one pulse of PWM digitalWrite(pulsepin, HIGH); delayMicroseconds(duty); digitalWrite(pulsepin, LOW); delayMicroseconds(5000-duty); } } digitalWrite(pulsepin, HIGH); while (1==1) { } } </pre> This means it will run through the fade-on sequence and then stay on forever, or until you turn the Arduino off.
That's great!! I was looking at 'if then else' statements but the answer is so much simpler!! <br> <br>As I want to build this as a permanent (winter) addition to our bedroom, and as I would prefer not to tie up my Arduino board, would it be possible to use this code on a little 8 pin Pic? I have a pic programmer but, as with the Arduino code, I struggle with the syntax for the language. <br> <br>I am very impressed with the code...it seems very compact yet the 64 levels of brightness work perfectly...thank you for posting it. <br> <br>cheers Gerry
Hi Gerry,<br> <br> Hardware-wise, this should be no problem. It's a very small program that I'd guess will fit on all but the smallest of microcontrollers. I'm not used to programming with PICs, but it seems you can write code for them in C so this program will probably work with only minor alterations. I don't know what facilities they have for timing delays, though, and I don't have access to a PIC programmer to experiment with so I'm afraid I can't help you with the specifics of the code.
No probs...I need to learn anyway!!!! I'm pretty sure they have internal crystals so the delay should not be a problem....beauty is, it costs nothing to try :-)) <br> <br>Thank you again for your quick replies.....Gerry.
Awesome project! I would love to do this project! However, I am very unfamiliar with Ardiuno. It is hard to tell the difficulty scale of this project. How long did this take you to do? Also, do you have more pictures of the final product?
I don't have any more pictures of the finished product, but it's not that pretty!<br><br>This project took me a while to do, mostly because I was experimenting while I did it to try to minimise flicker and provide the smoothest possible transition. All you have to do is copy and paste my code, maybe change the value of sunrisespeed if you want it to be faster or slower, and build the circuit. <br><br>I don't know how long that will take, but it's a fairly simple design so it should be quick once you have all the parts. Actually wiring everything up should only take you a few minutes if you have built circuits before, and once you know your way around the Arduino software then adding the code should be very quick too.

About This Instructable




More by PKM:Dining Chair From a 2x4 Word art trivet Sugru lens cap saver 
Add instructable to: