Making Magnificent Moonlights

Got any home remedies or DIY projects? Share them here!
Problems with your tank's equipment? We can help!
YBeNormal
Former Staff Member
Posts: 506
Joined: Sat Jun 04, 2005 1:19 am
Location: Northern Virginia
Contact:

Post by YBeNormal »

Absolutely! I'm building a DIY auto-topoff system using plans posted on RC. Might as well add moon lights while I'm at it!
User avatar
Phaedrus
Former Staff Member
Posts: 1402
Joined: Tue Jul 19, 2005 8:34 pm
Location: Saskatoon, Saskatchewan, Canada
Contact:

Post by Phaedrus »

This is cool. I think I'll give this a try when I set up my 55 gallon.
User avatar
PetPirate
Gone Today, Here Tomorrow
Posts: 1230
Joined: Mon Jun 27, 2005 5:41 am
My Puffers: 3x Tetraodon Nigroviridis in full marine
Location: Shanghai, China
Contact:

Post by PetPirate »

Yeah! Three people hanging on......

The next feature we're going to add will be SUPER BRIGHTNESS and a nifty dim-on and dim-off effect. 8)

I'm afraid there's going to be a bit more THEORY :twisted: :twisted: :twisted: in order for us to do this... but not to worry, I can hold your hand if it all gets too much.

How can we make that LED brighter? It's already running close to 20mA, and you told us that 20mA was the maximum recommended current? What’s going on here? Simple! We overdrive the LEDs! We shove more current through them, and make them so bright we can shine a spot onto the moon itself. Well, almost.

You wot? But won't that shorten their lives? :?:

Yes! It would, but we're going to do it PROPERLY... according to the spec sheet.....

Here's a piece of the spec. sheet:

Image

Wow, exciting stuff, huh? (wipes drool from corner of mouth). See the part I circled in pretty purple? That just tells you the absolute max. current – 30mA. They won't last as long at this current, and the recommended maximum current for most all LEDs is 20mA. Later on in the datasheet, they go on to provide reliability statistics, but point out that these are only valid for a maximum current of 20mA.

We knew all that already! We're already shoving 20mA of current through the LEDs! What's new? :?:

Grrr, you're persistent, aren't you? :lol: Well – can you see the parts circled in that attractive turquoise colour? That's the bit we're interested in. Let me translate it into plain English:
Jhong's magic Geekspeak to plain English converter wrote:"If you like, you can shove 100mA through your poor little LEDs without shortening their lives, as long as you only do it for a maximum of ten milliseconds, and then give them 90 milliseconds to cool down again before turning the poor little things on again"
Aha! So, that's what we're going to do! We're going to turn the little blue bu**ers on, as bright as can be, for a tiny fraction of a second at a time (much faster than the maximum time of 10 milliseconds), and then allow them to cool down for nine times this time... and do this over and over and over again, flashing them on and off repeatedly.... and because our eyes (and indeed the eyes of our fish and corals) are so slow, they won't even know that we're doing it! And, they'll look MUCH brighter than before – even though the average current drawn is less!!! GREAT! This is because doubling the current through the LED more than doubles the brightness. What's more, by varying the time it is turned off for, we can vary the brightness!! This nifty technique is called pulse-width modulation, or PWM.

OK... that's easy to understand. But how do we actually go about doing this?

Putting more current through them is easy – we just need to change out the resistor for something smaller. But, let's do this part at the end. This way, we can know everything is working before we risk the lives of our poor LEDs. The difficult part is, how do we flash them on and off gazillions of times every second?

There are a number of ways to do this. The cheapest (but not necessarily easiest, IMO) way is with a timer chip, like a 555, and a bunch of other components. However, here, I will choose a different approach. We have lots of BLING BLING features to add to this project, so hopefully there is a way we can find one general chip that can do everything we want for us – not just now, but down the road.

The good news is, there IS such a wonderful chip. A microcontroller. :idea: :P

A microcontroller is like a mini-CPU. We tell it what to do, and then it sits there and does it, over and over and over, without getting tired or asking for a pay rise.

Microcontrollers are everywhere – in your TV, your microwave, your mobile phones... inside my brain....oh no, wait, I wasn't supposed to let slip about that one. :twisted:

