Making Magnificent Moonlights
- 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:
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.
I'm afraid there's going to be a bit more THEORY
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:

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?
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:
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.
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.
"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.
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.
)
Here's a picture from the Microchip datasheet for this chip, showing the nifty little beast:
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!!!!!
The next feature we're going to add will be SUPER BRIGHTNESS and a nifty dim-on and dim-off effect.
I'm afraid there's going to be a bit more THEORY
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:

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?
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.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"
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.
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.
"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.
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.
Here's a picture from the Microchip datasheet for this chip, showing the nifty little beast:
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.
-
Jager
- 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:
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!!!!
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!!!!
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!
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
Tetraodon travancoricus (dwarf puffer) [RIP]
Ancistrus sp.(4) (Albino Bristlenose Catfish)
Otocinclus
-
Jager
- 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:
^^ 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.
[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.
- 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:
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.
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!!
First things first... the microcontroller:

What's that? Yep, you guessed it... The chip runs on 5V!
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.
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).

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.
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.

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!!!

Unfortunately, there are a few more things we need to do to make the MCU actually work.
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:

There's one more thing this MCU needs.
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.
So now, our circuit looks like this:

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:

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:

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.
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:

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.

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.

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!!
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!!
First things first... the microcontroller:

What's that? Yep, you guessed it... The chip runs on 5V!
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.
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).

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.
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.

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!!!

Unfortunately, there are a few more things we need to do to make the MCU actually work.
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:

There's one more thing this MCU needs.
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.
So now, our circuit looks like this:

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:

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!!
There is one thing we missed out though:

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.
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:

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.

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.

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!!

