Absolute Maximum Ratings

Home | Projects | Intersession | About

Stephanie | Magic Wand | Arcanum Mods | Paintzilla

Stephanie


Demo video

History

The boring part

Flashback all the way to 2003 or 2004 or so: a younger me discovers something called Microsoft SAPI. It's an API that reads an XML file of your creation and listens for the phrases listed in it. When it hears them, it notifies your program. It also does speech synthesis. I am intrigued, and attempt to make a volume control that requires no remote for movie watching with my girlfriend. The computer's synthesized voice sounds like the female version of famous astrophysicist Stephen Hawking. I name the program accordingly: Stephanie. However, without training (and with background noise from movies), the program doesn't work well. I abandon the project, but save the code. It stays in the back of my mind for awhile.

Flash forward slightly more to early 2006: I'm cleaning out the old hard drive for a fresh, clean install of Windows (mmmmm new Windows smell) and rediscover the code. I'm also taking my first electronics course, replete with a lab section, and seeing some cool electronics projects online. I wonder if I could build a basic avatar for my computer that would respond to voice commands.

The big roadblock is figuring out a way to have my software do something physical in the real world. Having no idea where to start, I of course turn to Google. The following summer, a bit of research reveals the world of microcontrollers to me, as well as information on RS232. Ebay provides a fairly cheap beginner's micro: the Basic Stamp 2. Perfect! I slowly build up my component stores and peck away at the programming. Soon, I have a blinking LED.

The Triac & Optopcoupler circuit I use for 120VAC
The Triac & Optopcoupler circuit I use for 120VAC

Somewhere along the way I wanted this avatar to turn the lights on and off. More Googling reveals a solid state alternative to relays: a Triac and optocoupler. I find that the Electronics Store at U of I has these components, so I puchase some and build the circuit. At this point, I have basic prototypes for code and hardware for most of what I wanted to do. Even with everything set up, though, I never really got working on it - until I discovered how important a flat surface can be! My parents got me supplies for making a workbench to fit my tiny apartment room. Over that break, my dad and I built it. I never realized how important a simple dedicated space is, but it did wonders for my hobby.

First iteration

Lights, outlet boxes, and a mostly static mask
Warning: May contain puns

The title's a bit of a misnomer because development on Stephanie is continuous, but once I got the workbench set up there was an initial spurt of action.

Project box for the light switch
Project box for the light switch

My first concern was the method of switching the lights on and off. The Triac circuit I had breadboarded could successfully turn a light bulb on and off using nothing but a 5V signal in the milliamp range that a BS2 pin can provide. But where would I connect that circuit to room lights? I toyed with building an adapter for the light socket, but then the bulb wouldn't fit in the lighting unit and I'd have to run a control cable along the ceiling. Since we had access to the breaker box in the apartment, I found it much simpler to put the triac circuit in series with the light switch that controls power to the lights. I kept the Triac circuitry in a small project box just outside the switch, with two wires that run power simply sliding under the switchplate. I used CAT5 cable for running the control signals to this and, later, other boxes all around the room. CAT5 is great! People are always busting cords and buying new ones instead of putting ends on, so they'll give them to you for free.

Light switch box open, showing triac (left) and optocoupler (right)
Light switch box open, showing triac (left) and optocoupler (right)

As an aside: My dad is an electrician, which had a lot of great benefits for this project. First, I had practice with working with 120VAC. If you're used to 5V, you need to know that this is a different beast. Don't EVER work in a box with live power; make sure it's off and double check it before doing anything. It can kill you quick.

The Triacs I used are MAC15A8s and the optocoupler triac-drivers were MOC3012s, and some NTE5047s (they have the exact same pinout). These components were available at the U of I's ECE store; fetching more required only a ten minute bike ride. They're fairly inexpensive (especially compared to relays), too.

Front of the outlet box circuit
Front of the outlet box circuit
Back of the outlet box circuit - each triac/optocoupler set has a couple of resistors
Back of the outlet box circuit - each triac/optocoupler set has a couple of resistors
Exploded view of an outlet box - Blue box with power cable and control port to triac/optocoupler circuit to outlet to faceplate
Exploded view of an outlet box - Blue box with power cable and control port to triac/optocoupler circuit to outlet to faceplate

