Sunday, August 30, 2009

Toy Traffic Lights



This is something I've been meaning to make for ages. My kids love toy cars (ok, lets face it, all kids love toy cars!). There's been lots of car related fun in our household (some of which has been documented on filthwizardry: "Toy cars and trucks from recycling", "shower curtain village playmat" and "home made toy carwash") and one of the kids favourite pastimes in the car is to shout "RED means STOP!" and "GREEN: GO!" (as loudly as humanly possible). I figured it was about time I used this as an excuse to spend some time in the garage making something with flashing LEDs :)

Between Lin and myself we've managed to amass quite a bit of cheap 'junk' that can be hacked together for something like this. I was going to make something flimsy using a battery pack and a drinking straw, but I was persuaded to make something a bit more kid-proof using a dollar store wooden box, an Altoids tin and the tube from a black felt-tip pen. Here's a picture of all the bits (there are three 150 ohm resistors are missing):



The plastic domes are the discarded remnants of 25c kids toys purchased from a vending machine in our local Taqueria, they looked like they'd make good LED covers (and they were used as wheels in another crafty distraction: "Toy cars and trucks from recycling"). The chip is an ATtiny13.

First up was to drill some holes: two in the box, one on the side for the switch and one on the top for the pen tube; one in the base of the altoids tin (again, for the pen tube) and three in the back of the tin for the LEDs.

Then I painted it black.



The wiring for the base/box is pretty simple, just an AA battery pack wired to a switch with the main wires threaded out of the hole in the top of the box. I stuck the pen casing in at this point and threaded the wires through to the top.



Now it's time for the wiring.

First off, I hot glued the base to the Altoids tin. Then I glued the LEDs into their holes with the cathodes all facing in one direction so I could solder them together to form a ground rail.




I soldered on three, 150 ohm, resistors to an 8-pin dip socket (pins 5, 6 and 7), soldered the positive lead from the base to pin 8 on the socket. Then I connected the LEDs to the resistors and finally connected the ground pin (pin 4) to the ground rail. That's it!





When I was writing the code I didn't think ahead about which pins were going to be connected where in the final project and ended up with the red and green pins mixed up (in software), so the initial sequence was backwards; but then that's why I used a socket rather than directly soldering the uC ;). Easy to fix with a quick software update.

Here's the final working project (yes, the yellow works too, I just didn't take a picture of it):



I've included the code below. As always, it's pretty simple:

### code starts here ###
(I found a nice way of displaying code in blogger. I talk about setting it up here)

/*
* trafflic_lights.c
*
* Created on: Aug 29, 2009
* Author: Paul
*/
#include <avr/io.h>
#include <avr/delay.h>

#define RED_LED PB2
#define YELLOW_LED PB1
#define GREEN_LED PB0

#define RED_DELAY 10
#define YELLOW_DELAY 3
#define GREEN_DELAY 15

uint8_t i = 0;
uint8_t j = 0;
void delay_seconds(uint8_t pSecs)
{
for(i = 0; i < pSecs; i++)
{
for(j = 0; j < 4; j++)
_delay_ms(250);
}
}

int main(void)
{
DDRB = 0xFF;//set all to output

//start traffic light sequence
while(1)
{
PORTB = (1 << RED_LED);
delay_seconds(RED_DELAY);
PORTB = (1 << YELLOW_LED);
delay_seconds(YELLOW_DELAY);
PORTB = (1 << GREEN_LED);
delay_seconds(GREEN_DELAY);
}
}

Tuesday, August 25, 2009

Led camp fire



A few days ago I came home from work and was rather surprised to find a, full-sized, indoor camp-out taking up the living room... you have to see it to believe it (the original was bigger than the version above!):- filthwizardry.blogspot.com. Well, the kids loved it and my lovely lady inspired me to make a flame free campfire to add to the fun. I figured it'd be easy to do with a uC and a few red/orange LEDs -all of which I had lying around the place.

