View Full Version : Infrared Sensor (Sharp GP2Y0A02YK0F)-Long Range Infrared Pro

03-06-2012, 04:56 PM
The Infrared Sensor produces an output analog voltage.
I want to interface it with the Propeller Microcontroller(Propeller Board used has a Product Number 555-32100.
Propeller IC is P8x32A-044 0739

03-06-2012, 05:02 PM
I want the code in Spin

03-06-2012, 05:13 PM
Not sure who you are calling sir but, Ill chime in here.

Generally as a rule of thumb if the signals are analog then it needs to be converted to digital, I say this lightly because there is always another way to skin a cat.

So if the signal is analog use a ADC to convert it to digital.

No code for you...

Cause you need to select a ADC.

Mike Green
03-06-2012, 05:17 PM
There is no readily accessible interface on the Demo Board for an analog voltage. It's not hard to add using the little breadboard area on the Demo Board. Pick up an analog to digital converter like the MCP3202 (http://www.parallax.com/StoreSearchResults/tabid/768/txtSearch/mcp3202/List/0/SortField/4/ProductID/575/Default.aspx). There's an object (http://obex.parallax.com/objects/515/) in the Object Exchange that handles the interfacing. Look at the comments in the Spin source files for details and examples. You can use any 3 I/O pins to interface to the MCP3202 and you specify which pins when you initialize the object as noted in the comments.

There are other objects in the Object Exchange for some other analog to digital converters, but the MCP3202 is very easy to use. It's possible to do analog to digital conversion with the Propeller with only a few passive components, much like the Stamps do it. You'll have to do your own coding though. Look at the discussion on the "app-notes" page here (http://www.emesystems.com) under battery voltage monitoring for some ideas. There is some useful code in the BS2_Functions object to provide the same functionality as the Stamps' RCTIME statement.

03-07-2012, 10:45 AM
Is it possible to use the Infrared Sensor with Counters without using an ADC?

03-07-2012, 01:04 PM
I would just use a RC circuit with an RCTIME command to measure the voltage. In the book "What's a Microcontroller" there's a section on measuring analog voltages using RCTIME.


You can do this on the propeller chip as well using the basic stamp functions.

03-11-2012, 11:34 AM
Sir,can you please explain me how to connect the sensor along with the RC Circuit.this is the code I'm using for the RCTime.Sir,Please check it.

_xinfreq = 5_000_000
_clkmode = xtal1 + pll16x
long RCValue
pst : "Parallax Serial Terminal"
PUB main
RC.start( 0,1,@RCValue)

PJ Allen
03-11-2012, 03:59 PM
I have used analog output sensors without ADCs or RCTIME.
In one instance I used the sensor output as the control voltage input for the VCO section of a 4046 (CD4046, 74HC4046, etc.) and COUNTed its output. In another, I had the sensor output going to the inputs of a couple of comparators where crossing the threshold of one indicated "near" and the other indicated "closer still".

T Chap
03-11-2012, 05:17 PM
Similar to PJ Allens idea, I have produced a ramping voltage from a Prop pin using PWM(ramp frqa), the voltage looks like a reverse sawtooth. Connect the voltage to a comparator, the other input of the comparator to the analog source(sensor). As the voltage ramps up from the PWM, and at the trip point on the comparator, the Prop code can take note of the comparator output going low(active low), and then convert the PWM (counter frqa value) at the point of the trip to a usable value. The frqa value can be scaled to the voltage. It just takes some experimenting to document the voltages out of the Prop in order to create your scale.This methods of course is not for high speed changes, as the ramp does take some time to move from 0v to 3v3V and start over. But for distance or motion sensing is quite OK. An advantage of this method is that it is not so delicate as trying to use the Prop ADC method.