November 17, 2005
Motor Lab
I piggybacked on Jenny's mostly already-done motor lab, just to make sure I could get a motor going if I ever had to. I kind of slacked off on the motor lab because I was working pretty hard on the iTunes Jukebox.
The lab went pretty smoothly. Jenny had set everything up already, mostly. We both learned that there's such a thing as a unipolar motor that only goes in one direction (and doesn't go at all if the polarity is reversed) and we also learned that even a tiny motor can get going fast enough to make masking tape cut through paper.
The breadboard with the motor.
One half of the breadboard setup.
The other half of the breadboard.
Tools used
- PicBasic Pro
- DC Motor
- Stepper Motor
Posted November 17, 2005 02:11 AM. Categories: Labs , Week 10 | Permalink
November 16, 2005
Air Guitar (MIDI Lab)
Oren strumming the air guitar.
An image of the guitar with the breadboard. "No strings attached!" (A helluva lot of wires, tho').
For the MIDI lab, I decided to try out a beam-break detection system I had been wondering about for awhile. Creating an invisible "string" that could be "plucked" seemed to be a perfect applicaiton for MIDI.
The beam-break detection system is pretty simple: An infrared (IR) LED shines at an IR emitter/detector. If the IR LED isn't too far from the emitter/detector, you will pick up a signal. Indoor lighting gives off IR, too, so the values you get on the IR detector will vary depending on the lighting situation. To overcome this I created a "calibrate" routine where the PIC measures the initial value it reads off the IR detector and then compares subsequent readings against this "calibrated" value. If the new reading on the detector is off by a pre-determined amount (my "threshold variable"), we know the beam has been broken, and so we can do something (in this case, we send a MIDI note out).
A close-up of the IR emitter/detector
A close-up of the IR LED, which is situated facing the emitter/detector, about 6-8 inches away. You "strum" the guitar by interfering with the beam between this LED and the detector.
The reason I used an IR emitter/detector (note the emphasis) is that I wanted to be able to do some basic ranging. That is, I wanted to get more information about where the beam was broken, in addition to the fact that it was broken at all. When you break the beam with a finger, your finger reflects some of the IR from the emitter back to the detector (the emitter/detector combo is one unit, with both emitter and detector facing out. The IR LED is across from the emitter/detector module, about 6 inches away.). The idea (and this was born out when I looked at the data I was getting) is that there will be a range of values that the detector detects, going from low (finger breaks the beam far away from the emitter/detector) to high (finger breaks the beam right near the emitter/detector and a lot of IR light gets reflected off the finger into the detector), as well as the "calibrated" value (i.e., nothing breaking the beam).
In practice it worked out pretty well except for the fact that the range of values the detector read were not linear (they tend to be quite low for the furthest third of the length of the beam, and then jump up very quickly when you get less than a couple centimeters away). I don't think I got the correct code onto the PIC to translate those changing measurements into changing notes, though.
Here's a close-up of the breadboard, without the 20MHz clock.
I also drilled a hole in the guitar body and added a potentiometer with a knob on it (just like a real electric guitar). The values from the potentiometer are used to change the volume of the notes generated using the guitar.
You can download the PICBasic Pro Code (I commented it as well as I could).
One of the major problems I ran into was making sure that the PIC programmer was set for a high-speed oscillator (oscillator->HS). It was really frustrating before I realized I was forgetting to do that. Also, getting the hang of how to set up the hardware serial out (the HSEROUT command) was difficult.
I should point out that I didn't do this alone. Oren helped out a lot for the final stages, and Tikva helped me along when it was still an air harp. And Megan MacMurray gets special thanks for generously letting me use her 20MHz clock whenever I needed it.
Me jamming.
Me jamming harder.
There will be a movie coming soon (it's not the same without the audio).
Also, I'm planning on expanding the project to include a couple strings and Oren's suggestion which was to use photodetectors as "frets" to change chords. I am going to need to use lasers for the multiple strings (IR would diffuse and interfere with itself). I think I'll call it my Laser Air Guitar.
Tools used
- PicBasic Pro
- MIDI
Posted November 16, 2005 09:54 PM. Categories: Labs , Week 10 | Permalink
October 05, 2005
Servo Motors and PWMing of LEDs
This week's lab: Using a servo motor (and doing analog out).
I had a few spare moments in the lab, so I created an entirely new (but basically same-as-before) breadboard setup with the 10K resistor on the PIC's reset (upper left pin), power to the board and to the PIC, and the LED indicator light on the bottom. I figure it will be nice to be able to have two projects going at the same time, instead of having to pull all the attached wires each time my project changes. Plus, I think I'm a better solderer now, and I have hindsight on my side, so I was able to make a slightly cleaner board (the real improvement over the last one is in my serial connector. I did a much better job of soldering the header pins and laying it out this time).
The most difficult part of this lab was finding the servo motor. I trekked all around Chelsea trying to find a store that would sell it to me (there was talk about some store on 22nd street but I never found). I eventually had to go up to 30th street by 7th Av, a place called American Hobby Center, or something like that.
So what is a servo motor? Seattle Robotics has a good beginner's guide to the servo. Basically, it's a small motor that has a roughly 180-degree range of motion, and the shaft of the motor moves according to the time that a voltage is pulsed to it. It is connected to +5V and ground, and there is a control wire as well (this is the input to tell the servo how far to turn).
Luckily, there is a command in PicBasic Pro, PULSOUT that we can use to specify a length of time to send a signal to the motor. This is how we can specify how far the motor should turn. Sending a short pulse will cause the motor to reset back to its starting state.
One other neat thing I found out about from the Seattle Robotics link above is that servos move at a speed proportional to how far they have to go. This makes sense considering what I observed while using the little motor, but I didn't realize it before.
So what did I build? I came up with two ways to use the motor: manual and automatic. In manual mode, twisting a potentiometer varies the analog input to the PIC, which then translates this into a length of time to pulse the motor, with the result being that you twist the pot, and the motor twists along with you.
In automatic mode, the motor rotates until it hits a trip-switch that I built. When the switch is tripped, it resets and starts over. I think there's something really fascinating about watching the motor twist until it hits the wire and then abruptly resetting once it does. You can watch the movie below to see for yourself.
This first image is a close-up of the motor with the trip-switch. The trip-switch is just the yellow and white wires wrapped around each other. When the motor pushes the first wire, it touches the second and closes the switch.

This second picture is an overview of the entire board. It shows the switch in the upper right corner of the board and the yellow and red leds in the middle on the right side of the board. The yellow and red LEDs act as indicators of which state (automatic or manual) the board is operating in.

The LEDs also dim and glow according to the state of the stepper motor. This is done using PWM, or pulse-width modulation. The LEDs are PWM'd a certain length of time depending on the position of the motor's gear. Pulse-width modulation is when the PIC outputs a square wave voltage; the proportion of time the wave is HIGH and LOW (or ON and OFF) creates an average voltage. If the modulation is fast enough, the eye cannot see the individual on-off changes and perceives the LED as being dim (or bright). I was never able to keep the LEDs from flickering a bit. It was a trade-off between faster response of the stepper motor and smoother lighting of the LEDs.
Posted October 5, 2005 12:56 AM. Categories: Labs , Week 4 | Permalink
September 27, 2005
Analog In/Out, Serial Out, Infrared Remote Control
Description of the lab see here.
This week I learned how to send serial signals out from the PIC to be read and understood by a computer. We used a PC program, Hyperterm, to view the serial data. Connecting reminded me of how I used to get on the internet back around '96: Specify the baud rate, the parity, stop bits, flow control, etc.
I figured out how to use a potentiometer wired in series with a 10K resistor to vary the voltage coming in to the PIC, and the resulting numbers that show up in Hyperterm range from 0 (when there are 0 volts, i.e., the potentiometer is at maximum resistance) to 1024 (because we specified that there would be that many steps between low and high).
In the course of trying to find something interesting to use this analog signal for, I thought about the different kind of input devices that were possible: there are force resistors, light-sensitive resistors, heat-sensitive resistors. We use single LEDs to indicate the presence or absence of a digital signal, so why not use one of the analog sensors mentioned above with an array of LEDs to indicate strength of the analog signal coming in? I decided to be fancy and try to create a crude remote control using an infrared sensor and infrared emitting LED.
I went down to Chinatown and found an electronics store where I bought an IR Photodiode, part number NTE3033, and an IR LED, part number NTE3017. I had a lot of headaches with these, mostly because I didn't have a clue how they should be properly powered and installed on the breadboard. I finally got a decent reading from the IR receiver when I wired it like a switch, from power to receiver to 10K-Ohm resistor to ground. But I never got the IR LED to work well. I wired it in series with a potentiometer so that I could vary the voltage on it (I wasn't sure if it uses the same amount of voltage as a normal LED), and I was only able to get big readings off my photodiode when I had the resistance on the pot turned down so low as to almost fry the board.
I had also been told that a digital camera will pick up IR, so that you can see an IR LED shining if you look through the camera's viewfinder. I could see no such thing on my poor IR LED.
Long story short, I plopped down a few more bucks at Radioshack for another IR-emitting LED, and all my problems were solved. On with the lab.
The first idea was, if I am going to make an infrared detecting system, I might as well just go ahead and make a full-blown remote control. I used a 9V battery and wired it together with a 5-volt regulator, a 220-Ohm resistor, the IR LED, and a push-button momentary switch. Here's the battery, wrapped in tape (to prevent its metal outside from creating shorts):

A close-up of the guts of the remote, before wrapping them all up in tape.

The final remote:

When the remote is clicked, you can see the infrared LED glow in the viewfiender of a digital camera:

Here is the original setup. The IR detector is the black blob on the right.

Here's how the board looked after I put the LED bar display in, trimmed all the wires, and bent the IR detector backwards so it would detect a signal coming from above.

This is the Radioshack IR Kit (emitter and detector) that saved me:

And, finally, a movie of the sucker in action, set to the Beastie Boys' "Remote Control" (turn your bass up):

And don't forget the code.
Posted September 27, 2005 12:52 PM. Categories: Labs , Week 3 | Permalink
September 13, 2005
Programming the PIC: Memory Game
The goal of the lab for this week was to program the PIC (Programmable Interface Controller). I created a simple game: There are 7 yellow LEDs, one red LED, and two buttons. One of the buttons is for gameplay, and the other is a sort of meta-button, used for starting/resetting the game and for advancing from level to level while playing the game.

The switch labeled "built switch" above is simply two bare wires that can be tapped together to "press" the switch. The gameplay starts as soon as the player pressed the built switch. The yellow LEDs all blink twice and then they blink in succession, from the first to last. Each LED blinks a random number of times between 1 and 3 inclusive. As soon as the last yellow LED has blinked, the game goes into a ready state while it waits for the player.
The player plays the game by pressing the momentary switch. Each time she presses it, the first yellow LED lights up. When she believes she has blinked the first LED the correct number of times, she presses the built switch to advance to the next level (the next LED). The red LED lights once to indicate that it has moved to the next LED. If the player blinks an LED too few times before advancing, or too many, the red LED lights continuously to indicate that the player has lost. The game then goes back into a ready state until the user presses the built switch to start the game again.
If the player succesfully makes it to the end of the game, all the LEDs blink up and down like a ripple and the game goes back into a ready state to wait until the player hits the built switch to start again.

You can see that I used the same soldered-resistor-and-LED combination I did during Lab 1. This made it easier to fit all the LEDs next to each other, and removed some of the logistical headaches in making everything fit well.
The coding of the PIC was by far the hardest thing. My code is pretty clean, but not nearly as efficient as I'd like. I had trouble getting for loops and dynamic variables working well, so I created separate loops for a lot of functions that probably could have been handled using a single function (for instance, I created a separate loop for each "level" rather than one loop that just iterated for each new level). Also, by far the biggest problem with the game is the random number generation. Every time the power is turned off and on, the game starts up with the same "random" configuration (hint: all but the last two lights blink 3 times). I never figured out a good way to be more random.
Code
The code.Posted September 13, 2005 03:21 PM. Categories: Labs , Week 2 | Permalink
September 07, 2005
First Lab: Breadboard, LEDs and Soldering
To begin, I soldered the connections of the connector for the AC adapter. There is a diagram on the back of the AC adapter that shows a minus sign next to a line with a semicircle on it partially enclosing a small circle with a line to the right and a plus sign next to it.
![]()
Diagram of power connector.
This means the outer part of the connector is negative (ground) and the inner part is positive. So I soldered the red wire to the inside connector and the black wire to the connector's shell.

And a picture of the connected adapter:

I found that I had trouble getting the solder to melt until I learned to put the broadest part of the soldering iron to the metal that I could. Just using the point of it doesn't work well.
I also soldered two header pins onto the end of the connector so that it would be easy to plug the connector into the breadboard. I used a glue gun to put a daub of glue around the connectors to prevent the wires from accidentally crossing and shorting out:

Next, I needed to connect some LEDs. I first put one LED in series with a resistor and watched it light up. Then I tried two, and they both lit, but when I tried three there was too much voltage drop across them for any of them to light up. (The images are a little blurry because I had to turn off my camera's flash to catch the light of the lit LEDs.)



I decided it would be nice to have an indicator LED that I could just leave plugged in to my breadboard all the time to make sure it was getting power. I soldered a resistor to the positive end of the LED so that I would only need to plug in one component to test.


Next, I soldered leads onto a potentiometer. I soldered a red lead onto one of the outside connectors and a black end onto one of the other outside connectors, and a blue lead to the center connector. Todd explained to me that the potentiometer needs to have one connector powered and the other connector grounded in order for the center connector to be able to give a variable resistance. The outside connectors can be positive/negative or negative/positive, it doesn't matter. Switching their connection just switches which end of the dial is 0 ohms.

There was a push-button momentary switch included with my kit, so I decided to give it a try. I connected it with the LED-resistor combo I had made:

I found a two-position button on an old radioshack soldering iron in the "pre-loved items" bin, so I took it apart and pulled out the switch. I used the switch to make a circuit with three options: off, one led, and two leds.


You'll notice that there are two capacitors on the top end of the breadboard. The first is a 10 microFarad cap that goes between the raw incoming voltage from the AC adapter and the 5-volt regulator. The 1 microFarad cap goes across the positive and negative ends of the output voltage from the regulator. Todd explained that these smooth out the incoming and regulated voltages, and help prevent the breadboard equivalent of brownouts. As soon as I can find a single-position switch, I am going to use it to create an on-off switch that I'll connect between the regulator's output and the power strip of the breadboard. I'm also planning on leaving the LED-resistor permanently plugged in as a "pilot light" for my circuit.
Posted September 7, 2005 03:13 PM. Categories: Labs , Week 1 | Permalink
