Happy holidays! (Christmas project 2015)

Last year’s Christmas holiday project was the “Make A Wish” fountain show. My original plans for this year was to follow it up with an updated set but I couldn’t find the time or motivation to do it. Instead, I decided to do something simpler.

20151222_190705_001Behold! A modern-style Christmas tree! It’s made out of foam-core board and has eight sides which are lit up by WS2812B addressable LEDs.20151222_190631With the room lights off, you can get a better sense of what I was going for. I am very happy with the way that it came together, considering how little time I gave myself. This was almost all done on a Sunday.20151221_193338It’s one of my larger projects, with the base being 50x66cm and the “tree” standing at 52cm. I’ll have to find somewhere to put it because I would love to work with it next year.20151222_190933_022One amusing observation which I hadn’t planned for was the fantastic pattern the project projects onto the ceiling.

Thanks for visiting my blog! I hope to find some time to write up a year-in-review-style post as I did last year. Stay tuned!

DIY Bluetooth Speaker!


After weeks of waiting, the parts I needed for a homemade Bluetooth speaker arrived. Pictured above are the PAM8403 amplifier board, Bluetooth module (USB powered with a 3.5mm audio jack), and a couple of 3-watt speakers. The power supply is a 5V 2A power supply I had laying around. All of the project materials amounts to roughly $13.

I got the inspiration from a couple of my favorite YouTubers — GreatScott and David Watts. They had much more polished finished products with a good quality speaker and cool enclosure… I had neither of those.

The project itself was simple enough: Break open the Bluetooth module, apply power to it, and then take the audio signals to the amplifier which would drive the speakers.


Here’s the Bluetooth module cracked open. My original intention was to remove the audio jack and USB plug to end up with a flat board, but the desoldering did not go well as I didn’t have any solder wick. After some failed tries with my desoldering pump, I ended up cutting off the edge of the board with the USB plug, and giving up on removing the audio jack. There were two copper pads near the USB plug that were labelled Vcc and Ground so I used them to apply power instead of bothering the with the pads of the USB plug.


Wiring it together did not go as simple as I thought it would either. I tried connecting wires directly from the pins of the audio jack to the amplifier board, but it didn’t work. The audio jack was still working with headphones, and the speakers worked faintly when connected directly to the audio jack. (The speakers arrived a bit banged up so I was worried they may have been broken.)

After some time troubleshooting, I ended up replacing the PAM amplifier board (I bought a few, exactly for situations like this) and spliced the included 3.5mm audio jack cable and used that to connect to the amplifier board. I was so happy to hear the power-on tone that the Bluetooth module makes!


After some playing around with it, I realized that there was only static coming out of one of the speakers so I chopped that one off. I’m not a audiophile by any means so I’m easily impressed… I was pleasantly surprised in the audio quality from these cheap speakers. Even with just one speaker, it can get pretty loud without sounding bad.


Time to put everything into an enclosure! This was my first time using foam board. If I didn’t use foam board, I’d still be using cardboard. Now that I’ve given it a chance, I can definitely see foam board being my go-to material for this sort of thing. My cuts are a little rough but I learned later on that using a new blade and/or cutting at an angle will give you cleaner cuts.

I used some needles to keep the foam board in place while I used hot glue everywhere.


Once I was finished putting it together, I printed out a simple nameplate for the speaker.

The Bluetooth module board has a blue LED that blinks rapidly when it isn’t connected, and once every 3 seconds when it is. Honestly, it wasn’t intentional, but my design with raised bottom, which was intentional, worked in the LED’s favor as it gives it a neat glow underneath the speaker. The nameplate originally had a note about how the rapid blinking meant it wasn’t connected, but my printer wasn’t having it…

So that’s it! It only took me half the day from start to finish and I am satisfied with the final product. I hope you’ll take this post as inspiration to whip up your own Bluetooth speaker!

Thanks for reading!

Clock Project Journal Entry #2: Get on with it

In the first journal entry for my clock project, I introduced the purpose and general idea of the project. It’s simple, but it’s been dragging on for weeks. The schematics and PCB designs have been tweaked many times since the first draft. I’ve been hesitant to call them complete because of my unfamiliarity with the DS3231 real-time clock, and because it’s my first time making my own component parts in Eagle. After some focused work today, I’ve sent the boards off to be made.

