Introduction: Decorative DC12V Spotlights

Picture of Decorative DC12V Spotlights

Objective : -

We wanted to have four decorative 12V DC Spotlights blink randomly in different patterns for our display window. Probably, it would have been easy to buy something like this off the shelf but then, that would be no fun and I also wanted to make some constructive use of the Atmega8 Chips that I had lying around from my earlier projects. Since the project came out the way it was expected, I thought I’d share my experience with you.

First thing I wanted was to have a relay board that would not make the continuous clicking sound that mechanical relays make. It can be quite annoying the clicking sound from those relays, so I wanted to use Mosfets instead of the mechanical relays

Step 1: Parts Required

Where I stay, it was difficult to find logic level Mosfets so I had to settle for IRF540N as the switching Mosfet. The IRF540N is quite cheap and readily available so it was a convenient choice. Initially I was skeptical, all with the limitation of the voltage and current output of the Arduino and had thought of using some 3906 Transistors to amplify the current but while trying out on the breadboard, I figured we’d be able to manage without the transistors with the 5 Volt Arduino. I did try with the 3.3 Volt version of the Arduino too but for that I had to use the 3906 Transistors to get them to work. Since we’ll be using the 5 Volt version we’ll forget about the Transistors for now.

We will be using 12V DC output for the spotlights and we require 5V DC for the Arduino so the board has been designed to incorporate a 5V regulator IC (the popular 7805) to supply power to the Atmega8 and we will use a 12V 2A DC wall wart/power supply to supply power to the lights through the IRF540N Mosfet.

The Parts & Tools Used

1. Atmega8 x 1

2. 7805 Voltage Regulator

3. .1 uF Ceramic Capacitor x 4

4. 22pF Ceramic Capacitor x 2

5. 47uF Electrolytic Capacitor x 1

6. 10uF Electrolytic Capacitor x 1

7. 2200uF Electrolytic Capacitor x 1

8. 10K ¼ watt Resistor x 5

9. 1K ¼ watt resistor x 4

10. 220 ohm ¼ watt Resistor x 2

11. 3mm LED x 2

12. 16MhZ Crystal x 1

13. IRF540N Mosfet x 4

14. 12V DC Barrel Socket x 1

15. 2 Pin Terminal Block x 4

16. Copper Clad Board for PCB 4” x 2.5”

17. Ferric Chloride (Etchant)

18. Acetone

19. Toner Transfer Paper

20. General Small Hand Tools

21. Assorted Jumper Wires, Solder, Flux Etc.

Step 2: The PCB

Picture of The PCB

The PCB Layout and the Component Layout are clearly shown in the pictures and it is fairly simple to assemble.

I don't suppose there is the need to go into the details of inserting each part and soldering them onto the board. All the parts used are through the hole and one look at the component layout will be enough to tell you what goes where

Step 3: The Sketch

After the board was completed, I used the Arduino IDE to compile a short sketch that would turn on and off the LED lights connected to the four output terminals in different sequences and continue to do so endlessly. Note here that I used digital pins 5, 6, 7 & 8 as output pins and these pins are connected to the control pins on the board with jumper wires. These pins were not permanently connected to each other on the PCB while designing the board since you may want to use different pins on the Atmega8/328 in your sketch.

The sketch is absolutely simple, all we need here is to have the McU turn four i/o pins high and low as per your requirement and in the order that you want your lights to blink and at the speed at which you want them to blink. So here goes :-

The Sketch -

void setup()

{

pinMode(5, OUTPUT);

pinMode(6, OUTPUT);

pinMode(7, OUTPUT);

pinMode(8, OUTPUT);

}

void loop()

