Introduction: Arduino Night Light
This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com). Hope this helps!!
Step 1: Design
This project started out as an image in my head. Figured out what I wanted and then moved on from there. I went the awkward route and made my inventor design first. Knowing I was going to create a 3-LED night light I decided I would mount the LED bulbs to the inside of a movie night light head. Below is a file and design screen shots of the 3D printed part containing the LEDs.
Step 2: Prototyping/Wiring
Here is where we began with the wiring and set up before code. Attached are finalized pictures as well as a Fritzing diagram of the breadboarding.
Notice how the bread board is set up with:
- 3 220 Ohm resistors
- 1 10k resistor
- 3 LEDs
- 1 Servo Motor
- 8 wire extensions
- miscellaneous wires for connections
- 1 Arduino board
- 1 Breadboard
- 1 9V battery connector
- 1 9V battery
Here the circuit is relatively simple. The power comes from the 9V battery to power the arduino and then using the 5V connector on the arduino as well as the ground, A0, pin 9 and pin 3, we are able to begin to power the breadboard. Then you connect the power to the rails and start connecting the resistors, LEDs, photoresistor, and servo motor. Once set up like the Fritzing diagram you move on to the code.
Step 3: Code
Included here in a word document you will find the completed and working code to make the LEDs turn on and the servo move.
In the code we started with including the library to make the servo preform properly. Then we initialized the position of the servo to 90 as well as set the variable for the LED in which the pin number it will be. We now moved on to the setup where we configure the pin as an output and attach the servo in order to be ready to be set in motion. Now moving to the loop we input the sensor value showing that it will be the A0 pin on the arduino and then created an if statement showing the point at which the state of the LEDs change. Included in that if statement we write the code to turn the LEDs on high and turn the servo to the second position and we included a delay as well. Then we move on to the else statement in which the LED is set to low and the servo moves the opposite direction and then stops.
This night light is controlled by a photo resistor and within the code the lights will turn on and the servo will move when the photo resistor is receiving no light but when it is receiving light the LEDs will turn off and the servo position will return to the starting spot. This will constantly repeat as long as it is powered.
Step 4: Finish Up!!!
This is where you will be able to finish up the project. Whether you put it inside a little black rectangle or just leave it open to see the wires is your choice; but, not its time to put the LEDs into the 3D par and then mount the part on the servo. Once this is completed and you have uploaded the code to the arduino you can plug in the 9V battery and fire it up!
Hope all of this commentary as well as pictures and sketches helps you to recreate this project.
We have a be nice policy.
Please be positive and constructive.