There are a couple of aesthetic aspects to these PCBs that are new for me: Larger size and different color. Both the control board and display board are larger than the 5x5cm (or less) size that I was always aiming for before. The larger boards give me a lot more room to play with when I’m routing the connections. It also lets me breathe a little easier knowing that the text sizes should be large enough to read… I’ve have cases where I made text too small just because I didn’t have space for anything larger. The boards will have black soldermask because I think it will make the LEDs stand out more and will hide the control board a little better. I’ve always gone with blue before.


As I mentioned earlier, this will be my first PCB with custom made parts designed in Eagle. The two parts that I made were for the power switch and the DS3231SN IC. The power switch is a tiny slide switch that I ordered a bunch of a while back. They’ve always been hard to use because of their somewhat odd form factor. The pins are tiny, it has two thick outer support pins, and has a 2mm pitch so it isn’t breadboard-able. I ordered digital calipers just to measure the switch’s pin thickness. Hopefully I got it right. If it turns out to be fine, I’ll probably make another PCB order for some breakouts for these switches.

The DS3231SN’s datasheet links to another document for its land pattern, which shows the spacing and sizes of the pads. The land pattern is clear so I’m confident that I made the part right in Eagle. Time will tell!

Since Eagle limits board sizes and the price for anything larger than 10x10cm would probably be too expensive anyway, I could only fit two digits on a board for the clock’s display. Each segment is made up of two parallel branches with a resistor and two LEDs in series. The resistor I plan to use are 1K 0805 surface-mount resistors. I tested them out in this configuration on a breadboard, thanks to my own 0805 breakouts. I chose the relatively high value of 1K because the brightness seemed to be just right, although it could still feel too bright when the entire display is put together. Time will tell on that as well.

I’m still trying to decide how I will put the two panels together. I want to have the colon in the middle of them, whether it’s made of LEDs or not doesn’t matter to me. I also don’t have much of a plan for an AM/PM indicator so the project may start off as a 24-hour formatted clock and be changed to a 12-hour clock in the future.

As you can tell, I’m still trying to get things sorted out even after the project milestone of getting the boards made being surpassed. I ordered the components for this project a couple of weeks ago from China so I hope they arrive soon. There are also a few components I’ll purchase locally when the other things start to come in.

Thanks for reading!

Clock Project Journal Entry #1: What is it, and what’s the point?

One of the things my desk is missing is a clock. Yes, I have a computer, watch, and phone that can all tell time, but when I’m in a full-screen game, I don’t want to have to go looking for the time. I’d rather have a clock large enough that I can simply glance at. First world problems, I know, but in any case, I thought that this would make for an interesting electronics project, despite how simple it may sound.

I will be making two custom circuit boards for this project. One will be the control board and the other will be the actual LED clock display. The project will be controlled by at Atmega328p microcontroller and the time will be kept by the DS3231 real-time clock chip. The LEDs will be driven with the help of some 74HC595 shift registers since it should make programming easier as opposed to multiplexing… I always gravitate toward using shift registers, I guess.

One of the things I wanted to make sure of was the LED configuration. As it sits now, each segment will have 4 red LEDs. At first, I tried driving them at their “full” 20mA each (so 80mA per segment) but I felt that it was too bright. Bumping up the current-limiting resistor brought it to a more comfortable brightness. With the higher resistor, the current drawn for the segment was about 4mA, which is low enough for a pin on the shift register to handle directly. With that, I don’t need any transistors, which makes me happy…

I was planning to use a single resistor for the four LEDs on each segment, but it’s bad form and I don’t want to go that route for the whole project. I already feel “guilty” about using shift registers instead of just multiplexing. I will be putting a resistor for each LED. The main reason why I wanted to go with the one resistor per four LEDs is because it saves space without having to go with surface-mount components. I’ll see how the layout goes with the 1/4 watt resistors and hope that I don’t have to go and get some surface-mount resistors. I’d like to use whatever I already have.
ds3231rtc_sch_1Here’s the schematic for the control board. The board layout is done, or at least the first draft of it is. The only thing left to add is a switch to either cut the power to the project or at least turn of the display. I haven’t decided yet. I’m planning on using some mini-slide switches I bought a long time ago but I need to create an Eagle part for it which may take a little time. I’m waiting on some digital calipers from Amazon so that I can measure the pin thickness.

