How to set up an IR Distance sensor?

Although I’ve tinkered around a little bit so far with other sensors, I’m really new to anything else and so I’m not 100% sure how to set up my IR Distance sensor (part of the Electron Sensor kit).

The model is Sharp GP2Y0A710, and I’m using a Particle Electron with breadboard. The sensor has two GND wires, two VCC wires and an output wire. I assume the output goes to A0, and the GND wires go to the GNDs on both sides?

I tried to look for any libraries or documentation but I couldn’t find a clear-cut answer for this specific sensor.

My current setup:

EDIT: Above setup works once LiPo battery is added and the red VCC wires are linked to VIN instead

The wiring sounds right.

Black --> GND
Red --> Vin
White --> A0

Take note that you need to have the Lipo battery attached when using the electron as well.

I see a library available --> https://github.com/guillaume-rico/SharpIR

Happy to help make it available in the Web IDE if required :slight_smile:

2 Likes

Oh I see! I didn’t know this was a requirement. I assumed my setup was semi-working already as on some rare occurances I did get one or two (inaccurate) readings, but 98% of the time the sensor couldn’t take any readings. So I guess getting a LiPo on there, and moving the VCC wires from 3V3 to VIN should do the trick.

Thanks for the linked library, that should be very useful!

I tested the library code for an hour or two but there’s no way I can manage to get any accurate readings from the sensor. It has a tendency to severely underestimate distances (e.g. a wall 3 metres away shows up as 60cm away)or no readings at all (even with a perpendicular, non-black object between 1 to 5 metres away).

@Vitesze, questions:

  1. Is your USB supply good quality capable of 1A, ideally 2A?
  2. Did you specify “100500” as the model number? (100500 is for GP2Y0A710K0F)

Sorry, here's the code (the default code):
Particle Web IDE

Yes I specified '100500' for the model number. The USB is plugged in my PC, so it should draw sufficient power. I haven't tried testing the sensor off the battery itself but I will try that now as well.

Here's also my current setup:

Depending on your PC, the USB port may only supply 500ma so if you have a power cube that can supply more, I would try that.

Nope, don't try that. The unit requires a minimum of 4.5v which the battery can't supply.

Also, you may want to elevate the sensor off the table to prevent secondary reflections.

Can you explain which pin the white wire connects to as well as the white jumper?

1 Like

White jumper runs from A0 to I7. Wire runs from J7 to the sensor.

Would changing the battery to one that can support more voltage work? Which kind of voltage would be recommended for the electron in this case? I would like this sensor to be wireless for an IOT project, so a power cube unfortunately is not really an option.

@Vitesze, put the white jumper from the sensor directly to A0. What is “I7”? Did you mean D7?

For battery operation, you may need to consider a different sensor which can run at a lower voltage or add a step-up dc-dc converter to get 5v.

Oh I see, if I would add a step-up dc-dc converter such as this http://www.ebay.com/itm/DC-DC-3V-3-7V-5V-Step-Up-to-5V-2A-Lithium-Battery-Boost-Charging-Power-Module-/182162410920 (input 2 to 5V, output 5V) then in combination with the default LiPo battery Particle supplies, it should be able to supply enough voltage to operate this sensor?

It seems almost all of the sensors I could potentially use for my little project require a minimum of 4.5V.

@Vitesze, the default battery can’t do magic in terms of running the Electron and other peripherals for a long time. It is primarily there to supply boost current while establishing a cell connection. You will need to consider a secondary voltage source or, for example, a solar panel for recharging the battery. As for the dc-dc converter, I would recommend a higher quality one from Polulu.

Did you make the wiring changes I suggested?

Yes, I made the wiring changes you suggested. Readings are still all over the place.

I understand the battery isn’t able to sustain the sensor for a long time; my plan however is to only have the device turned on for a maximum of 1 minute a day. The rest of the day it will be in deep sleep mode. Hopefully this should allow the battery to last quite a while. Solar panel would not be possible as it will be for use indoor.

There’s a small change I may still be able to salvage a bit out of this situation though; the thing is that the sensor actually is allowed to be very inaccurate. As long as it can distinguish between objects about 3 meters away, and 1 meter away it should be sufficient. Right now it does seem to make this little distinction, with objects at 0.5-1.5 metres being 80-90cm away, and objects at 3 metres being 120-130cm away (according to sensor)

I guess something like this would be good for this project though? https://www.pololu.com/product/2565
a DC-step up from 3.7V to 5V while being able to also deliver the neccessary A

Thanks a lot for this very fruitful discussion so far, things make so much more sense to me now.

@Vitesze, can you post a picture of your setup again. Am I correct that you had the white wire connected to D7 before?

You don’t need a 5A converter! This one is more suitable:

2 Likes

Yes in hindsight, it seems I indeed accidently wired to D5 as well. Now the white wire goes straight to A0.

Thanks for the link, I’ll give this a try. Would the 1.2A be sufficient still?

@Vitesze, the converter is only for the IR sensor which has a draw of about 30ma!

Thanks, I thought so but just wanted to make sure. I ordered the Regulator you linked and will see how this work out. Thanks a lot for all your help and advice.

@Vitesze, I am trying to understand why you are getting noisy data. Having connected the analog output of the sensor to both D5 may or may not have caused problems with the sensor. You may want to change the analog pin used (eg A1) and also change the port used in the library (if possible).

Oh I see, i tried switching to A1 but not much seems to have changed. Aiming it up towards the ceiling returns values of between 80 and 100cm (should be about 200 to 250)

Here’s my setup:

@Vitesze, something is not right. Do you have a multimeter?

Yes I do, what should I do with the multimeter?
I also just received my 5V DC regulator by mail.