Friday, December 21, 2012

Sensors

One of my first proofs of this robotics concept was having a remote control car almost stop before it hit a wall. To do this, I used a Parallax ping ultrasonic sensor. I got mine from Radio Shack for around $30. The Arduino IDE comes with sample code -- it has the sensor send an ultrasonic pulse, counts the microseconds until the pulse returns, then outputs that to the serial monitor in the IDE. The code also does some math to divide out the speed of sound, returning the distance in inches and cm. I wrote a loop that reduced the output to the car's motor as the sensor's distance decreased.

The ultrasonic sensor is relatively durable and hard to damage, it's reliable, and uses just the one pin for both input and output. But sometimes I think I can almost hear the sound, and it makes me feel weird. Also, $30/sensor is expensive for the number of sensors I'm planning on needing.

Enter the phototransistor

An alternative I'm investigating is infrared LEDs and infrared phototransistors. A phototransistor is a transistor, a switch with no moving parts. Most transistors have 3 legs, and if legs A and B have electricity going through them, then electricity can also travel from A to C. Phototransistors, however, basically use a "reverse-LED" to allow electricity to travel. They look like LEDs too, and operate much the same. Here's more info on phototransistors.

A problem I have in my initial testing is that my tests are unreliable. I can set up an infrared LED facing an infrared phototransistor, and can separate them to turn on and off an LED. But tomorrow, it will not function. I believe this is because I'm overloading the LED. So far I've "bricked" 3 of them, and I saw a faint red glow from the last one. Radio Shack's website is light on details, and I don't honestly know enough about electricity to know what's causing the problem.

But apparently easy to use EE calculators exist. This one says I need a 39 ohm 0.5 watt resistor, and conveniently tells me the color code: Orange, White, Black, Gold. I don't have any of these in supply, which reminds me I need to stock up on commodity components such as these.

No comments:

Post a Comment