The layout for the display is coming along slowly. There’s only enough space for two digits per board, which is not a bad thing since I could use them for other projects. The problem that does arise from not making them specific for the project is that I have to make a separate circuit board for the colon and AM/PM indicator (I don’t really want a 24-hour formatted clock).

That’s all I have to share for now. I’ll be back with more when more details get finalized. Stay tuned!

PS. I started working on this project about a week or so before Ahmed Mohamed’s clock incident happened. I found that to be a funny coincidence.

See you later, Active Surplus.

Active Surplus is one of those stores that you could spend so much time in just to browse. They have a stock of electronics gadgets and parts, as well as an assortment of just… things. Recently, they announced that both their Steeles and Queen stores would be closing. They’ve been around for decades so it’s a tragic announcement for those who visited for all these years.


For me, I only discovered the store a couple of years ago and have only visited the Queen location a handful of times and the Steeles one once. Each time, I wandered around in awe of all of these neat parts, while reading all of the quirky product labels. I never actually purchased anything from Active Surplus since I was strapped for cash those times I visited (ie. unemployed) and didn’t want to end up with random things I wouldn’t use. I was planning to go today but I scrapped those plans because I didn’t have the energy to take the trip downtown, and because I’m trying to get rolling on a couple of projects, in between playing Cities Skylines…

Anyways, it sucks to see them go. From what I gather, I take it that they will reappear again in the future so there’s still hope. In the mean time, I have Sayal, a chain electronics store in the Greater Toronto Area. There’s also the online stores like Dipmicro and Chinese eBay sellers.

Do you have any cool stores in your area like Active Surplus? Share in the comments!

Thanks for reading! Stay tuned for some upcoming projects!

This battery was excited to see me


I have a small area on my desk for batteries of various sizes, including these 9-volt batteries. I came home one day last week to see one of them popped its lid… I’m not sure why. There was nothing across the terminals or nearby that would short it out. I’m not sure if it slowly rose out of its casing like a growing flower but I’m glad that if it was violent at all that it wasn’t harmful to anything around it.

I had to share because it’s not something you see every day!

No Arduino Uno. No Arduino IDE.

Ditching the Arduino IDE

Some time ago, I started playing around with the Atmega328p microcontroller without the Arduino Uno board. Now it’s time to try doing the same on the software side, even as just an experiment. I’ve been getting started with AtmelStudio which allows you to program Atmel microcontrollers in C. I’m still not quite clear on what to call the Arduino programming language other than C, if not a simpler form of C because the Arduino language takes care of a lot of things for you to make it as easy as it is to program an Arduino.

I learned about microcontroller programming in college. I believe we used a PIC microcontroller for the labs so, while I recognize certain things, there seems to be a little variation in abbreviations. In the labs, the microcontrollers were part of a board my professor designed that had a bunch of peripherals like buttons, switches, LEDs, and an LCD. It was a very thorough course with loads of information to take in. I hope I can remember it all!

Anyways, I’d really like to continue playing around with it and see if I can make a full project with one of my Atmega328p boards programmed using AtmelStudio. I’m taking baby steps to get up to a good speed in AtmelStudio, and I hope that writing small tutorials on the blog will help me firm up my knowledge. If you spot anything that needs correcting, please leave a comment!

The rest of this post will introduce you to the little work I’ve done so far, and may be helpful for anyone else who may be interested in trying it out too.

Hello World!

I made two Hello World programs, with the help of a bunch of guides which I will link to throughout the rest of this post. Both programs blink a bunch of LEDs but using different methods. One uses a delay, while the other uses an interrupt routine.

USBtinyISP with AtmelStudio

AtmelStudio does not work right away with the USBtinyISP, which is what I used to program the Atmega328p. You must add it as an external tool. I followed this guide to add it to AtmelStudio. You’ll need to download WinAVR to complete the guide.

