Introduction: Shape Casting Arduino Night Light!

About: Hi my name is Alex and I love creating stuff. I dabble in a bit of html coding, writing, and programing and I'm alwase finding new things I love. Also I'm a 17 year old Jesus freak that has a crazy life (I mov…

Want to make an easy night light for your kid or just for fun, well then your in the right place. All that you need to make this creation is the arduino uno beginners kit, up to 15 minutes and some paper and tape. But if you want to get creative you'll need a pencil and a bit of artist skills. If you want to see this night light in action just look at the video above and if your worried about the blue light keeping your kid up don't worry. You can simply replace the blue and white LED's with a yellow and a green one for a much darker lamp. Now I know theirs a lot of other night lights out there so you may be wondering why choose mine? Well I haven't examined the competition (partially so I wouldn't subconsciously steal someone else's idea) but I bet this is one of the easiest night lights for you to replicate. Basically all you need to do is place 6 components and 4 wires on a bread board, cut and tape some paper and copy and paste the code. So if your looking for a fast and easy night light this is your instructable. However if you got some time on your hands and you want to make it look good you can dive int some art work on your lamp shade like I did and make it look awesome. It glows really nicely and casts a shape ( in this case a butterfly ) onto the roof. Now the reason I made this night light was for my little sister (not to mention the programing challenge I got to tackle). But ,as every older brother should know, a little sisters interest's are blown by the wind and when I finished making it , guess what, she didn't want it. So the lesson I learned is: make sure you have fun making whatever you make.(just incase your sister doesn't want it any more) Anyway I hope who ever your making this for isn't so fickle. Now all that being said I think we need to get started!

What You Will Need

Materials:

1. A arduino Uno,and the usb that connects it to your computer

2. 3 LED's, a red one, a white one, and a blue one (or a red one, a green one, and a yellow one if you want a darker light.)

3. 3 220 ohm resistors

4. Some wire

5. (optional) a bread board

6. 2 pieces of printer paper, and some scotch tape( and a pencil if you want to make your lamp prettier )

7. an AC to DC 5 volt converter with usb input ( a phone charger converter that you can plug a usb into)

Tools:

1. The software required to make some code

2. scissors

Step 1: The Circuitry

The circuitry in this project is super simple. First plug in the power buses (the long strips labeled + and - on your bread board). Next you need to connect the anode of the white LED (the longer leg) to digital pin 11 using a wire and the cathode (the shorter leg) to ground ( -) via a 220 ohm resistor. Do the same thing for the blue and red LED's except attach the anode to the 10th and 9th digital pins. Last, put one end of a wire into digital pin 12 and the other end into the reset pin (this is the yellow wire in the picture). Note: you have to remove the end of the yellow wire from the reset button when uploading. Just like that your done with the circuitry! To power you nightlight use a phone charger block like the one pictured above, and plug the usb cord that connects your arduino to your computer into to it and the block into the outlet.

Step 2: The Shade

To make the nightlight shade follow the pictures form start to finish or you can read along and I will walk you threw it. If you want a fast and easy shade just do steps 1 threw 4 and don't draw on the paper. But if you want it to really look good follow all the steps. Start by getting 2 pieces of paper and citing one in half. Then tape that half to a full sheet of paper. Do some sketches, whatever you think looks good and tape the two remaining ends of the paper together making a cylinder. Now take the other half you didn't use and cut it into a square. Round out the edges and draw the outline of the object you to be cast onto the roof. Cut out the object and put the paper on top of your cylinder. Lastly cut a small hole at the bottom of your cylinder for the chord to go threw. Great, your done with your shade!

Step 3: The Code

Now there are two ways to do this, if you're in a rush or just don't care, you can copy and paste the code below. (Please note, in order to upload this sketch you must remove the wire from the reset pin. After the sketch has uploaded put the wire back in place and nothing else needs to be done.) However if you don't fall into one of those categories stick around and I'll explain whats going on in the code.

const int reset = 12;

const int white = 11;

const int blue = 10;

const int red = 9;

int brightness = 0;

int fadeAmount = 10;

int brightness2 = 0;

int fadeAmount2 = 10;

int brightness3 = 0;

int fadeAmount3 = 10;

void setup() {

digitalWrite(reset,HIGH);

pinMode(white, OUTPUT);

pinMode(blue, OUTPUT);

pinMode(red, OUTPUT);

pinMode(reset, OUTPUT); }

void loop() {

while(millis () < 3000){

brightness = brightness + fadeAmount;

analogWrite(white, brightness);

delay (30);

if (brightness == 250)

fadeAmount = -fadeAmount;

delay(30);

if (brightness == 0)

fadeAmount = -fadeAmount;}

while(millis () > 3000 && millis ()< 6000){

brightness2 = brightness2 + fadeAmount2;

analogWrite(blue,brightness2);

delay(30);

if(brightness2 == 250)

fadeAmount2 = -fadeAmount2;

delay(30);

if (brightness2 == 0)

fadeAmount2 = -fadeAmount2;}

while(millis () > 6001 ){

digitalWrite(reset,LOW);}

while(millis () > 6000 && millis ()< 9000){

brightness3 = brightness3 + fadeAmount3;

analogWrite(red,brightness3);

delay(30);

if(brightness3 == 250)

fadeAmount3 = -fadeAmount3;

delay(30);

if (brightness3 == 0)

fadeAmount3 = -fadeAmount3;}

}

Now I'll explain what's happening chronologically. First we're developing four constant variables to represent our pins. This isn't nessesary but it can be helpful. Next we make 6 integer variables that will allow the LED's to brighten and dim in the future. The first thing we do in our set up is make our reset pin read HIGH (have voltage on it). We do this because when reset pin reads LOW it resets the arduino and when the arduino initially starts it makes all pins read LOW (have no voltage). This would put us in a never ending cycle of the arduino reseting itself over and over and we could never get anything done. (I figured this out because of this: https://www.instructables.com/id/two-ways-to-reset... I give gabriellalevine the credit for helping me fix that problem.) Now you tell all the digital pins you're using to put out voltage instead of reading if voltage is present and you move on to your loop. The first thing you do in the loop is tell it to run the following code only while the arduio has been on for less than 3 seconds. This makes sure all of your LED's don't run at once and only the white one runs until 3 seconds has passed. The next bit of code I got from this: https://www.instructables.com/id/How-to-Fade-an-LED-Arduino-Tutorial/ instructable and I want to give a shout out to codebender_cc because his instructable was the foundation for my night light. What happens here is every time the arduino runs through the loop brightness gets fadeAmount (in this case 10) added to it. This means every time the loop is run brightness gets bigger and because we are telling the arduno in the next line of code to use the variable brightness as the amount of light the LED is to emit we're making sure that every time the loop is run the LED gets brighter. This creates that brightening effect but what about when the LED is as bright as it can be? (The LED can actually get a little brighter as the highest value is 255 not 250 but 250 is much easer to cut into bite sized sections). This is when we implement some code that makes the fadeAmount negative when the LED is at its brightest. This makes the brightness get smaller and thus the LED gets dimmer. By the time the LED has reached just about 0 the three seconds has passed and the arduino stops using that loop and moves on to the next one. The only thing different about the second loop is it starts after three seconds has passed and stops when six seconds has past and it illuminates a blue led. You may have noticed however that after the blue LED's loop there is a piece of code that makes the arduino reset. This isn't after the last loop because it takes the arduino a little time to carry out this command and if this bit of code happens last then there is a relatively large span of time when no LED's are lighting up. Placing it second shortens this gap. Lastly the red LED's code kicks in after six seconds and ends when the clock reaches nine seconds. The arduino then resets itself and there is a short break were no lights are on and then the whole thing starts over again. There you have it ,an explanation for the code but there is one more thing you need to know. For some reason unknown to me the arduino won't upload if a wire is in the reset pin. I have no reason to believe repetitively reseting your arduino is harmful as my arduino uno seems fine and the other instructables didn't mention their arduino's breaking down. I do believe the cause is similar to when the arduino can't upload if a wire is in digital pin 0. Whatever the case the problem is simply solved by removing the wire until the arduion has uploaded and then sticking it back in. If anyone knows why this happens please tell me in the comments. Thanks every body for reading this instructable and I hope you love your new night light.

Lastly I'm giving God the glory because he made us so awesome and that we can overcome and understand the world of programing. Also His night lights are cooler than mine and he has about a trillion of them in space. : )

Make it Glow Contest 2016

Participated in the
Make it Glow Contest 2016

Arduino Contest 2016

Participated in the
Arduino Contest 2016

Homemade Gifts Contest 2016

Participated in the
Homemade Gifts Contest 2016