{

digitalWrite(5, HIGH);

digitalWrite(7, HIGH);

delay(100);

digitalWrite(5, LOW);

digitalWrite(7, LOW);

delay(100);

digitalWrite(6, HIGH);

digitalWrite(8, HIGH);

delay(100);

digitalWrite(6, LOW);

digitalWrite(8, LOW);

delay(100);

digitalWrite(5, HIGH);

digitalWrite(7, HIGH);

delay(100);

digitalWrite(5, LOW);

digitalWrite(7, LOW);

delay(100);

digitalWrite(6, HIGH);

digitalWrite(8, HIGH);

delay(100);

digitalWrite(6, LOW);

digitalWrite(8, LOW);

delay(100);

digitalWrite(5, HIGH);

digitalWrite(7, HIGH);

delay(100);

digitalWrite(5, LOW);

digitalWrite(7, LOW);

delay(100);

digitalWrite(6, HIGH);

digitalWrite(8, HIGH);

delay(100);

digitalWrite(6, LOW);

digitalWrite(8, LOW);

delay(100);

digitalWrite(5, HIGH);

digitalWrite(7, HIGH);

delay(100);

digitalWrite(5, LOW);

digitalWrite(7, LOW);

delay(100);

digitalWrite(6, HIGH);

digitalWrite(8, HIGH);

delay(100);

digitalWrite(6, LOW);

digitalWrite(8, LOW);

delay(100);

digitalWrite(5, HIGH);

digitalWrite(7, HIGH);

delay(100);

digitalWrite(5, LOW);

digitalWrite(7, LOW);

delay(100);

digitalWrite(6, HIGH);

digitalWrite(8, HIGH);

delay(100);

digitalWrite(6, LOW);

digitalWrite(8, LOW);

delay(100);

digitalWrite(5, HIGH);

delay(100);

digitalWrite(5, LOW);

delay(100);

digitalWrite(6, HIGH);

delay(100);

digitalWrite(6, LOW);

delay(100);

digitalWrite(7, HIGH);

delay(100);

digitalWrite(7, LOW);

delay(100);

digitalWrite(8, HIGH);

delay(100);

digitalWrite(8, LOW);

delay(100);

digitalWrite(5, HIGH);

delay(100);

digitalWrite(5, LOW);

delay(100);

digitalWrite(6, HIGH);

delay(100);

digitalWrite(6, LOW);

delay(100);

digitalWrite(7, HIGH);

delay(100);

digitalWrite(7, LOW);

delay(100);

digitalWrite(8, HIGH);

delay(100);

digitalWrite(8, LOW);

delay(100);

digitalWrite(5, HIGH);

delay(100);

digitalWrite(5, LOW);

delay(100);

digitalWrite(6, HIGH);

delay(100);

digitalWrite(6, LOW);

delay(100);

digitalWrite(7, HIGH);

delay(100);

digitalWrite(7, LOW);

delay(100);

digitalWrite(8, HIGH);

delay(100);

digitalWrite(8, LOW);

delay(100);

digitalWrite(5, HIGH);

delay(100);

digitalWrite(5, LOW);

delay(100);

digitalWrite(6, HIGH);

delay(100);

digitalWrite(6, LOW);

delay(100);

digitalWrite(7, HIGH);

delay(100);

digitalWrite(7, LOW);

delay(100);

digitalWrite(8, HIGH);

delay(100);

digitalWrite(8, LOW);

delay(100);

digitalWrite(5, HIGH);

delay(100);

digitalWrite(5, LOW);

delay(100);

digitalWrite(6, HIGH);

delay(100);

digitalWrite(6, LOW);

delay(100);

digitalWrite(7, HIGH);

delay(100);

digitalWrite(7, LOW);

delay(100);

digitalWrite(8, HIGH);

delay(100);

digitalWrite(8, LOW);

delay(100);

digitalWrite(5, HIGH);

delay(100);

digitalWrite(5, LOW);

delay(100);

digitalWrite(6, HIGH);

delay(100);

digitalWrite(6, LOW);

delay(100);

digitalWrite(7, HIGH);

delay(100);

digitalWrite(7, LOW);

delay(100);

digitalWrite(8, HIGH);

delay(100);

digitalWrite(8, LOW);

delay(100);

digitalWrite(8, HIGH);

delay(150);

digitalWrite(8, LOW);

delay(150);

digitalWrite(7, HIGH);

delay(150);

digitalWrite(7, LOW);

delay(150);

digitalWrite(6, HIGH);

delay(150);

digitalWrite(6, LOW);

delay(150);

digitalWrite(5, HIGH);

delay(150);

digitalWrite(5, LOW);

delay(150);

digitalWrite(8, HIGH);

delay(150);

digitalWrite(8, LOW);

delay(150);

digitalWrite(7, HIGH);

delay(150);

digitalWrite(7, LOW);

delay(150);

digitalWrite(6, HIGH);

delay(150);

digitalWrite(6, LOW);

delay(150);

digitalWrite(5, HIGH);

delay(150);

digitalWrite(5, LOW);

delay(150);

digitalWrite(8, HIGH);

delay(150);

digitalWrite(8, LOW);

delay(150);

digitalWrite(7, HIGH);

delay(150);

digitalWrite(7, LOW);

delay(150);

digitalWrite(6, HIGH);

delay(150);

digitalWrite(6, LOW);

delay(150);

digitalWrite(5, HIGH);

delay(150);

digitalWrite(5, LOW);

delay(150);

digitalWrite(8, HIGH);

delay(150);

digitalWrite(8, LOW);

delay(150);

digitalWrite(7, HIGH);

delay(150);

digitalWrite(7, LOW);

delay(150);

digitalWrite(6, HIGH);

delay(150);

digitalWrite(6, LOW);

delay(150);

digitalWrite(5, HIGH);

delay(150);

digitalWrite(5, LOW);

delay(150);

digitalWrite(8, HIGH);

delay(150);

digitalWrite(8, LOW);

delay(150);

digitalWrite(7, HIGH);

delay(150);

digitalWrite(7, LOW);

delay(150);

digitalWrite(6, HIGH);

delay(150);

digitalWrite(6, LOW);

delay(150);

digitalWrite(5, HIGH);

delay(150);

digitalWrite(5, LOW);

delay(150);

digitalWrite(8, HIGH);

delay(150);

digitalWrite(8, LOW);

delay(150);

digitalWrite(7, HIGH);

delay(150);

digitalWrite(7, LOW);

delay(150);

digitalWrite(6, HIGH);

delay(150);

digitalWrite(6, LOW);

delay(150);

digitalWrite(5, HIGH);

delay(150);

digitalWrite(5, LOW);

delay(150);

digitalWrite(8, HIGH);

digitalWrite(7, HIGH);

digitalWrite(6, HIGH);

digitalWrite(5, HIGH);

delay(100);

digitalWrite(8, LOW);

digitalWrite(7, LOW);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

delay(100);

digitalWrite(8, HIGH);

digitalWrite(7, HIGH);

digitalWrite(6, HIGH);

digitalWrite(5, HIGH);

delay(100);

digitalWrite(8, LOW);

digitalWrite(7, LOW);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

delay(100);

digitalWrite(8, HIGH);

digitalWrite(7, HIGH);

digitalWrite(6, HIGH);

digitalWrite(5, HIGH);

delay(100);

digitalWrite(8, LOW);

digitalWrite(7, LOW);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

delay(100);

digitalWrite(8, HIGH);

digitalWrite(7, HIGH);

digitalWrite(6, HIGH);

digitalWrite(5, HIGH);

delay(100);

digitalWrite(8, LOW);

digitalWrite(7, LOW);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

delay(100);

digitalWrite(8, HIGH);

digitalWrite(7, HIGH);

digitalWrite(6, HIGH);

digitalWrite(5, HIGH);

delay(100);

digitalWrite(8, LOW);

digitalWrite(7, LOW);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

delay(100);

digitalWrite(8, HIGH);

digitalWrite(7, HIGH);

digitalWrite(6, HIGH);

digitalWrite(5, HIGH);

delay(100);

digitalWrite(8, LOW);

digitalWrite(7, LOW);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

delay(100);

digitalWrite(6, HIGH);

digitalWrite(5, HIGH);

delay(250);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

delay(250);

digitalWrite(7, HIGH);

digitalWrite(8, HIGH);

delay(250);

digitalWrite(7, LOW);

digitalWrite(8, LOW);

delay(250);

digitalWrite(6, HIGH);

digitalWrite(5, HIGH);

delay(250);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

delay(250);

digitalWrite(7, HIGH);

digitalWrite(8, HIGH);

delay(250);

digitalWrite(7, LOW);

digitalWrite(8, LOW);

delay(250);

digitalWrite(6, HIGH);

digitalWrite(5, HIGH);

delay(250);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

delay(250);

digitalWrite(7, HIGH);

digitalWrite(8, HIGH);

delay(250);

digitalWrite(7, LOW);

digitalWrite(8, LOW);

delay(250);

digitalWrite(6, HIGH);

digitalWrite(5, HIGH);

delay(250);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

delay(250);

digitalWrite(7, HIGH);

digitalWrite(8, HIGH);

delay(250);

digitalWrite(7, LOW);

digitalWrite(8, LOW);

delay(250);

digitalWrite(6, HIGH);

digitalWrite(5, HIGH);

delay(250);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

delay(250);

digitalWrite(7, HIGH);

digitalWrite(8, HIGH);

delay(250);

digitalWrite(7, LOW);

digitalWrite(8, LOW);

delay(250);

digitalWrite(6, HIGH);

digitalWrite(5, HIGH);

delay(250);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

delay(250);

digitalWrite(7, HIGH);

digitalWrite(8, HIGH);

delay(250);

digitalWrite(7, LOW);

digitalWrite(8, LOW);

delay(250);

}

