LED UV exposure box part 2, the timer

Introduction

There are a few others out there for the same purpose, but I wanted to add some more features to make things better.

As I have mentioned in the previous post, safety was a big concern for me so I added a switch that should prevent turning on the UV LEDs when the lid is open. Of course, this is not enough, so the switch has to work along with the timer ensuring that everything goes smoothly.

The key features that I wanted:

– Exact time display

– Adjustable time, 10 second resolution

– Start/pause function

– Automatic pause and UV LED turn off when the lid is open

– Some predefined available values for easy access.

Implementing the safety measures is easy, as the switch on the box could be made to connect either the RED or the UV LEDs. The timer needs to control the UV LEDs, so I have used a MOS transistor. It also needs to know the state of the box lid. I have built a circuit that can achieve all this. The concept schematic can be seen below:

The schematic shows, symbolically, the red and UV LED arrays through the basic cell that is repeated on the panels: a series of three LEDs and a resistor. As you can see, there is no way to turn on the UV light when the lid is open, even if such a command would come from the microcontroller. The microcontroller can turn the UV light on via the MOS transistor only when the lid is closed. This is controlled through software too. In order to sense whether the lid is open or not, the microcontroller monitors the state of the cathode of the red LED array. When the lid is open, this is shorted to ground and the micro sees a low logic level. When the lid is open the red LEDs will conduct current and force the microcontroller to see a high. This current is small, limited by the 10K resistor and therefore the LEDs do not appear to be on. I could have chosen to leave the red LEDs on all the time as this does not influence the functionality of the exposure box, but it adds extra consumption and more heat needs to be dissipated by the lower panel.

Although it is not totally justified, I decided to go the full effort and make this timer with a display. There could be many more ways to do this starting from a simple 555 circuit. I wanted the circuit to be a challenge for the box itself, so small SMD parts are used wherever possible.

The build

The display is a KW4-361ASB from Luckylight. It is small, 9mm digit height and has 4 multiplexed digits. There were two basic criteria for selecting this particular part, first I wanted it to be small and efficient so that a small current is enough for a bright display and second I wanted it to be multiplexed as this simplifies board layout.

I choose an ATTiny2313 microcontroller as it has all the features needed to implement all the tasks: sufficient pin driving capability, a timer, enough pins and memory. It’s got an internal oscillator too, but as I missed it, the tolerance is within 10% which I consider too high for this project. I have later added a crystal on the board but adjusted the starting timer value on my particular circuit to compensate for the internal oscillator deviance. This was easy as I knew that the refresh frequency for the display should be 50Hz, so a frequency meter was all that I needed. I believe that this should not fluctuate and no future compensation will be needed to maintain the error at a small value, maybe less than 2-3%. I do suggest using a quartz crystal, but this is not mandatory, you may use my method or simply accept the maximum 10% tolerance.

To turn on the UV LEDs I have used a TSM2302 MOS transistor which has a capability of 3.6A, more than enough for both the boards. Other transistors may be used, such as IRLML0060TRPBF.

Other than this, there are 4 buttons on the board, a 7805 regulator and connectors. The 4 buttons have the following functions, from left to right: START/STOP the timer, UP – adds 10 more seconds, DOWN – subtracts 10 seconds, MEM – recalls some preset values from the memory.

Because software allows flexibility in connecting the display, I chose to make the connections as easy as possible for the PCB layout, and this is why the schematic is not very straightforward.

The connection of the lid switch and LED arrays is shown below:

Because the box was functional, I decided to make the PCB a challenge for it: Small display, small SMD components. The finished PCB is shown below, the board is very compact and measures less than 6×3.5cm:

You may wonder why there is no programming connector. The reasons are two: I wanted to make it as compact as possible and the fact that it is the type of circuit that requires a single programming (For the end user). As all the pins required for programming are connected to the display it is easy to connect a few wires to the programmer, as you can see I did in the picture below:

I’m quite new to AVR programming and would appreciate your help about the exact fuse settings for this application as I don’t want the mess around too much with them. I have managed to boot up the timer but the display is flickering and it takes 3 or 4 seconds to count down one second. I think the

Hi. Built your circuit with a few mods mostly to handle higher current and a few led indicators. Works great! Thanks. The only feature I would like to have is a buzzer when the count down completes. Have you thought about this? Would I need to change the code or is there a way to drive a transistor with the current code to switch a buzzer on.

I actually planned on having a buzzer, but then i forgot about it in the design of the PCB. It didn’t prove to be missed, though. In the few minutes that the exposure is done I just go an prepare the etching and developing solutions. It’s all done when I come back.
You could add a buzzer, but some software would need to be modified.

hi
im having trouble programming the fuse bits as im unsure what low high and extended fuse bits to program .
im using usbasp programmer with avr-dude.
can you help by providing me with a command line please

Hello again Bogdan,
I tried initializing with 0xB1E0 as you suggested but there was no change.After a few trials today I came up with 0xB38E as the best initialization constant for the 4mhz crystal oscillators used in this project. I have built 2 of these and results were the same for both. Thanks again for a teriffic project and your help.

