Tuesday, July 24, 2007

Ambient Orb aka Rainbow Ball

For some reason this "ambient orb" Arduino project blew me away. The basic setup is very easy: red, green and blue LEDs mixed in different amounts. (Putting them inside a diffusing cover helps the mixing.) There are only two catches:
  1. LEDs aren't dimmable the way incandescents are, so how do you control mix?
  2. Finding LEDs of all three colors in the same output is nearly impossible.
The solution to the first catch is Pulse Width Modulation. Basically, you send tiny bursts of current so it flickers on and off faster than you can see it. The more time it spends on (the "duty cycle") the brighter it seems. Doing this from the Arduino is simply a matter of adjusting a number to say what you want the duty cycle to be in the range 0-255.

For the second catch, I pored over catalogs and websites trying to find matching LEDs. I did find them more than once, but it was always coming out too expensive. I mean, I was blown away by the idea, but not to the tune of $10! (Maybe I should have called this blog "The Cheap Bastard".)

I actually do already have all three colors, but the single blue LED I have is a trillion times brighter than any of the others. Really, it's blinding. I could have just bought a new blue to match the low-level reds and greens I have, but what power are they? Is there any way to figure that out, maybe from power consumption?

Finally I realized I could just use a bunch of reds and greens and also cut the blue's power in half (i.e. never get the PWM duty cycle above 50%) and it comes out all right. Mostly. The blue is still too powerful and swamps the blue-green transition.

Why is the green almost invisible in the video? Is the CCD in the camera less sensitive to green? Is the green really a lot less powerful and my eyes just adjust to it?

Light and Fluffy as a Kitten: For Real Now

That's because I gave up and washed my hair.

It was definitely true that my hair was less oily than I expected. There were many days when each hair stood alone, unclumped from the others, and I thought I was near to fluffy kittenhood. But then the next day I'd forget to rinse it or something and I'd be a greasemop.

Also, and this may have been psychosomatic, I felt like the greasiness was starting to migrate down my head. Like maybe the hair was leaving oily trails on my forehead, on the tops of my ears, etc.

Experiment terminated after two weeks.

Monday, July 23, 2007

Guide To LEDs

Until now, I've really only understood 3 things about LEDs:
  1. They don't use much power
  2. You need to plug them in the right direction
  3. You can blow them if you apply too much voltage (or was it current?)
I think I've got it figured out now. I haven't seen it explained this way anywhere else, which could mean I'm just wrong or it could be I'm about to be nominated for the Nobel Prize in Explaining LEDs on a Blog.