Step 4: Getting It Onto the Atmega8 Chip

Picture of Getting It Onto the Atmega8 Chip

I am no programmer and as far as I am concerned this simple sketch lets me have 5 – 6 different sequences and seems to be enough for my purpose. Lots of people would want to do it differently and I am always open to suggestions and thrive to learn from the experiences of others. For those who are proficient with programming and have knowledge of different programming languages can definitely do a much better job or attain the same or better results with different IDE’s like Atmel Studio 6 etc. but I wanted this to be as simple as it could be and wanted to use my unused Atmega8 Chips so I chose the Arduino IDE as I find it easier to use. Also, writing code is not quite my forte.

Now the issue was to transfer the sketch to the Atmega8 Chip, current day Arduino boards do not support the Atmega8 chips and getting the Arduino bootloader onto the Atmega8 Chip is also one job so the easiest way was to extract the HEX file that theArduino IDE would create and transfer the HEX File onto the Atmega8 Chip with the help of an AVR Burner.

To find where the hex file is formed when you compile the sketch in the Arduino IDE you need to first make sure that you choose the correct board in the ARDUINO IDE as we want it to compile the sketch for the particular chip that we are using, in our case, we choose the “Arduino NG” or older in the boards menu and then choose “Atmega8” as the processor before compiling the sketch. This is so that the Arduino IDE knows which chip is being used so that it can compile the sketch and create the HEX file for that particular chip.

