Unable to make 80cm Infrared Proximity Sensor work

Hi all,

I purchased a bunch of “80cm Infrared Proximity Sensor” devices and I’m unable to make them work as expected.

Once connected to D4, as per the sample instructions, when I run the “grove_infrared_distance_interrupt.py” sample (with and without sudo), I always get “found something” result. No matter that there’s nothing in front of the sensor for way more than 80cm.

Is there anything special that must be done to make it work?

Thanks,
Carlos

1 Like

Anyone from Dexter Industries support???

1 Like

Hi @ccasares,

Can you give us a link to the sensor you have bought?

Also, I think you may be running the wrong script. This is, I guess, the one you need to run:

Thank you!

1 Like

Hi Robert,

Sorry for my late response. You’re right. I now recall I also tried that script (grove_80cm_infrared_proximity_sensor.py). When I run it, using sudo and making sure I connect the sensor to the A0 port, I always get the following responses ranges, no matter I place my hand in front of the sensor (1cm) or leaving no object in front of it:

sensor_value: min=350 max=374
voltage: min=1.71 max=1.83

I’m not sure whether the sensor is really working or not, but I see no real difference when I place my hand or not at all.

I purchased 7 devices and tried all of them. Same result with all. BTW, this is the sensor: https://www.seeedstudio.com/Grove-80cm-Infrared-Proximity-Sensor-p-788.html

Any idea?

Thanks

1 Like

You should be able to read the analog value from this sensor with the python function analogRead(pin)

ie:

import grovepi
print(grovepi.analogReadPin(0))

The value should change as you move an object in the detection range of the sensor (10cm to 80cm).

Ideally you’ll probably want to loop and average several readings, but this should get you started.

Info. about analogRead(pin) and GrovePi port descriptions here:
https://www.dexterindustries.com/GrovePi/engineering/port-description/

1 Like

All these years later I’ve exactly the same issue as OP and I’m wondering how he managed to solve it. Because no matter what I put in front of it I always get the same read out no matter if it’s 10 cm or 80 cm. I switched pins, switched read outs switched everything I can possibly switch but it’s always ~10cm. Code I’m using:

import time
import grovepi

class ProxySensor:
    def __init__(self, sensor):
        self.sensor = sensor # an integer
        grovepi.pinMode(sensor, "INPUT")
        time.sleep(1) # this is a hardware thingy

    def read(self):
        adc_ref = 5
        total = 0
        for i in range(20):
            sensor_value = grovepi.analogRead(self.sensor)
            total += sensor_value

        total_value = total / 20

        return (
            total_value,
            round((float)(total_value) * adc_ref / 1024, 2)
        )

def main():
    proxy_sensor = ProxySensor(1)
    while True:
        print(proxy_sensor.read())
        time.sleep(.5)

if __name__ == '__main__':
    main()
1 Like

As weird as it sounds, I made it work whit the official code… connected the sensor to A0, but used the “sensor = 1” in the code… still trying to understand why this is happening. Same problem whit other sensors (like grove air quality), and it works with A0 but using “sensor = 1”.

Enviroment:

  • Raspberry Pi B+
  • Raspbian for Robots by Dexter (Stretch)
  • Grove Pi+

With the provided code, if you use:

  • A0 → sensor = 1
  • A1 → sensor = 2
  • A2 → sensor = 3

Any reason to all of this?

2 Likes

Because this was originally designed to be used in a teaching environment, and people naturally start counting with “1” instead of “0” as computers do.
:wink:

1 Like