Here's the deal: An LED requires a certain minimum voltage. If it gets that voltage, it turns on, otherwise it doesn't (and it doesn't drop any more than that voltage). The exact number varies by color (and other parameters?), but is in the region of 1.5-3.5V. So if you had a 1.5V LED and a 1.5V battery, you could just hook them up, right? No, because you'd get too much current. The LED drops 1.5V but has practically no resistance. (Ohm's Law is really more of a guideline.) A reasonable number to use as a first guess for the amount of current an LED can take is 20mA.

So how do we put this all together? Perhaps the clearest way is to do what I did: Figure out what voltage all the LEDs in my drawer took and label them. First, I built the very simple circuit on the right.

What value to use for R? We don't want more than about 20 mA running through the LED and R = V/I, so 9V/.02A = 450Ω. A standard 470Ω resistor should be fine. So far, so obvious. But how does this figure out the voltage the LED drops?

I tricked you. You actually build that circuit but put an ammeter in there too. Measure the source voltage carefully (well, semi-carefully--I just mean don't assume a "9V" battery is really 9V). Measure the actual resistance of R. You are going to get some measured current Im. Im will not be equal to V/R! That's because the Ohm's Law is only applying to the resistor and the resistor isn't dropping the full 9V. It is dropping only the remainder of the voltage that the LED didn't use. The current is then that remainder voltage divided by the resistor value. In equation form: Im = (V - Voltage dropped by LED)/R. Rearranging, the voltage your LED is dropping = V - Im * R.

So for instance a typical red LED in my drawer is 2.1V. So when I put it into the circuit, the voltage across the resistor is 9 - 2.1 = 6.9V. 6.9V/470Ω ~= 15mA.

Is this just arcane nonsense? Yes, for source voltages that are much higher than the LED voltage and when you are only putting one LED in the circuit. But I went through and did that with all my LEDs. Now I know how to put a bunch of LEDs together and can save power (and resistors, and circuit space) by putting them in series with the right size of resistor. I could fit 4 2.1V LEDs in a 9V circuit because 4 * 2.1 = 8.4. That leaves .6V. In order to limit to 20mA exactly, I'd want a 30&Omega (.6V/.02A); resistor in there.

One caveat: If the voltage varies you might blow something in such a tight margin. I was running my circuit off a weak 9V that was down to about 8.5V. If I really did build the circuit with 4 LEDs I'd have .1V left over, which would require a mere 5Ω resistor. But then say I put a fresh battery in and it's 9.3V now. Now suddenly there's .8V across the same 5Ω resistor which gives me 160mA. Goodbye LEDs! So it would be good to either work with a regulated voltage OR leave yourself enough extra voltage that normal variation isn't a huge change percentage-wise.

Sunday, July 22, 2007

Temperature Logging Part III: The Exciting Conclusion

Some pics of the final state: You might notice an extra button. I decided to write to EEPROM rather than an array after all. The reason was an unreliable power situation. A 9V battery lasts for a few hours and I didn't want to lose hours of data at the last second. So we have a switch for power on/off, a button for "send data" and a button for "start collecting data". The last one is I can control when the EEPROM starts getting overwritten the next time I turn it on.

That relatively minor change forced a paradigm shift in what processing was done where. Originally, I was just reading the voltage ratio from the pin and sending it to the PC that did the work to convert to degrees. The pin reports a value in 10 bits (i.e. 0-1023) but the EEPROM stores only bytes (i.e. 0-255). I could have renormalized to the smaller range, but only at the loss of a lot of precision. Instead, I now calculate the temp right on the Arduino. Surprisingly (to me, anyway), you can use the regular math library functions like log(). So then I end up with a temperature that practically speaking won't get above 255 or below 0, and even if it did I could add or subtract a constant to recenter it to my working range. I will describe what temperature I was logging in another post, but for now here's the pretty graph.

Thursday, July 19, 2007

How To Make Awesome Pizza

Until recently, my idea of awesome pizza was "lots of cheese, almost burnt". Also, there needed to be a way to hold the cheese without burning yourself, so I needed crust. I wasn't sure what the sauce is for, but tradition demanded its inclusion. Tradition definitely did not demand the inclusion of members of the plant kingdom.

However, I have changed my boring pizza ways. I now make gourmet pizza on a weekly basis. The secret....REVEALED!

Crust Ingredia

  • 3 cups flour
  • Between 1 cup and 1.25 cups water, depending on the weather
  • A dash of olive oil
  • Two pinches of basil
  • A generous helping of yeast
  • 1 bread machine with a "dough" setting
  • 1.5 hours
Stir all these ingredia until you have a bunch of dough. Meanwhile, dice a couple sausage patties a 2.25 oz can of black olives (sliced) a tomato (The role of the tomato has been played by an understudy in tonight's performance due to a grocery malfunction.) And some pepperoncini: I think the rest of this recipe speaks for itself. I'm still using boring old Sauce in a Can, though. I need a good pizza sauce recipe.

Tuesday, July 17, 2007

Light and Fluffy as a Kitten...Sprayed with Pam

I've heard this claim before: You don't really need to shampoo your hair. Your head chemistry will adjust if you stop stripping the natural oils from it.

OK, sure. However, in this article the author not only claims that his hair is "as light and fluffy as a kitten's coat" but he also gives the basic idea on how go about the experiment. So I decided to try it and compare my head to a hypothetical kitten.

Experimental Procedure

  • The article author hedges about what exactly he's putting on his head. "No de-greasant" means what exactly? Are you still conditioning? Since the only thing I use is regular shampoo (i.e. liquid soap), I decided to just use plain water. Every morning I dunk my head in the shower and scrub it thoroughly with fingers and fingernails, but use "no de-greasant".
  • I also vaguely remember some other claim about "redistributing oils", so I also combed.
Results after one week
My hair is definitely less greasy-seeming than I expected. I normally shampoo every other day and when I skip a soaping I definitely notice it. My hair feels clumpy and gross. Rinsing and combing seems to fix that so I don't really notice.

On the other hand, I wouldn't say my hair feels clean, either. If I run my hands through it they start feeling like I've been eating potato chips. OK, maybe not that bad, but I'm not squeaky clean. In fact, when I rinse in the morning I have to wash my hands with soap after.

When I started this post I thought he said to try it for a week, but now I see it says a "few weeks". OK, I can probably stick it out a little while longer. No one has commented on it, so I guess I'm not too awful to behold.

Monday, July 16, 2007

Salsa & Guacamole

This is a very basic, simple recipe. It's 100x better than the canned stuff I used to eat (which I think is actually picante sauce, so I guess I'm comparing tomatoes to peppers there) but I'm sure there are homemade salsae out there that beat this to a pulp (GEDDIT??). Nevertheless, if you've never made salsa before this is an OK place to start and a good base for experimentation.

2 green peppers
2 red onions (I like the taste vs the yellow/white)
some cilantro (you have to buy a whole bunch, but you only use a few chopped tablespoons)
several jalapeƱos/habaƱeros, to taste

Chop everything up and put it in sealable plastic bins. On Taco Night, I dice a tomato and add a few scoops of this salsa mix. The above lasts probably 3 months at the rate I use it. However, the quality seriously degrades so if you have more free time (for some reason it takes me like 45 minutes to put this together) I'd recommend making smaller batches more often.

The guacamole recipe is even dead simpler (deader simple?). The only reason I even mention it is that I never knew the awesomeness that is guacamole until recently. Here's the recipe:

An avocado
1/3 of a packet of guacamole powder

The only tricky part is choosing ripe, but not too ripe, avocados. A perfect avocado is just a little firmer than a perfect peach. If you squeeze it and it gives more than 1/16" clean off your hand and find another avocado. However, it must give at least somewhat or it is underripe. I've learned the hard way that an underripe avocado is a nightmare to get out of its skin. If that's all the store has go ahead and buy them, but store them on the counter for a couple days before enfridgerizing.

(Another way to identify avocados is by color: Black is too far gone, bright green is not far gone enough. You want a very dark green.)

Saturday, July 14, 2007

Temperature Logging Part II

OK, so I had the temperature (sorry if this reads like a novel--I'm writing this one after the fact), but I already had that with a kitchen thermometer. The whole point of this is data collection. From the docs and examples, I think most people are using the Arduino attached to a computer, which makes logging a simple matter of reading the serial port and writing to the hard drive. But the temperatures I'm going to be logging will be located far away from a USB port.

My initial plan was to write the values to the "EEPROM" (no, me neither), but:

  • It only supports 512 bytes. At one sample every two minutes, that's only 4 hours.
  • It only supports a limited number of writes. Large, but limited.
  • I don't really need the ability to save the values through a power cycle.
Instead I went with an array in RAM. I just have to be sure to get the data before I turn it off or the battery runs out.

And how do I get the data off? I have a button that tells the thing to dump the data to the serial port. This is really a simple feature, but I learned a lot while doing it. That's because, even as an electronics n00b, my analog electronics sk1llz leave my digital ones in the dust.

Here's the schematic for a digital switch. Notice that it doesn't really work like an analog switch. That's because you aren't sending electricity around a digital circuit like with a simple flashlight, you are sending voltage around the circuit. Or so this one experience indicated to me. D2 is the digital port. When S is open, as shown, D2 is HIGH (i.e. 5V) with respect to ground. If I close S, current flows (which is why R exists--to limit the current, which means R should be as high as feasibly possible, at least so I infer), but more to the point D2 and ground are electrically connected, meaning it is now LOW (0V).

Question: I think I could have had D2 at LOW by default and switched to HIGH. Would that save power? Ideally, a voltage doesn't have a current, but I don't know how the voltage comparison happens internally.

Anyway, this circuit and the previous one can be put in parallel. The thermistor one reads temps until the buffer array is full and the switch one waits for someone to press it and when someone does, it spews data.

All that remained was to make it small and robust enough to survive an afternoon outside, with light breezes, sunshine, etc. So I soldered the components onto a board (seriosly, this project is like 1/4 of all the soldering I've ever done--I'm a total, total N))B) and slapped it into a tupperware container.

Friday, July 13, 2007

Temperature Logging Part I

There have been many times when I've wanted to log temperatures. No useful reasons, I just like collecting data. The problem is that temperature logging devices are like $50 and up and of course they only do that one thing. After the orgy of temperature data collection is done, it just sits on the shelf.

But I'd been hearing about this Arduino dealie, which is an open-source microcontroller that only costs about $35. I figured that I could put a thermistor on there and make my own logger, which would not only be cheaper but I'd also have a versatile device for other projects. I've never used a microcontroller before, plus electronics above the level of a flashlight circuit confuses me, so it's been an adventure. Fortunately the Arduino is supereasy.

For that matter, the electronics of this were prettyeasy. The hardest part was doing the math to convert a thermistor reading into a temperature one. I harvested a thermistor from a broken (except for the thermistor) electronic thermometer. (It was easy to identify, since it was sticking way up away from the rest of the circuit board and and had "therm" written next to it.)

A thermistor varies its resistance based on temperature. That means that if you apply a voltage, you'll get a varying amount of current out. But the Arduino input port measures voltage level, which means you need to turn a varying resistance into a varying voltage instead. That's easy with a voltage divider.

"Th" is the thermistor, and A1 is the steak sauce Arduino analog input port. The total voltage drop across both resistors is a constant 5V, but how much drops across each resistor depends on the ratio of their values. So when the thermistor changes, the voltage at A1 also changes.

Now you just need a way to convert a voltage reading to a temperature reading. I assumed it would be a linear relationship, but it isn't, it's exponential. When you buy a thermistor, apparently they give you two numbers. A baseline resistance (at 25°C,) and a number B. Apparently you are supposed to know this equation:

RT = RTzeB(1/T - 1/Tz)

Oh sure, THAT equation! RT is the resistance of the thermistor, which you can figure out based on the read voltage and known values of the circuit. RTz is the resistance at 25°C (or whatever baseline), which is Tz. T is the temperature you want and B is the magic number.

I didn't get my thermistor from any fancy-shmancy store so I didn't have the magic number. Instead, I used the thermistor to measure hot and cold water (calibrated by a kitchen thermometer). Plugging in those readings I was able to solve for B. Just using math got me within 2 or 3 degrees (over the range 0-100°C--I haven't tested outside that range). Then a little empirical fudging got me right on the money.


Or maybe "Statement of Purpose" would be better.

I just want a place I can keep track of the many projects I'm "working" on at any one moment. My attention seems to cycle through a semi-fixed list of topics and when I come back to a topic I don't always know what's going on. Plus even if I don't have any readers, I'd like to document the things I figure out so random googlers can get a leg up.

Also, I need a place to articulate the solutions I find to problems. No matter how blinding the insight or life-changing the epiphany, I usually forget how I solved a problem the first time around.