Automatic Light Dimming Device
by sorensenl in Circuits > Arduino
112 Views, 0 Favorites, 0 Comments
Automatic Light Dimming Device
![IMG_2516.jpg](/proxy/?url=https://content.instructables.com/FVK/C537/LIHFPB1X/FVKC537LIHFPB1X.jpg&filename=IMG_2516.jpg)
I made an automatic light dimming device for my dad. My dad wakes up early and goes to bed early. He forgets to turn off his tableside light and leaves the light running over the night. This costs money and makes him mad. I made a light that will dim until completely off saving my dad from worrying about a running light all night.
Supplies
Arduino uno R3
Breadboard
6 male to male wires
4 small led lights ( colors up to user )
9v battery
9v battery connector
4 resistors
Computer ( for code )
Computer cable (to upload code onto the arduino)
Tinkercad website
Arduino IDE app
Digital Design
![Screenshot 2023-06-04 165447.png](/proxy/?url=https://content.instructables.com/FNE/R3KA/LIHFPBN5/FNER3KALIHFPBN5.png&filename=Screenshot 2023-06-04 165447.png)
Using the tinkercad website, search all the tools given above and put it on the workspace. After grabbing all of the tools, begin connecting the wires to the correct spots in the picture. After this, then you rotate the LED lights with the rotate tool 90 degrees and put them on the breadboard in the spots noted above. Make sure the long side is faced down. Then, put the resistors in the spots like up above to make sure the light does not burn out. Picking the color of the LED lights is up to the user.
Create Code
![Screenshot 2023-05-25 190054.png](/proxy/?url=https://content.instructables.com/F6G/TUO4/LIHFPCPU/F6GTUO4LIHFPCPU.png&filename=Screenshot 2023-05-25 190054.png)
For creating the code, it can be done in tinkercad easily. In tinkercad, using block code, the website can automatically change it to written code without you having to write it. If you want to create the code yourself, you can use the example on the left of the image. Make sure that you create the variable brightness so the code can dim and change its voltage of light. I will also give the written code below. Then, copy the written code into the Arduino IDE app so it can then be transferred to the IRL version.
// C++ code
//
int brightness = 0;
int i = 0;
int counter;
int counter2;
void setup()
{
pinMode(A0, INPUT);
pinMode(9, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(3, OUTPUT);
if (analogRead(A0) > 500) {
for (counter2 = 0; counter2 < 1; ++counter2) {
for (brightness = 500; brightness >= 0; brightness -= 0.0001) {
analogWrite(9, brightness);
analogWrite(6, brightness);
analogWrite(5, brightness);
analogWrite(3, brightness);
delay(30); // Wait for 30 millisecond(s)
for (counter = 0; counter < 10; ++counter) {
for (brightness = 250; brightness >= 0; brightness -= 0.001) {
analogWrite(9, brightness);
analogWrite(6, brightness);
analogWrite(5, brightness);
analogWrite(3, brightness);
delay(30); // Wait for 30 millisecond(s)
}
}
}
}
} else {
analogWrite(9, 0);
analogWrite(6, 0);
analogWrite(5, 0);
analogWrite(3, 0);
delay(30); // Wait for 30 millisecond(s)
}
}
void loop()
{
delay(10); // Delay a little bit to improve simulation performance
}
IRL Version
![IMG_2516.jpg](/proxy/?url=https://content.instructables.com/FBV/5RKQ/LIHFPDID/FBV5RKQLIHFPDID.jpg&filename=IMG_2516.jpg)
Using the tools you have, create the tinkercad version identical for the real version. Make sure that the breadboard and arduino are close so you can connect the wires comfortably. Make sure the wires are in the right spots and make sure the LED lights are facing the right way. Also, connect the battery and the battery connector to the arduino device.
Transfer Code
![Screenshot 2023-06-04 172528.png](/proxy/?url=https://content.instructables.com/F9I/903V/LIHFPE3E/F9I903VLIHFPE3E.png&filename=Screenshot 2023-06-04 172528.png)
For this step, put the exact code from tinkercad or the one provided above into the arduino IDE app. When pasted in there, connect the arduino with the computer using the computer cable, and select from the drop down function and click arduino uno. Finally, click the arrow in the top left to transfer the code into the real device.
Test
![WIN_20230525_18_59_53_Pro.jpg](/proxy/?url=https://content.instructables.com/FZG/LDAM/LIHFPF09/FZGLDAMLIHFPF09.jpg&filename=WIN_20230525_18_59_53_Pro.jpg)
When the code is uploaded, the lights should light up and dim over a short period of time. If you want to make this longer, then change the time variable in the code. If it does not work, make sure all of the code is in correctly or all the tools are in the right spots.