If you are using the Window Platform, go to the start menu and type “%temp%” in the “search programs & files” box, refer to screen shots.

Hit enter and you will see a list of all the temp files on
your computer. Most of these can be safely deleted but that is not our purpose.

Now, when you “Verify Compile” the sketch in the Arduino IDE, a temporary folder is created in this directory which looks something like this “build9c5c42f46812d2c0168c7e753f3510e0.tmp” It is in this folder that you will find the HEX file that you need. Note that there will be 2 hex files, one with bootloader and one without, you need the one without the bootloader. Before closing the Arduino IDE make sure to copy the HEX file that you need to the location of your choice because when we close the Arduino IDE, this temp folder is automatically removed.

Refer to the images

Make sure to select and choose the correct Fuse Bit Settings before burning the HEX file. If you are using a 16MhZ Crystal the most appropriate setting would be LOW FUSE – “FF” and HIGH FUSE as “C9” and lock fuse as “FF” Check on the appropriate boxes. If you are using a different crystal, say a 12MhZ or 8MhZ, you could refer to the various AVR Fuse Calculators that are available online. The wrong fuse settings could have you brick your AVR chip and then it becomes difficult to unlock the chip. (You would probably need specialized software and a parallel programmer to be able to unlock these chips.)

Now insert the targate chip in the correct orientation in the DIP Socket of the AVR burner that you are using, connect the Burner to you computer USB port, Add external power to the Burner as shown (if requirfed by your burner) and open the Extreme AVR Burner software (I assume you will have the software already installed in your computer) or which ever software you are using.

Hit “Open” and select the HEX File you want to burn

Go to Fuse Settings menu and select the correct fuse settings as mentioned earlier

Make sure all systems are on and hit the “Write All” Button. If all is well, you should get the all done message in a few seconds.

Almost done,

We now need to move the chip to our board and we are ready to connect to our 12V DC Spotlights.

Step 5: Time to Test

Picture of Time to Test

Time to test it!!

Power on the system. Since the lights I am using are rated 12V 10 Watts which works out to 1.2A at 12 Volts, I decided to use a regular 12V 2A DC adapter/wall wart for the power supply because the lights would not be on continuously at the same time and never for more than 250 mili seconds at a time. This is working perfectly for me. I have enclosed the PCB in a plastic box for the sake of saftey from short circuits.

To test the board, I have attached 4 LED’s to the output terminals. For the sake of convenience, I have marked the positive output pins with red nai polish so that the Spotlights are connected correctly. The Spotlights that I intend using are like the ones in the picture.

Step 6: All Done - Hope You Enjoyed the Article!!

I am uploading a couple of small video clips of the final board before I actually installed in the display window.

The possibilities are endless and your imagination will be the only limitation.

Comments

fadecomic (author)2017-06-01

If you ever want to be able to use the atmega to control more than one thing (you never know!) you can use the timer instead of "delay". Delay works, but it completely locks up the chip. Alternatively, you can check the running timer and let it fire each light every x, y, z, q milliseconds and still leave it free to, I don't know, brew you a cup of coffee. Also, if you are having trouble finding logic level mosfets, you can also use optocouplers. They're cheap, and do the same thing as a relay silently. Nothing wrong with anything you did, just passing on things I've learned.

jaatbuddhi (author)fadecomic2017-06-01

Thanks for your inputs, I have a lot to learn !!

About This Instructable

551views

13favorites

More by jaatbuddhi:Decorative DC12V SpotlightsSimple Mini Dusk to Dawn Switch for 220v AC
Add instructable to: