Let's Make Robots!

How do people get analog values? (Question)

TofuRobot's picture
I just had a question burning in my head. How do people get analog values from thier accelerometers, potentiometers, Sharp infared proximity sensors? How do you guys find those values that you can plug in the PICAXE?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Calculon320's picture

all picaxes have at least one Analog to Digital Converter. the 28x1 has 4. You just plug your analog into the input pin and program:

readadc x,y (where x is the input pin # and y is the variable)

... and your axe will give you a value from 0 to 255.

As far as what those values MEAN, that depends entirely on the sensor you are connecting.

ezekiel181's picture

Your micro needs an ADC. You may already have one, in which case the documentation will explain what commands are needed to read the value.

For comparing the sensor data, the sensor might have information on what kind of analog level it will output. For example a distance sensors datasheet might have a graph showing what voltage is output for what distance is detected.

Or you can just experiment. Make a program to constantly output the analog info to a debug window on the computer then just put your hand in front of the sensor. Check the distance and the analog output.

TofuRobot's picture
I dont really know how to make it display the anolg values on a debug winndow. Is there a sample code for that?
Calculon320's picture

symbol value = b0

symbol device = 0   'or whichever pin you're using

do

readadc device, value

debug

loop

 

ignoblegnome's picture
Read through the "Start here" link and search the page for the debug command.  Fritzl put a good overview of how to do a lot of basic stuff in there.