The next step was to produce more optocoupler & triac circuits for controlling applicances. I wanted to make them more general purpose than the light switch. Once again, being an electrician's son had great benefits! My dad has plenty of the 3-prong outlets in stock, as well as boxes and faceplates to match. I also got some 3-prong power cables from him. Power comes into the box from that cable and feeds the triac circuit. I dremeled a hole in the side of the box to fit in some female header from Sparkfun.com (this stuff is great!). This is where the control cable plugs in. The triac circuit then connects to the actual outlet. All put together, it's like a small computer-controllable surge strip. Supply 5V to the box, and you can then set any input to ground to turn on the corresponding outlet. That way you can control lights, fans, air filters, christmas lights, etc. Very versatile!

The first applicance to get this treatment was my workbench surge strip. A floodlight at the top provides light to the work area and is also a great visual indicator of whether the workbench is on or not. This makes it a lot harder to accidentally leave a soldering iron powered on. Once again, my good friend CAT5 cable came in handy for running control cable between the computer and outlet box.

A couple boxes later and I had a fan, bedlamp, christmas lights & disco ball, and a couple of other lights from Spencer's all controlled by voice and the BS2.

Servo controlling Venetian blinds
Servo controlling Venetian blinds

Another room automation idea I had was controlling the blinds via voice. Because I was renting an apartment, I couldn't make major modifications to what was already there. I grabbed a servo modified for continuous rotation, some paperclips, a push pin, and duct tape. It was a stereotype of hacky construction (missing only chewing gum!), but the servo mount servoed its purpose just fine (see what I did there? eh?). By turning the rod attached to the servo, the angle of the slats can be varied from horizontal (full light) to vertical (no light). One of the best uses I got out of this was a Sunlight Alarm: I would set a time to wake up on the computer, and when that time rolled around my computer would slowly open the blinds. It wasn't enough to wake me up, but having sunlight in the room while you're still lying in bed is a great way to get the day started.

Front view of face with mouth open.
Front view of face with mouth open.
Side view of face showing mouth motor
Side view of face showing mouth motor

The next part of the project was building an avatar for Stephanie. I wanted to go for a mad science robot look. I really liked pictures of robot face prototypes with electronics sort of bursting from the back. I envisioned control wires coming out from behind a mask and running all around the room to control various things, looking like hair, or veins, or roots, depending on which analogy you wish to use. The face was easy enough to procure; Hobby Lobby sells basic androgenous masks. I also wanted a few animatronic features, like a moving mouth. For this, I took a geared DC motor out of a Billy Bass singing fish (these are an excellent source of basic motors for animatronic movements). It has a spring on it, so if you apply power it goes towards one position, and if you release power it goes back. Very simple to control. I then simply used an exacto knife to slice her mouth in the fashion of a ventriloquist's dummy and attached it to the movement on the dc motor.

Another animatronic feature involves a system I had previously devised for dealing with SAPI's false positives (the times it overhears a conversation or movie and thinks it heard a command). Stephanie spends most of her time in a 'deactivated' mode where she listensg for nothing but her name. Once she hears her name, she responds and enters an 'activated' mode. While active, she listens for any of commands. Saying "That's all" or letting her idle for a certain amount of time deactivates her. To show what state she's in, I put LEDs in her eyes. After all, what self-respecting robot doesn't have LED eyes? There needed to be material between the LEDs and the eye sockets in the mask to help diffuse the light a bit and to keep her eyes from looking beady. I had recently split open a blinking bouncy ball and found two portions to be the perfect size for this purpose. Yay providence!

There was a third (slightly smaller) portion of the bouncy ball that was also about the same shape. First, I thought to myself "Stephanie only needs two eyes." Then I thought, "buuuuuuut... three eyes has got to be better than two!" Taking a cue from Buddhism, the third eye went on Stephanie's forehead. Instead of finding the path to nirvana, however, it shows her inner connection to the room. When she turns something on or off, the orange LED behind it blinks.