Bogdan,
Thanks for the great project. Once I chased the bugs away it worked like a champ. The major issue I had was using the ISP to program the T2313. What happened was that I programmed the chip using your hex file ahead of time. Then I remembered that I was using a 4 mhz xtal so I programmed the lfuse, but forgot to rempve the divide by 8 fuse, so when I powered up the timer it ran slowly – about 1/8 normal speed. Then when I tried to program it after it was soldered to the board but avrdude could not initialize the chip. What I traced it down to was that pins 17, 18, and 19 were being connected through the LED display. By temporarily removing the resistors between t2313 pins 17 and 18 and the LED display (R1 and R6) I was able to reprogram the lfuse and now it works as you designed it. A few comments though: I used an Everlight MSQC6912C display with 13mm display height. There were 2 problems – the display had 7 pins on the lower part and 5 pins on the upper side, and your display has 6 above and 6 below, so I had to relayout the board. Secondly, the Everlight display operates at different voltages and currents – I ended up with 150 ohm resistors between the T2313 and the display unit. Also, it seems like the xtal is not too accurate. I set the timer for 4.00 minutes and then timed it. It took an actual 4 minutes 5 seconds for the display to reach zero, so it is running a little slow. Is there an easy fix for that? Thanks again for sharing it.

Hi, nice tutorial!
Im working on a box of my own right now, but have one question regarding your circuit: Is it possible to use a relay instead of the MOSFET switching the UV-LEDs? or does that make it hard controlling the leds from the mcu?

Sorry, i missed your comment. Sure, you can use a relay to drive the LEDs. You’ll also need a small circuit to drive the relay, something like this:http://images.elektroda.net/24_1326968063.gif
For small relays you can use a small power transistor, like BC547, BC337 etc

I have succeded in building a box similar to the first part of your project and am now trying to create the timer part, but I have encountered a problem. After creating the circuit I tried to program the ATTiny2313 with your firmware (using avrdude and a Bus Pirate). I set the low fuse bits to 0x6C and high to 0xDB to make use of a 4MHz 30pF external crystal (and brown-out though it’s probably not needed?) and flashed in timer.hex. When I power on the timer however, the display (a 4 digit, multiplexed, common anode) only flashes between almost random states about every 3 seconds. I assumed I needed to change the instructions as it probably doesn’t use the same as yours, so I tried flashing in a modified version. It didn’t succeeed, as now it seems the ATTiny doesn’t respond to the programmer at all, avrdude complains about invalid device signature.

I have some ideas of what might be wrong. It is likely that I used incorrect fuse bits, as I don’t fully understand all of the options. Also, before flashing, for some reason I decided to rebuild the .hex file you provide with “make” command. It might have broken something in the firmware, though I can’t see why it would.

Luckily I have a spare ATTiny that I will make another attempt with. Before I try it I would like to ask what fuse bits I should use this time. Which did you use?

Sorry, I’ve missed your comment. I have used internal 4MHz which proved imprecise so I altered the counter to get accurate timing. You just have to set the fuses to external xtal and that’s about it. You should check your fuses, maybe even use some different programing utility that does the calculation for you. (try AVR OSP II or something similar).

Thank you for the involvement of the timer, I am from Slovakia and I accidentally bought 200 pieces of UV LEDs and looking for something like this. Involvement worked the first time, the board is a place where the signals are very close (pin 5 and 6), but otherwise I like the involvement. I used KW4-361ASA, recommended type is not available. Capacitor tantalum 10u I used on the top side. Capacitors also not available. 🙂

Great results! I see your box is working fine and your first pcb seems ok. I like how you have included the supply in the box, i should have done that too. Hope you don’t mind, i’ll add your pictures from your box.

Hello, Bogdan!
This is an amazing project! I was looking for an UV Lamp from about a year, but now, I will build this box with your timer.
I am using AVR mcs from about 7 years, but I don’t use 7 segment displays yet. So, my problem is that I can’t find this kind of display that you’re using – KW4-361ASB. So will you give me an advice in this direction – how to control a single 7 segment display with your code? (with 1 number) I build my Timer with 16×2 LCD Display, but yours look pretty simple. 🙂
Thank you very much!
Regards from Bulgaria!
Borislav

You can’t find that particular display because there are so many kinds available. You should get any 4 digit display as long as it is multiplexed. There may be pin differences, but you can fix that by making a different board or by using wires to connect it to the one I designed.
As for working with 7 segment displays, have a look at: http://extremeelectronics.co.in/avr-tutorials/interfacing-seven-segment-displays/
There are many other tutorials available, google will help you uncover thousands of sites.

Thanks again!
But I already found this display on TME’s web page. And I will purchase LEDs and the display soon.
Now, I will etch the PCBs for the box and I will post here some pictures and PCB files!
Best regards,
Borislav

I bought the dispaly and UV LEDs from TME too. But i was too lasy to etch and drill boards for the leds, I did have the chance to purchase the boards used for a low price, a little over one euro.
Have fun with your build and I’ll be waiting for your box.

Hello!
I have used the LM317 as a voltage regulator, set to output 12.0V. This is so that i can have a stable voltage for the panel, which means stable UV power, therefore a fixed exposure time.
If the voltage applied to the leds(3 leds + 91 ohm resistor in series) varies, so does the current and the exposure time. LM317 gets a fixed output for a wide range of inputs(15 V minimum) so i can use different power supplies.
The total current required for my panels is a little over 1A, that’s why i didn’t use a simple 7812.

The leds you mentioned are quite a narrow angle, which means you will need a higher distance between the led and the board to get a uniform exposure. You may want to look for some with a higher angle.