To get the basic set-up I cannibalized the innards of the glow in the dark balls project and jammed a few LEDs in the right places; this let me start messing with the code. In the second image you can see my test set-up. I ended up using my LED tester to provide power to the breadboard and my ATtiny header board for quickly cycling the code on the chip. I was happily surprised that both of these worked and were useful - I've been getting frustrated jamming frayed power leads into the breadboard and it'd only just occurred to me that I could use the LED tester.



All I wanted the code to do was randomly switch the LEDs on and off fast enough to mimic flickering flames. I messed around with the speed of flickering a bit until I was happy.

For those who are interested, I've included the code at the bottom of the page. It's a pretty simple affair. I take no credit for the random number generator, in the past I've just used library code for this, but I happened across that nice bit of code online and fancied using it (I think this is the original source but I found it here). The code is in a slightly incomplete state as I was also messing around with altering the delay between each set of LED updates. Shorter delays give the impression of an angry/quick burning fire and longer delays give rise to a soothing fire. I quite like the idea of having a random drift for the delay to make the fire more interesting, but got tired at around midnight and decided to simplify.

Lin suggested housing everything in the top section of a solar garden light case (which had been destroyed during a particularly energetic play-date). All that needed modifying was to add a small hole for the switch. I also cut down the LEDs so they took up less space and were more secure:



Then I added some protection to the top and a cardboard base to keep the innards in place (I used a hot-glue gun to secure both parts).



And that's it! Very simple.

Here's the contraption hidden in the kids camp fire waiting to be discovered:



and a little video of it in action:



p.s. anyone notice the freaky kiddie scarecrow in the first image? Have a look at the whole filthwizardry post, that thing freaks me out on a daily basis! I think it's the eyes... "she's got the cold dead eyes of a killer" ;)

### code starts here ###

/*
* candle.c
*
* Created on: Aug 21, 2009
* Author: Paul
*/
#include <avr/io.h>
#include <avr/delay.h>

/*
* pseudorandom
* return the next pseudo-random number (PRN) using a standard maximum
* length xor-feedback 16-bit shift register.
* This returns the number from 1 to 65535 in a fixed but apparently
* random sequence. No one number repeats.
*/
uint16_t randreg = 10;

static uint16_t pseudorandom16 (void)
{
uint16_t newbit = 0;

if (randreg == 0) {
randreg = 1;
}
if (randreg & 0x8000) newbit = 1;
if (randreg & 0x4000) newbit ^= 1;
if (randreg & 0x1000) newbit ^= 1;
if (randreg & 0x0008) newbit ^= 1;
randreg = (randreg << 1) + newbit;
return randreg;
}

int main(void)
{
uint8_t i = 0;
uint16_t j = 0;
uint8_t delay = 20;
DDRB = 0xFF;

while(1)
{
j = pseudorandom16();
for(i=0;i<5;i++)
{
if(pseudorandom16() > j)
{
PORTB ^= (1<<i);
}
}
_delay_ms(delay);
}
}

Monday, August 10, 2009

Home cooked PCB etching - part 1

I saw this excellent Instructables on easy PCB etching and have been itching to give it a try ever since. I popped into the local Radioshack to pick up the bits, but was dissapointed that they had neither the ferric chloride solution nor the copper boards. So, when we were up in Santa Rosa for the mini Maker's Fair (see Lin's blogpost for more on that) I ran into the Radioshack up there and was lucky (they'd only just restocked them). Tonight, after the battle of the bed-times, I thought I'd give it a test run. For a proper run, I'm going to have to decide on a board to make, get some transfer paper and print out the design at work (no laser printer at home).

The instructable mentioned that a sharpie should be enough to mask the board, so I drew out a test pattern:

Imaginative, eh? I guess I could have gone computer programing 101 and used "Hello World!" instead.

So, next step was to add ferric chloride solution to a sponge and get scrubbing. The only plastic gloves we've got in the house are 'small' so I figured I'd risk it and just try keeping my fingers out of the way as much as possible. I used a dollar store, sponge on a stick, dabbed on a small amount of ferric chloride solution and got scrubbing.

About 5 minutes later, nothing had happened. A bit of an anti-climax from the promised '"1-minute etch" but I persevered for a little while longer and added a bit more solution to the sponge. I couldn't tell if the black liquid that was forming was to do with the etching process, or if it was just me scrubbing off the sharpie marks...

Another 5 mins of scrubbing and a few more dabs of solution yielded a glimmer of hope:

You can clearly see some of the copper being cleared from the top of the board. A few more minutes and most of the board was clear. Being impatient, I stopped there and used a "Mr Clean magic eraser" to clean off the remaining sharpie marks (no nail polish remover in our house, but plenty of need for powerful grime removal ;) ).