"But this all sounds terribly complicated", I hear you whingeing, as you try to slope off out the door unnoticed.... No, WAIT, COME BAAAACK.... IT'S SIMPLE, I promise. See, the great thing about microcontrollers is that they are so flexible. Because they can be told to do pretty much whatever we like, the circuitry we need to construct is comparatively simple! We don't need to buy billions of tricky little components to do one thing – just a few parts, and a bit of programming. Plonk down microcontroller. Connect up LED. Tell it to flash. Simple. Pretty much. :wink:

Specifically, we're going to use this chip: a PIC 16F628A, from Microchip. Despite having a dull name that would make it the least popular chip in the classroom, this cute little chip has it all: Low cost, easy to find, powerful, and it can do everything you need – including making coffee, massaging your feet, and solving world hunger. Really. And the little beast can process instructions 20 million times every second. (That's about 20 million times faster than my assistant. :lol:)

Here's a picture from the Microchip datasheet for this chip, showing the nifty little beast:

Image

Sexy stuff, huh?

Admittedly, a microcontroller is overkill for this simple PWM application, but, we will really make use of it when we get to the more interesting features later.

I've also searched high and low, just for you guys, to find ways that this can all be done cheaply! That's right! All the parts can be bought online for a few dollars, and you won't need to buy expensive software. And, once you're through, you'll be able to solve all your fishly problems with the stuff you've learned here. Not bad for free, eh?

In the next instalment, I'll go over the parts and resources needed to get cracking on this EXCITING NEW TWIST to the project! And then we'll start upgrading our boring moonlights into something worthy of these tediously long posts.

You're still with me, right?

WATCH THIS SPACE!!!!!
Last edited by PetPirate on Mon Nov 14, 2005 9:43 am, edited 3 times in total.
Created a User Gallery yet? Go On!

Affordable Metal Halide Lamps: http://www.petpirates.com
User avatar
Sari
Dwarf Puffer
Posts: 67
Joined: Sun Jun 05, 2005 12:44 am
Location: The Canadian Prairies

Post by Sari »

Hehe.... hard. core. :twisted:
When life gives you lemons, make grape juice.
Then sit back and watch as everyone tries to figure out how you did it.
Jager

Post by Jager »

OK Jhong me think we need to do the next section on neon el wiring up your puffers :shock:

j/k but it is nice to see a helpful guide so ppl dont have to spend 30-40 bucks for a premade led set....

now where is my soldering gun OWWWW..........

found it.. grumble grumble
8)
User avatar
PetPirate
Gone Today, Here Tomorrow
Posts: 1230
Joined: Mon Jun 27, 2005 5:41 am
My Puffers: 3x Tetraodon Nigroviridis in full marine
Location: Shanghai, China
Contact:

Post by PetPirate »

LOL

Just wait til you see the next part........ :shock:
Created a User Gallery yet? Go On!

Affordable Metal Halide Lamps: http://www.petpirates.com
User avatar
PetPirate
Gone Today, Here Tomorrow
Posts: 1230
Joined: Mon Jun 27, 2005 5:41 am
My Puffers: 3x Tetraodon Nigroviridis in full marine
Location: Shanghai, China
Contact:

Post by PetPirate »

I'm busy trying to figure out the finished product so I can take us through each step without messing up....

The next part is going to be a long one as I have to introduce all the components... it really will be the biggest "learnin'" installment. But don't be deterred! It's all downhill after that!

WATCH THiS SPACE!!!!
Created a User Gallery yet? Go On!

Affordable Metal Halide Lamps: http://www.petpirates.com
YBeNormal
Former Staff Member
Posts: 506
Joined: Sat Jun 04, 2005 1:19 am
Location: Northern Virginia
Contact:

Post by YBeNormal »

It may be "downhill" for many of us before we even get started! :lol:

Seriously though, excellent write-up and (so far) not too intimidating. I'm going to wait for the final installment before I begin working this project though--so I only have to make one trip to Radio Shack!
User avatar
PetPirate
Gone Today, Here Tomorrow
Posts: 1230
Joined: Mon Jun 27, 2005 5:41 am
My Puffers: 3x Tetraodon Nigroviridis in full marine
Location: Shanghai, China
Contact:

