Sunday, December 22, 2013

Traffic Light

[Editor's note. This is a post that I started almost 3 years ago, I'm making an effort to purge or polish some of the unfinished or unworthy posts on Bytecruft]

This is a traffic light I made for my kids. It's got a ATtiny 13 driving the leds. It also features a "soft" on-off circuit   driven by a tactile momentary push button.

I know, another AVR LED based project. They're so easy. I swear, I work on more than LEDS and with chips other than AVR's. It's just that the AVR ones tend to get 100% finished. Part of my hopes for this blog is to provide motivation to finish a couple of the unfinished projects I have. Actually, looking back, it's not so much a problem of motivation, but time. I usually "multithread" my projects, work on several at once, to keep form getting burned out or over-obsessed with one. Sometimes, before I know it, a project hasn't been touched in a couple months.

This is a project I did for my kids, it was another one of those "in between" projects, where my goal was to make a small project that would be lightweight after working on something big.

Present-day action shot, I finally replaced the 3+ year old batteries
during the teardown/photo shoot for this.

The real neat trick with this project, in my opinion, was the power management.



I wanted to make the light not reliant on my kids to turn the light off when they were no longer using it. I needed a way for the device to turn itself off after a certain length of time. I happened to have some CMOS based logic chips laying around. One of the great things about CMOS chips are that they tend to have low quiescent current draws, often measured in nanoamps. I was able to build a power control circuit using a J-K flip flop, a ripple counter, a non-inverting buffer, and a couple of mosfets.

Here is an approximation of the schematic (recreated from breadboard pictures, I lost the original hand sketch :( )


"Soft power" circuit. This is somewhat of an approximation, not the exact circuit I used. For example, my "3.3V" is really 3 AA batteries, ~ 4.5V



Here is a list of the chips used:
U1A, U2A = HCF4050BE (Non-inverting hex buffer)
U3A = CD4060BCN (12 stage binary ripple carry counter)
U4A = 74HC112P (Dual J-K flip-flop)
U5 = AtTiny13 microcontroller.


The basic premise is this: There is a "switched" ground line that is controlled with mosfet Q2 (I used a 2N7000, more than capable of handling the ~ 60 mA operating current). The flip flop, buffer, and counter IC's run straight from battery power, in a "off" state of the traffic light, these chips draw negligible current. When the push button is pushed, the flip flop sees a negative edge, and toggles it output, turning the device off or on by activating Q2.

So what's up with the counter? The counter helps the microcontroller activate a "virtual on off switch". Since  using an 8 pin AVR chip left me with no free pins, I had to be resourceful to have a way to programmaticly activate the flip flop. I used all 6 outputs on the tiny, one for red, yellow, green, in each direction. I routed one of the outputs to the counter input in addition to the LED. I did the same to the reset line on the counter. In normal operation, whenever light "yellow 1" on PB4 transitions negative, the counter is incremented. When light "green 1" on PB3 goes high, the counter is reset. I.e., the counter never increments, since it is reset every cycle. When it's time to turn the device off, I simply toggle the yellow light rapidly, incrementing the counter until the count gets high enough to bring Q4 high. The toggling happens too fast for the human eye to see, so the device just appears to turn off. 

That's really the most notable part of the project. The rest is just a mini-storage box from an office supply store, and some PVC piping. Oh, and glue, lots of miserable, messy glue.


The inside. The battery holder had come loose... again. Have I ever mentioned I hate glue?
Also, after 3 years, there is a white residue on everything, notice the batteries.I suspect the residue is some reaction with the glue
Strategically placed and glued Shapelock form a restraint system to keep the circuit board in place.
Action shot of the circuit board. One amusing thing I noticed in looking back at this project from early in my maker days is that I used electrical tape instead of heat-shrinking.

--P

No comments:

Post a Comment

I welcome you're thoughts. Keep it classy, think of the children.