Sweet! It works! Time to create something more functional!

Wednesday, July 8, 2009

Solar powered fairy lights

  
Yes, I'm going through a solar powered phase right now. I'll have used up the parts I bought from allelectronics.com soon enough & will have to move onto pastures new.

My lovely lady suggested it'd be nice to have some twinkling fairy lights in the kitchen; ideally, ones that didn't need to be plugged in to the mains. The simplest solution would have been to use a battery pack, but our kitchen gets a fair bit of light &, like I said, I'm in a solar powered gadgetry phase right now...

My ebay habit has brought me some colour changing LEDs (before I knew exactly what they did). These look like normal LEDs (two leads) but cycle through a few colours over the course of 15 seconds or so. I figured these would be perfect for the project, so I dug out 4 working ones (using the LED tester I posted about previously).

There are very few components for this (if you count the solar-panel/charger as a single component): 1 solar charging circuit, 4 colour changing LEDs, an Altoids tin, some wire and I used a couple of neodymium magnets to secure the tin onto the curtain rail in our kitchen.

The first thing to do is to cut the LED leads from the solar-charging circuit, this is where we'll attach the wires for our own lights. I also cut down the plastic 'pins' which hold the circuit board in place; this was to make the assembly fit nicer in the tin (and as an excuse for me to try out some new cutting disks for the Proxxon).