As the guide says, to upload code with the USBtinyISP, you must go to Tools>USBtinyISP (or whatever you named it). Just remember to build your code first before uploading it.


Using a Delay (and Beginner’s Introduction)

As I mentioned, I made two programs that blink LEDs. One uses a delay while the other uses a timer interrupt. Let’s first take a look at the delay version.

Screenshot (3)

The first line defines the clock speed, which is 16MHz. The next line includes io.h header file, which actually just includes the appropriate file for the project’s microcontroller (which you select when you create the project, in this case the Atmega328p) that contains definitions for register addresses and things like that. The third line includes delay.h header file which enables us to use _delay_ms(); to cause the delay.

Now, into the main program! But first, let’s talk about ports.


This is the pinout of the Atmega328p-pu. Some of the pins are labelled PBx, PCx, and PDx, where x is a number. These stand for PORTB, PORTC, and PORTD, which are 8-bit data registers where each bit is a pin. The pins on the uC aren’t exactly laid out as cleanly as an Arduino Uno when looking up and down the rows of pins, but you can always order them in a way that works best for you when you’re actually wiring up your project.

Anyways, back to the code. In the first two lines of code in our main function, we set all of the pins in PORTB and PORT D to outputs. This is equivalent to the pinMode() function of the Arduino which is used to set certain pins as inputs or outputs. DDR stands for Data Direction Register where setting a bit/pin in the DDR to 1 makes it an output and setting it to 0 makes it an input. To make things easier, I put it in hexadecimal format (“0xFF”). You could also write “0b11111111” which is the binary equivalent and is more helpful when pins in a port are a mix of inputs and outputs. The third line in the main function sets all of the bits in PORTD to 1.

Everything in them main function up to this point is like the setup() function in the Arduino IDE. This code only runs once when the uC is powered on. Everything in the while loop will loop forever, like loop() in the Arduino IDE.

We set all of the bits in PORTD to 1 earlier so that we can toggle all of the bits on PORTB and PORTD at the same time and they will alternate. If we didn’t set them before we started the loop, all the bits in both ports would be the same. In another case, we could put in some logic that would toggle or set all of the bits in PORTD to 1 on the first loop, but that’s unnecessary since we could do it this way.

The exclusive OR (abbreviated as XOR, symbolized as ^) operation can be used to toggle bits high and low whenever the line is executed. In this code, the bits in PORTB and PORTD are toggled, and then there is a delay set for 250ms on the last line of the while loop. It loops around and toggles all of the bits again, and so on.

Using an Interrupt

A lot of the core stuff was covered in the previous code section so I’m not going to go into as much detail for any repeating lines in this section. Also, I’m rusty when it comes interrupts especially so don’t quote me on anything. Check out this and this for the information that I used to help me get this working. Also see the Atmega328p datasheet.

This program sets up Timer1 interrupt so that the ISR, or Interrupt Service Routine, will execute every 250ms. Let’s go line by line where we initialize Timer1.

cli(); disables interrupts. This is used so that important code that shouldn’t be interrupted isn’t.

The next two lines set all of the bits in the TCCR1A and TCCR1B, or Timer/Counter Control Registers for Timer1, to 0.

See the large comment block for information on calculating the Output Compare Register (OCR1A) (“Compare Match Register” in the comment block).

The next line enables the Clear Timer on Compare Match mode, which clears the timer once a match is made.

The next two lines are to set the prescaler to 1024, which is a value that was used to calculate the value for the Output Compare Register. The following table, found in the Atmega328p datasheet, shows how to set the bits in the TCCR1B register to set the prescaler.

Screenshot (6)

The next line enables the Output Compare A Match interrupt.

The last line enables interrupts.

There’s nothing in the while loop since all of our code is in the interrupt routine.

The bottom of the code is the Interrupt Service Routine (ISR) which is the code that runs when there is an output compare match with Timer1. In the ISR, we toggle the bits on PORTB and PORTD like we did in the other Hello World example. The ISR code is run every time there is an output compare match, which is set to 250ms.

So, uh, that’s it.

Trying to write this post was difficult. I need some more reading up and experimenting to do. I hope you got something out of this, at least a link to somewhere that’s more helpful.

Thanks for reading!