Home Chapter 17 BS2 Infrared, pressure, bend, color, acceleration, vibration

Site Search


Chinese (Simplified) French German Italian Portuguese Russian Spanish
BS2 Infrared, pressure, bend, color, acceleration, vibration
Active infrared sensors allow you to have your sensor on a moving platform as they send out a beam of infrared light at 40Khz (40,000 times a second) and look for only that frequency back. There are a variety of these sensors that can sense from a few feet on up. Some can give you a fixed distance and some can give you variable distances.  A good source for these sensors is Acroname.com and be sure to order the correct ones as they all look quite similar.


The ones that give you a fixed distance require less code and are very easy to use such as the GP2YDO2YK a one bit sensor that returns a 0 or a 1 to your microcontroller so they are very quick and responsive. I suggest you carefully add the yellow, black (middle wire) and red to the white mini terminal connector first and then attach to the sensor. 


 Here is a schematic of how to wire the GP2YODO2YK to your BS2 or Arduino microcontroller. This sensor can detect an object as far away as 80 cm (30") and down to a 2 inches (5 cm).


Basic Stamp code for this sensor could look like this if you have the yellow wire attached to pin 15. Be sure to have good connections to the Basic Stamp power and ground and careful to make sure you are using a 12K OHM resistor between power and signal pin. 


GP2YODO2YK active infrared sensor

' {$STAMP BS2}
' {$PBASIC 2.5}


GOTO top



IF IN15 = 1 then see

DEBUG "I don't see", cr

GOTO top

DEBUG "I SEE", cr 

GOTO top 



Is also a sensor that provides changing resistance in relation to the force of pressure it sees. It outputs a varying resistance that is proportional to the force applied to the black button and a resistance of 500K without pressure to 500 ohms when it is experiencing maximum force. You can use this sensor with the PULSIN command on the BS2. Good sources Digikey or HVW Tech.com.


Force Sensor 10 x 68 mm is actual size


Bend resistor

Bend sensors are resistors, which change their resistance in relation to the bend. They are used in many applications but are popular with dancers and theater people because they can be inserted into clothing and wearable computing devices so arm or leg bending can be sensed and cause something to be activated.


Bend Resistor


A good source for these is: http://www.imagesco.com/index.html

Taos TCS230 Color Sensor Kit

Imagine building a robot that had a favorite color and would move around it's environment sensing the color of everything it encountered until it discovered its favorite color. Maybe you want to construct an electronic eye/ear that would produce different tones depending on the colors it viewed in a painting you made?


Color Sensor


The TCS230 sensor module set is comprised of a complete color detector, including a TAOS TCS230 RGB sensor chip, white LEDs, collimator lens, AppMod adapter board, and connecting cable. It interfaces easily to any BASIC Stamp module, either through an AppMod socket or connected directly, and can detect and measure a nearly limitless range of visible colors. Applications include color edge-following robots, sorting by color, and color matching, to name just a few.

The TCS230 has an array of photo detectors, each with either a red, green, or blue filter, or no filter (clear). The filters of each color are distributed evenly throughout the array to eliminate location bias among the colors. Internal to the device is an oscillator, which produces a square-wave output whose frequency is proportional to the intensity of the chosen color. Read the documentation below and check out the Color Matching Demo for more detailed information.

Memsic 2125 Dual-axis Accelerometer

The Memsic 2125 is a dual-axis thermal accelerometer capable of measuring acceleration (vibration) and static acceleration (gravity) with a range of 0 to ±3 g on either axis. For integration into existing applications, the Memsic 2125 is electrically compatible with other popular accelerometers.


Memsic 2125 Dual-axis Accelerometer



This sensor can sense movement/Lack-of-movement. It sends a pulsed output of g-force for both the X and Y-axis and therefore needs to have an analog to digital converter to interface to your Basic Stamp 2. It is stable over a range of temperatures from 0° to 70° C so it is OK outside if protected from weather. It has a low current draw at 4 mA at 5 volts DC so this works well with batteries. Some possible applications are sensing the movement of your artwork or invention. You can also employ this sensor as a single-axis rotation sensor.

 With the two pins attached pins 15 and 14 respectively to the Basic Stamp 2, code for this could look like this:


'tilt sensor 

'{$STAMP BS2} 

'{$PBASIC 2.5}

a VAR Word

b VAR Word



PULSIN 15, 1, a

PULSIN 14, 1, b

DEBUG HOME, DEC4 ? a, DEC4 ? b




 A good source for these is: http://www.parallax.com/


The Geophone sensor produces an electrical signal proportional to motion of the geophone sensor and this was used during the Vietnam War to tell if enemy soldiers were getting close. You can plant these sensors in the ground and use them to sense footsteps. If you Google these sensors you can find them surplus and some new units as well. Google with seismic activity phrase as these are also used to sense seismic activity.



A source for geo phones is http://www.geospacelp.com/ and http://www.mitchamindustries.com