I then cut two strands of wire (about 1 1/2' each of red and black), marked where I wanted to place the LEDs/lights on the wires and striped away the insulation around these points. I ended up melting the insulation away with a soldering iron and then using a knife to scrape off the excess plastic. There must be a much better way of doing it.

Soldering the LEDs onto the wires was a little awkward, especially since I cut the LED leads down to about 1/3 cm to keep them close the the wires. I'm glad I decided to only put on 4 for this prototype! Hmmm... thinking about it now, I should have left the leads on and bent them around the other wires to hold them in place whilst soldering them, doh!

After soldering the LEDs, I drilled a couple of small holes in the Altoids tin, threaded in the two wires and soldered them onto the solar charging unit.
Slide everything into place and there we go:


My better half has been making lots of playdough for some lovely projects (see: Dinosaur Island and playdough rain table) as a result, we've used up a lot of food colouring. It turns out the bottles make quite good LED diffusers. The picture below shows the Fairy Lights in front of our kitchen window. I used two magnets to make the tin secure (the magnets are on the inside of the tin). I also ended up taking the lid off the tin and securing the solar panels in-place with a couple of elastic bands.


Saturday, July 4, 2009

Personal empowerment through skill acquisition (or how I fixed a Vtech Tote 'n Go)

Phew, what a poncy title! Well, that's me through and through :) But what I wanted to post about was how empowering learning something pretty simple like soldering has been for me.

The kids have been playing with various incarnations of Vtech laptops (ones that play 'learning' games to do with letters and numbers). Their first laptop, the Vtech Tote 'n Go, broke about 6 months ago, the speaker stopped working as did the mouse button. Normally, that'd mean landfill for this big bit of plastic, but, having learned a little bit of electronics, I took it apart to see if I could figure out what was wrong.

It turns out that the speaker wires had broken off and the small push button inside the mouse had broken completely. I got the speaker wire soldered back in place the same day, but the button fix had to wait a while. I was tempted to hack together some Frankenstein creation using the huge push buttons I bought ages ago, but decided against it (I'm sure the kids would have loved it though).

I recently found allelectronics.com (see the solar power upgrade to the fireflies) and, as part of the initial order, I bought some small push buttons which were exact matches for the one in the kids laptop. So I took a second stab at fixing it. I couldn't successfully de-solder the original button, so I just clipped it off, trimmed the leads of the replacement and soldered it in place.

All very simple stuff. I left the laptop out somewhere I knew the kids would find it and the next morning I hear our youngest waking up our oldest by crying "Carys! Carys! Come see! Come see! The monkey laptop! It's working!". It was lovely.

The shocking part of this is that our friends have the same laptop and it's mouse button has stopped working as well. I'll fix that one too, but it must mean that loads of these things become landfill just because a single button breaks...

LED tester


I have to be honest, I've not been very er... meticulous when it comes to keeping my LEDs in check. Let's be frank, I have a big mess of them and I've no idea which ones work or what colour they are. I'm about to start on a solar powered fairy lights project and realised I'd be spending a lot of time working out which LEDs were the ones I wanted (hence the subject of this post).

To date, I've been using a torn down dollar store hand fan for testing; I'll take a picture to show you what I mean:

It's not the easiest to use, but it outputs ~3V, has a switch and two leads (not obvious which one is positive and which one is ground though since they're both red). I ended up getting frustrated whilst holding the ends of the wires onto the LEDs and then switching over wondering if the batteries were dead, the LED was dead or if I was just crap at getting a decent connection between the leads.

Anyway, what all this blathering is getting to is that I wanted something simpler and more reliable to use. You know, something that doesn't make me want to throw it against the wall in frustration... I'd been messing with 8 pin IC sockets and perf board for other projects and realised that they are perfect for this as well. So I got together the old battery pack from the JarOFireflies prototype (which is why it has a magnet still glued on top), a small bit of perfboard, an 8 pin IC socket and 4, 330 ohm, resistors.

I soldered the resistors and socket onto the board at the same time.

I used the wires from the last resistor to solder all the connections on each side together forming two rails (positive and ground):

Then I soldered in the wires from the battery pack, connecting one to each rail, and voila!

The nice thing about this is that it's easy to check a single led without messing much with it's leads (since there's 4 holes a side, there's plenty of room) and it'll also accommodate, up to, 4 LEDs at a time:


This took about 20 mins to put together including frequent interruptions from the kids wondering what I was doing by myself in the garage.

UPDATE (2009-09-19): The resistor set-up I created is obviously crazy, I'm not sure what I was thinking (or not) at this point... The resistors should be separating pins 1 - 4 from the positive rail.

Wednesday, June 17, 2009

Solar powered fireflies

I've been wanting to make something solar powered for some time & figured the firefly kit would be perfect to upgrade to solar power.

I just came across some cheap, second hand, solar powered light fixtures from allelectronics, which is a great place to pick up bits and bats for your electronic projects. Here's the actual solar lights I bought - solar-cell w/charging circuit. As the description says, they come with two solar panels, an LDR, a charging circuit (including - old - batteries) and some LEDs (one LED with this particular one and three with a different product).



As you can see from the pictures, all the components are easily acessible; these seemed perfect for hacking.

My first attempt was pretty simple, I just de-soldered the battery wires from my old JarOFireflies project, snipped the leads to the LED on the solar light kit and soldered the two kits together (the leads to the LED actually have a + and - designation printed on the board).


The LED wires are solid core and quite thick so there's no worry about them snapping under the strain and it made positioning the firefly board easier too. Speaking of which, I cut down the board to a more reasonable size for this project.

I didn't know if the batteries on the solar kit were duff so I left the hybrid out in the sunshine for a full day to charge then brought it indoors to see if it works:


And it does! What a pleasant surprise for something to work first time!

I think I'll cut a hole in the original jar's lid and place the kit in it more securely. Might be nice just to put it out in the garden to confuse the next door neighbours cats who seem to prefer our back yard to their own...