Post by PetPirate »

Good idea... no worries, at the end I'll post a full parts list for the whole thing.
Created a User Gallery yet? Go On!

Affordable Metal Halide Lamps: http://www.petpirates.com
Quaid
Puffer Fry
Posts: 34
Joined: Fri Nov 04, 2005 10:12 am

Post by Quaid »

Wicked, I love the bit about pulsing the LED's, I didn't know that even from electronics class!

However, isn't it proper to use red LED's for night viewing since it is almost invisible to the fish and doesn't disturb them? It is true that blue shines the deepest, but it is also the most visible and to the fish is supposedly just like having the lights still on!
Colomesus asellus (SAP) [RIP]
Tetraodon travancoricus (dwarf puffer) [RIP]

Ancistrus sp.(4) (Albino Bristlenose Catfish)
Otocinclus
Jager

Post by Jager »

actually no. red does not bother the fish as much, however deep blue light is literally what the moon light is under water. it also does penetrate the best so that corals anemones etc can know when to spawn :P
User avatar
PetPirate
Gone Today, Here Tomorrow
Posts: 1230
Joined: Mon Jun 27, 2005 5:41 am
My Puffers: 3x Tetraodon Nigroviridis in full marine
Location: Shanghai, China
Contact:

Post by PetPirate »

^^ What he said.

[AFAIK]....Traditionally, it is thought that fish can't see red, because there isn't much red light at depth (this view is being challenged, however, as many creatures show brilliant red colours... pointless if nothing can see it!). However, we *want* the light to be visible. Just a little. The idea here is that you can't clearly see the effect with the room lights on. Very subtle.
Last edited by PetPirate on Tue Nov 15, 2005 12:18 am, edited 1 time in total.
Created a User Gallery yet? Go On!

Affordable Metal Halide Lamps: http://www.petpirates.com
User avatar
PetPirate
Gone Today, Here Tomorrow
Posts: 1230
Joined: Mon Jun 27, 2005 5:41 am
My Puffers: 3x Tetraodon Nigroviridis in full marine
Location: Shanghai, China
Contact:

Post by PetPirate »

I'm back!!! This is going to be a LOOOOOOONG post..... We're going to need a few components for the next step.... The theory looks tough, but trust me, it's not... nothing ever makes sense until you do it in person. If this bores you, then sit back and wait for the next step, and see how easy it is to build it! In the next post, I'll show exactly what to order and how to put them together. It is not hard. :P

However, my aim here is to explain in detail the parts we need, and why, to (hopefully) help it all make sense. Should be more fun if you know what you're doing. The circuit diagrams may start to look a bit complicated, but TRUST ME, as the SIMPLICITY WILL BE REVEALED in the next post, this is actually VERY EASY to build!! :D

First things first... the microcontroller:

Image

What's that? Yep, you guessed it... The chip runs on 5V! :shock:

This is the first thing we need to worry about. Our moonlights run on 12V, but our dandy microcontroller (MCU) runs on 5V. Supply it with 12V, and you'll let the "magic smoke out". Very cool , but not really what we want here. :cry:

So, how do we deal with this mismatch? :?: :?:

We need to use something called a voltage regulator. This little thing's job is to convert one voltage to another. In our case, it will take in 12V, step it down to 5V, and throw away the excess power as heat. (not to worry, our circuit will not use much power).

Image

Looks simple enough, eh? :?:

It's not quite done though. Just like our fish, it's important that we provide our chip with STABLE parameters. The voltage regulator, by itself, will not tend to be very stable... it will produce "ripples" in the voltage. We need to find a way to smooth these ripples out. To do this, we use a couple of cheapo capacitors. The job of these capacitor is to "filter" the voltage across them, making our voltage levels all pristine and dandy. :P

Here's what it looks like with two caps connected (I've labelled them C1 & C2) Note the symbols for the caps – it matters which way round they are connected. The body of a capacitor has markings (usually "minus") to show you which way round it goes. :!:

Image

And here's where we put it in the circuit... see, now we plug in the "wall wart", and can provide 12V to the moonlights, and 5V to the MCU. Brilliant!!! :P :P :P

Image

