Infrared Proximity Sensor -GP2Y0A21YK won't work with PICAXE

I have just purchased the Infrared Proximity Sensor - Sharp GP2Y0A21YK for a project that I am working and need to interface it with a picaxe chip. I had my circuit laid out on a proto board with the sensor and the motor I was going use. I went to download the code and it kept giving me an error. I had everything hooked up right and I know I was able to download because I have another project I did with a picaxe and it was just fine.

I started removing components from the board. Started with the motor, no change. Once I removed the sensor I was able to download the code. Weird, but ok whatever!

I hooked everything back up and as I got closer to the sensor the voltage increased but my output to the motor didn’t change.

Long story short, whenever I have the sensor hooked up from vcc to ground the picaxe doesn’t perform anymore. What am I doing wrong here?

Thanks,

Vert

vertigonix:
Long story short, whenever I have the sensor hooked up from vcc to ground the picaxe doesn’t perform anymore. What am I doing wrong here?

“Doesn’t perform.” What does that mean? If you modify your code to blink an LED as well, does it work when you connect the sensor? Can you write data to the debug port and see it in the PICAXE IDE?

Which PICAXE are you using?

Can you provide some or all of your code for review?

I am using an 18x dip chip. When the sensor detects something it is going to pulse a motor. Here is an example of the code I am using. It’s a very simple code for now.

Main: readadc 2,b0

If b0 > 200 then pulse1

If b0 > 50 then pulse2

Gotomain

Pulse1: high 1

Wait 5

Low 1

Wait 5

Gotomain

Etc.

When everything is hooked up, if I put my hand in front of the sensor and depending on what value it sees on adc2 the program is suppose to pulse the motor on output 1. When I do this I get nothing on the output.

If I remove the vcc and gnd of the sensor from the circuit and tap the adc2 pin with 5v then the motor pulses. Hook it back up and nothing.

I tried using debug after the readadc. I had to remove the sensor from the circuit so I could download the code. Once it downloaded the debug counter starting counting. When I hooked the sensor back up to just the vcc and gnd the counter on the debug stopped. I tried several times in different scenarios and I couldn’t get the debug to read the input value.

I measured 54k ohms between vcc and gnd for the sensor. I don’t know what it supposed to be but at least it is not shorted. And I get a good analog signal on the output. I am using a regulated 5v supply that is built into the breadboard that I made in DeVry a long time ago and I know it is working fine. I also measured the current draw of the sensor and it was only 26mA.

I have seen some picaxe projects using this sensor so I know it can work with but I am not understanding this particular failure.

Well, I ordered a long range sensor just for the purpose of experimentation for my project and to see if it had a different outcome than the other sensor. And it didn’t.

Everytime I hook a sensor up to power and ground, don’t even need the output pin of the sensor to the chip, the chip doesn’t work. The sensor works fine, but the chip seems like its put in hold state. No inputs or outputs do anything.

Wierd! I’m about to give up. Please help!

Sorry, vertigonix, I missed your response earlier this month. I’ll hook up a PICAXE tonight and have a look.

I wired up one of my Sharp sensors to a PICAXE 18X and it works fine. I have the output of the sensor going to Analog 2 (Pin 1). The program reads the sensor via one of the ADC ports (#2) and outputs the reading to the debug port. I’m not sure why you have to disconnect the sensor to get the serial port working. Check your wiring again.

Other things to check…

  1. Do you have a pull-up (10k or so) from the reset (MCLR) pin to +5v?

  2. Do you have decoupling capacitors across the VDD and VSS lines? You should have a .1 uF and something like a 10 uF - 47uF across the power.

Hope this helps moves your project forward.

riden:
I wired up one of my Sharp sensors to a PICAXE 18X and it works fine. I have the output of the sensor going to Analog 2 (Pin 1). The program reads the sensor via one of the ADC ports (#2) and outputs the reading to the debug port. I’m not sure why you have to disconnect the sensor to get the serial port working. Check your wiring again.

Other things to check…

  1. Do you have a pull-up (10k or so) from the reset (MCLR) pin to +5v?

  2. Do you have decoupling capacitors across the VDD and VSS lines? You should have a .1 uF and something like a 10 uF - 47uF across the power.

Hope this helps moves your project forward.

Im kinda new to electronics (played with 555 ect…), How do you connect a decouping Cap? Also whats does the pull-up resistor do?

Thanks,

Matthew

matthew945:
Im kinda new to electronics (played with 555 ect…), How do you connect a decouping Cap? Also whats does the pull-up resistor do?

Decoupling capacitors are placed across the power lines (VDD/VDD or VCC/GND) to keep the power lines “clean”. They should be placed as close to the power lines of the micro-controller as possible. There is another thread on the forum gets into more details, but the values I mentioned are generally considered good values.

A pull-up resistor is a resistor that ensures that an input pin of a micro-controller is at a known logic state (1). If a pin is configured as an input pin (and the PIC I/O pins power up as input pins), the pin will be floating without a pull-up leading to erratic behavior. For example, a floating reset pin means that the micro-controller may reset unexpectedly or not run at all.

riden:

matthew945:
Im kinda new to electronics (played with 555 ect…), How do you connect a decouping Cap? Also whats does the pull-up resistor do?

Decoupling capacitors are placed across the power lines (VDD/VDD or VCC/GND) to keep the power lines “clean”. They should be placed as close to the power lines of the micro-controller as possible. There is another thread on the forum gets into more details, but the values I mentioned are generally considered good values.

A pull-up resistor is a resistor that ensures that an input pin of a micro-controller is at a known logic state (1). If a pin is configured as an input pin (and the PIC I/O pins power up as input pins), the pin will be floating without a pull-up leading to erratic behavior. For example, a floating reset pin means that the micro-controller may reset unexpectedly or not run at all.

Thanks for the information.

  1. Do you have a pull-up (10k or so) from the reset (MCLR) pin to +5v?

  2. Do you have decoupling capacitors across the VDD and VSS lines? You should have a .1 uF and something like a 10 uF - 47uF across the power.

Thanks for the response Riden!

I don not have the resistor in place but I do have MCLR going to 5v.

I also don’t have the cap in place. I will try that. But it still confuses me that the circuit runs fine until I add the sensor power and ground to the circuit, without even hooking up the signal wire.

I will try rebuilding my circuit and added the components you mentioned and see if that helps.

Thanks again!

Connecting MCLR to +5 is okay. The only thing you lose is the reset capability (you will need to do a power off/on cycle). The capacitors may help if the sensor is putting noise on the power line. One thing to check is the voltage after connecting the sensor to the controller. It may very well be that your power supply can’t supply enough current. What kind of power supply are you using?

Thanks for the tip on the capacitor, Riden! That did it. Once I put a cap across the vcc and gnd it started to work like it should. thanks a bunch!

Glad I could help, Vert. Good luck on the rest of your project.