Brain tray ejected
Brain tray ejected
Side view of the brain tray ejected
Side view of the brain tray ejected

When I was planning for the third eye, another thought came to mind. When they work on a robot in the movies, they always press a button, and then pieces fold, slide, and glow, fog billows out from an opening, lights dim, and the inner core is revealed. While most of these special effects were out of my budget, taking a dremel tool to an old CD drive yielded the perfect sliding mechanism. I then mounted the BS2 chip on a socket sitting on the dremeled-out CD tray just behind the third eye. Now the "eject brain" command slides the third eye out, revealing the micro behind it all. The inside of the head is also backlight with some red LEDs. During retraction, a small whisker switch (liberated from old electronics, of course) serves to stop the brain slider at the perfect spot.

The full setup.  This shot includes some features built later
The full setup. This shot includes some features built later

After getting the face together and the BS2 mounted behind the third eye, I thought about where to put the rest of the needed circuitry. I had been doing development on the Board of Education I got from EBay. As it turns out, taking a couple scraps from the CD player resulted in the perfect mount for the BoE right into Stephanie!

Next up was a method of mounting all of this somewhere in my room. I wanted to go for a 'disembodied' head look; I wanted the wires emanating from the avatar to be more prominent than whatever was holding it in place. I ended up finding a desk lamp with a swingarm. The swingarm lets me reposition the head easily and gives the whole thing a nice mad scientist feel. I feel that plugging in all the wires really achieved the effect I was looking for as well.

Improvements

Expanded outputs, H-bridge for brain tray
Breadboarding shift registers with LEDs
Soldering the expanded outputs board
Soldering the expanded outputs board
The new output board mounted onto Stephanie, above and to the left of the BoE
The new output board mounted onto Stephanie, above and to the left of the BoE

The limited IO on the BS2 quickly became an issue. To add supplemental IO, I started working with some 74164 shift registers I got from an EBay auction. The idea behind a shift register is that by sending data through the input lines one bit at a time, you can control eight output pins (on the shift register) using only three control pins from your micro. The data actually shifts along the pins in series as you put it in. This can cause issues with timing-sensitive circuits. I didn't think it would be a problem for simply turning things on and off - I found out later that I was. However, at first, I simply got the shift registers running a bunch of LEDs and then proceeded to solder a couple onto a circuit board. I used a big chunk of female header on this board - one row gives pinout to the sixteen outputs from two shift registers, one row provides 5V, and the other row provides ground. Female header is great!

You can see from the pictures that I don't much mind messy wires. I would argue that it helps for the mad scientist effect, but really, I just don't like taking the time to lay it all out nicely.

Latches hacked into the output board
Latches hacked into the output board
Stephanie tilts her head for latch installation
Stephanie tilts her head for latch installation

It didn't take long to discover that the timing on the shift register did indeed have a noticeable impact. Every time I turned something on or off, data would shift through all the pins, and I would hear the faint buzz of the overhead room light briefly. Everything worked fine, but it certainly couldn't have helped the bulb life. And I knew I could do better.

The solution to my problem was D-Latches. These have eight input-output pairs. When you pulse the latch, it sets the output high or low depending on what the input is. It holds the output there until the next time you pulse the latch, no matter how the input changes. By putting latches in between the shift registers and the actual outputs, I could shift data through without disturbing the outputs, and then latch the data out all at one time. Since I didn't feel like resoldering the whole board, I wired them in dead-bug style. Somewhat crude, but it's worked fine ever since!

Base resistors for the H-bridge.  Soldering is hard with a tip that blunt
Base resistors for the H-bridge. Soldering is hard with a tip that blunt
There are a few things that I am inexplicably obsessed with.  Zombie apocolypses are one.  Mechnical arachnids are another.
There are a few things that I am inexplicably obsessed with. Zombie apocolypses are one. Mechnical arachnids are another.

At this point, the brain tray still wasn't wired up. The mechanical components were all in place, but a lack of outputs had kept me from really working on it. With the shift registers and latches in place, I could tackle this problem.

