Radio Shack Mobile Robot manual Analog Inputs, Basic Stamp II light sensor example code

Page 44

Expansion Port Circuit Examples continued

Analog Inputs -

Analog inputs are inputs that can vary from 0 to 5 volts. While the Basic Stamp II doesn’t have a true analog input, analog signals can be read using a little trick. This is done by adding a capacitor to ground on a digital I/O pin and a resistive sensor to +5 volts. The sensor value can be read by first setting the digital I/O pin low to drain the capacitor, then the I/O pin is changed into an input, the resistive sensor will gradually charge the capacitor towards +5 volts. The time it takes for the signal to read a logic one (high) is the value of the sensor.

Analog Light Sensor

Basic Stamp II light sensor example code

'This routine demonstrates detecting light. The light level is 'read by determining the time it takes to charge the capacitor. 'The CDS photodetector changes resistance as the light 'intensity changes. This changes the current that is charging the 'capacitor. The output result is then output to the debug screen.

light var word

'light variable.

main:

 

 

pause

500

'check every half a sec.

low 2

 

'drain cap.

pause

50

'wait for cap to drain.

rctime 2,0,light

'time cap charging.

debug

? light

'send result to PC.

More expansion information

Our space is limited here so make sure to visit our web site for the latest expansion application notes complete with program examples. www.robotics.com/arobot/projects.html

Also visit the Parallax web site which has an entire section dedicated to application notes for the Basic Stamp II. www.parallaxinc.com

41

Image 44
Contents Assembly and User Guide ARobot Mobile Robot Connectors Basic Stamp II Control Computer IntroductionAbout ARobot Feature List What You’ll NeedTechnical Specifications Precautions Component Locator ControllerGlossary of Terms Glossary of Terms Glossary of Terms Assembly Overview About Screw, nut, and washer sizes PartsQuantity Description Used For Parts Motor Brackets Painting SandingPaint Primer Finish CoatHow it Works WhiskersSummary Whisker Detail Full Scale Whisker Wire Pattern Drive Motor and Brackets Encoder Sensor Front Wheel Assembly Steering Motor and Rear Wheels Steering Motor Mounting Wheel and Axle Steering System Controller Board Summary Don’t install batteries yet Battery PackDon’t install batteries yet Body Cable Finishing Up Programming Basic Stamp II InstallationAbout the Controller Board Cable to your PC PC Editor/Downloader SoftwareUSB Port Programming NoteSteering Adjustment Program STRAIGHT.BS2 ProgramsTest Program TEST.BS2 Wander Program WANDER.BS2About the Controller Board Batteries Power On/Off SwitchReset Button LED indicators SpeakerPush Buttons and Jumpers switches Drive Motor and EncoderSteering Motor Coprocessor Command Summary Example !1M11200E7RC Servo Motor and Steering Motor Control Coprocessor Communication RulesHexadecimal, Binary, Bytes, Words, etc Battery Connector J9 Body Connector J8Serial Port J12 PinoutRC Servo Motor Connectors J2-J5 Drive Motor Connector J10Powerful Connector J11 Voltage 12 volts Maximum Current 500ma PinoutExpansion Connector J1 Expansion Port RC Servo Motor SignalsExpansion Port Circuit Examples Switch Input Example Digital/Power OutputDigital Inputs Sensor Input ExampleAnalog Inputs Basic Stamp II light sensor example codeCoprocessor Network Expansion CommunicationsCabling between ARobot’s controller and another controller Using Other ControllersUsing ARobot’s controller as a coprocessor Suggested Reading Component Suppliers Sava Industries Small PartsStock Drive Products SuperCircuitsInternet Robot Resources Web SitesInternet News Groups Newsgroup NameDescriptionTroubleshooting Warranty Information Arrick RoboticsRobotics.com