Archive for the ‘Circuits’ Category

Binary Clock II with ATmega32

leave a comment »

I made this binary clock to learn how to use Eagle and go through a real PCB ordering process. Until I made this clock, all my PCBs had been made through ExpressPCB. ExpressPCB’s PCB ordering process is very easy but their PCB design tool is not as advanced as Eagle, puts out proprietary files, and is not well used by the PCB community. In addition their PCBs are a little on the expensive side at $51+shipping for 3 boards although you do get them in 1-2 weeks.

For this project I had the PCB manufactured by BatchPCB – a service run by SparkFun.  However, since then I’ve switched over to OSH Park.  OSH Park has much better looking and higher quality PCBs than SparkFun.  In addition they are purple and come with nice looking gold plating.


The clock layout is very simple since this was a beginner project. Most binary clocks represent the time in binary-coded-decimal (BCD) format where each digit in the time is encoded as a binary number. I chose to do a full binary clock where the entire hour (or minute, or second) is displayed in binary.

Putting the schematic together in Eagle was easy and so was laying out the PCB. I took the easy way out and used the autoroute feature to lay the traces. The autorouter isn’t very smart and I recommend against it, it routed several traces under the small 1206 parts and inserted vias where it was very easy to bridge them to pads with solder.

A few places that I screwed up was in connecting the LEDs to the IO pins and not putting in a screw down terminal connector for the input power. I randomly assigned the LEDs to various pins and this made addressing them difficult when writing the code.  For the input power, I figured that I would just solder the power adapter directly to the voltage regulator pins (7805).  I found out the hard way that this is not a very secure way to tie down the supply and it made re-using the supply difficult because I now had solder on the tips of the wires!


I based much of the code on a binary clock I made a while back.  I set up timer1 to overflow every 100ms and increment the seconds every 10 overflows.  I increment the minutes and set the number of seconds to 0 when seconds is greater than 60,  and increment the hours when minutes are greater than 60.  Updating the display only needs to be done after you increment the seconds.  I also did a crude PWM where I toggled the LEDs on each overflow to reduce power consumption.

You can download the code here.

Layout view:

The schematic is not very interesting, so here is the layout.  I have four buttons to set the time; the ATmega32; 6 LEDs per for the hours, minutes, and seconds; a 6 pin AVR-ISP header; and a 7805 voltage regulator.  I initially thought about powering the device via USB – There are pads for a USB socket – but I never got around to it.

Parts list:

Quantity Part Name Description
18 1206 100ohm resistors current limiting resistors for the LEDs
18 1206 LEDs For the display. Mine are blue.
4 Momentary on Omron switches Part name: B3F-10XX
4 10KOhm resistors pull up resistors for the switches
1 ATmega32 Microcontroller
1 2×3 header AVRISP connector
1 7805T 5v Power regulator
1 USB header USB header as alternate powersupply – not used
misc capacitors Used for AC bypass and switch debouncing

Eagle files:

You can download the eagle files by clicking here.

Written by M Kapoor

June 27, 2013 at 6:44 pm

How a Joule Thief Works

leave a comment »

A Joule Thief is a small low power circuit that uses up almost all the energy stored in its power source.  The circuit is based on the Boost DC-DC converter where the output voltage is higher than the input voltage.  The circuit below is a type of Joule Thief that does not require a ferrite toroid core inductor.

How it Works:

Looking at the schematic below – transistor T2 switches inductor L1 between ground and capacitor C1.  When connected to ground, L1 charges up.  When connected to C1, L1 acts as a current source and forces charge onto  C1.  This continues until node N1 is charged up to the Von of LED1.  This lights up LED1 until the current flowing through the LED discharges node N1 to below its Von.  This happens very fast (at several KHz) so to us it appears that LED1 is always on.

T2 is controlled by transistor T1.  T1 is in a negative feedback loop through resistor R3.  Now, VCC is divided between resistor R2 and resistor R3.  As the voltage across R2 increases, the voltage across R3 will decrease and vice versa due to the voltage divider they form.  This increase and decrease across R3 switches T1 on and off.  As T1 switches on and off and the voltage across R2 varies.  This voltage change at the base of T2 switches T2 on and off.

Building it:

Unlike the other examples available online, I decided to make a board that did not require me to wire up additional components.  My board contains the entire circuit as well as a AA battery holder.  An AA battery is not required, the circuit should work at voltages up to 3v.  A battery that is almost depleted will also work – so you can take the dead battery out of your flashlight and use it in this circuit to get some more usable light.

With a good battery the circuit runs for about 10 days at full brightness and then slowly dims over the next few days.  I’ve been able to get two full weeks (day and night) of usable light.  This is a great circuit for night lights, emergencies, and camping.

Click to enlarge:

Building Your Own
Interested in building one? Eagle schematic and brd files available on my BitBucket page:

Written by M Kapoor

August 8, 2012 at 2:25 pm