Unfortunately, there are a few more things we need to do to make the MCU actually work. :evil:

Consider this: the MCU runs at 20 million cycles every second. As it rushes around switching things internally on and off, the power it draws can change very rapidly from moment to moment. But the changes occur on a very short time-scale. This can place dynamic demands on our regulator, and the voltage can fluctuate faster than the capacitors we included can handle. Very small capacitors are better at filtering such fast changes. So we need to put a small capacitor (C3) very close to the power pins on our MCU. This capacitor is so small, it doesn't matter which way round it is connected:


Image


There's one more thing this MCU needs. :twisted: It needs a clock. No, not a clock for telling the time (that comes later) – but one so it knows when to do things. Then, whenever the clock "ticks", the MCU performs an instruction. There is a clock built into the MCU, but it's not very stable or accurate. For now, that doesn't really matter (what's a few million cycles between friends?), but down the road it will be more important to us. So, let's do it right now and put in an external clock source.

For this, we use a crystal, just like in your watch. The crystal, is just as it sounds – a piece of quartz. When electricity is applied to it, it vibrates at a very predictable frequency. This frequency acts as the "clock", vibrating exactly 20 million times every second. The MCU picks this up and knows when to do stuff. Phew. 8)

So now, our circuit looks like this:

Image

It's not quite complete like that..... You guessed it – the crystal is not terribly stable. Again, a couple of tiiiiny capacitors connected to ground on each side of the crystal will save our bacon. Like so:

Image

In the diagram, I've labelled the crystal "XTAL", and the new capacitors C4 and C5.

YOU TOLD ME MY SMELLY AUNT AGNES COULD BUILT THIS!!! YoU LYING SCUM!! THIS LOOKS COMPLICATED!!

:( Not to worry. Really. These are all small components. In the next post you'll see what I mean... you could lose these parts amongst the lint in your pocket. Couple of dabs with the soldering iron, that's all this is. I promise!

There is one thing we missed out though:

Image

Duh! That's right. The MCU is not yet controlling the lights. The MCU gets its nice 5V, and the moonlights get 12V, but they are always on. The moonlight needs to switch that 12V on and off to the lights whenever we want. We need to find a way to switch on and off the 12V going into the moonlights with a 5V MCU.

For this, we need a transistor. :idea:

A transistor is the granddaddy of all modern electronics – all chips are built with many, sometimes millions, of transistors in different configurations. Here's a transistor:

Image

For our purposes, the transistor is really a very simple device. Honest, guv. Put a small current in at its base, and it conducts current from its collector to its emitter. It's like an electronic switch that can "bridge" between two voltages.

If this sounds a bit complicated, don't worry. It's simple to wire up. Here it is controlling our moonlights.

Image

As with the LEDs, the resistor is there to limit the current going into the transistor. Same ole' same ole'.

And HERE WE ARE, with EVERYTHING put together. Of course, all the "0V" connect together.

Image

AND THAT'S IT That's the biggest amount of theory and pictures I'm gonna make you look at.... I PROMISE!!!! It's all DOWNHILL from here! All the future steps will be MUCH more straightforward, don't worry!!!!

I'll be back in a jiffy with pictures showing exactly what all these parts are, and how to wire them up so they can play together!!
Created a User Gallery yet? Go On!

Affordable Metal Halide Lamps: http://www.petpirates.com
YBeNormal
Former Staff Member
Posts: 506
Joined: Sat Jun 04, 2005 1:19 am
Location: Northern Virginia
Contact:

Post by YBeNormal »

You're not foolin' me. There's tons o' white space left on that diagram and I have a feeling that you're a gonna fill it in, right?

Seriously though, is all of this hanging loose in the project box or mounted on a project/circuit board of some type?
User avatar
PetPirate
Gone Today, Here Tomorrow
Posts: 1230
Joined: Mon Jun 27, 2005 5:41 am
My Puffers: 3x Tetraodon Nigroviridis in full marine
Location: Shanghai, China
Contact:

Post by PetPirate »

Would I do that to you???

It's all going to be held together with electrical tape and chewing gum. No worries. :lol:
Created a User Gallery yet? Go On!

Affordable Metal Halide Lamps: http://www.petpirates.com
Post Reply