It turns out that driving a motor two directions is much more complicated than driving a motor one direction. Instead of connecting or disconnect power, you have to be able to connect and disconnect both leads to both 5V and ground. I initially worked out a crude circuit with four NPN transistors (2N3904) to control the motor, but it just didn't work. I had forgotten that while NPN transistors work somewhat like a switch, it's not exact. They are good at sinking current (connecting a lead to ground), but are bad at sourcing it (can't connect the motor to power). After searching with google, I discovered H-Bridges and the need for PNP transistors for power connections. You can buy H-Bridge chips that have all sorts of nice features, like protection from burning out your circuit. Since I didn't have any of those chips, and I already had a half-assembled H-Bridge, I grabbed some PNP transistors (2N3906) and rigged up a basic two directional motor control. After that, it was simply a matter of wiring a whisker switch with a pull up resistor and writing a few lines of code to get the brain tray opening and closing.

I also added numerous software features to Stephanie. She can read the local weather and forecast by parsing an RSS feed from weather.com and control Winamp through its API; she can pause and move to the next (or previous) track. She also rebuilds her own grammar using the list of playlists in a special folder on my hard drive; saving a new playlist in that folder adds a voice command for loading it.

Second Iteration

Moving, more blinds control, more software features

The next school year, I moved to a different location. Moving Stephanie didn't take much extra work. It just takes some time to navigate the rat's nest of wires and plug everything in correctly. Before the move, I also developed the software into a much more versatile form. In the first iteration a lot of the grammar commands and actions were hard coded. In the newer software version, I can add and change commands quickly. I can even change her name with a few clicks and keystrokes.

I had programmed her earlier to read off the current weather and forecasts using an RSS feed from weather.com, and I wanted to add some more features like this. One very useful feature has been the ability to look up bus schedules. Champaign-Urbana has a great mass transit system and getting onto campus in the winter sometimes requires more than my bicycle. The bus system has a web page that lists bus times for an intersection; they even update it in real time with delays. Reading these times only requires that Stephanie downloads the page, does some string parsing, and sends it to SAPI.

Whereas my old room had only one window, my new room has a total of 5 (there's a bay window with 3 separate segments). To have control over the blinds I needed a new system. The problem was that I didn't have 5 continuous rotation servos, or enough servos to modify to do that, or even a way to control them all individually (you didn't think I would just run them all together, did you?). Luckily, I had picked up a Robo Sapien at a thrift store for really cheap. Opening him up revealed no less than SEVEN geared DC motors! They're fantastic! If I ever find another one for $5, I'm picking it up, no questions asked.

However, driving geared DC motors works differently than driving servos. With the servo, all that's needed is one control wire and some code. But to drive the geared DC motors back and forth, I needed H-Bridges. While I could have constructed 5 more out of my pile of 3904's and 3096's, I opted to go with real H-bridge chips from Spark Fun. Each chip could control two motors, so with three chips I could handle all five motors.

I still needed a way to drive all the H-Bridges. I was already using a lot of the expanded output board, and driving all five blinds independently required a number of pins. I ended up putting another shift register on the blinds control board and wiring the shift register in series with the old expanded output board. This way, I didn't use ANY more pins on the BS2, and the blinds control board only needs power connections and a few data lines!

Future

What's next for Stephanie? I'm currently working on an internet gauge inspired by this beautiful example. My grandfather was an electrician and he had many old parts. Searching through the basement yielded an old battery charge monitor with 'low' and 'high' markings.

I'd also love to get a chance to experiment with some Python and OpenCV. I recently grabbed an old multi-disc stereo out of a dumpster, and if I can get the disc platform to rotate my fan, then I'll have a web cam watch for motion and point my fan accordingly. In the summer, I'll never be without a breeze!

If you have any suggestions or questions, please feel free to stress test the comments system I just put in place. You can also e-mail me at babaker2 -AT- illinois.edu. The source code is available below. If you want to use voice commands to send data over a serial port, you might want to check out the small SAPI program I wrote for Intersession.

Downloads

Visual Studio 2008 Source - for the computer interface
Basic Stamp 2SX source - for the avatar

Comments