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