Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using IR Sensors #10

Open
ehansi opened this issue Aug 28, 2018 · 2 comments
Open

Using IR Sensors #10

ehansi opened this issue Aug 28, 2018 · 2 comments

Comments

@ehansi
Copy link

ehansi commented Aug 28, 2018

Hello,

I bought an analog IR distance sensor (https://www.robotshop.com/en/sharp-gp2y0a21yk0f-ir-range-sensor.html) and wanted to test it on the motor-shield. I've connected VCC to +, GND to -, and V0 to OP on the board. Running the provided test program there seems to be no reaction, IR is never triggered.
Tested on both IR connectors. I'm pretty new to all of this so I guess I'm missing something very basic. Thanks for any help, people!

@sgarret3
Copy link

sgarret3 commented Dec 17, 2018

My problems were because something is backwards here for the IR sensors only. When I use this example code:
#-------------------------------#
from PiMotor import Sensor
ir1 = Sensor ("IR1",0)
ir1.trigger()
if ir1.Triggered:
print("Obstruction Detected")

#-------------------------------#

This code would only enter the IF statement when there was NOT an obstruction, which was causing me misery when I kept putting something in front of the sensor, and it would never enter the IF statement. I had to rewrite the code to follow this form:

#-------------------------------#
from PiMotor import Sensor
ir1 = Sensor ("IR1",0)
ir1.trigger()
if ir1.Triggered:
print("Nothing Detected")
# keep going on like normal#
else:
print("Obstruction Detected")
#code for when IR sees an obstruction#
#-------------------------------#

PiMotor.py has an IR pin voltage backwards (checking for pin voltage up when they mean down or vice versa) but I don't know how to fix it. This also applies to IR2 input.

If you just want a piece of code as an example. Here is a very unfinished, untested, (and poorly written) chunk of something I am preparing for some kids to demonstrate a little tank navigating a simple maze. You might want to take a look if you want to see the indents, since this editor is not saving my indentations above which Python requires.

Tank.txt

@mc03225
Copy link

mc03225 commented Apr 14, 2019

Hi,
Take a backup of PiMotor.py, then change line 233
if input_state != True: (it was set to equals ==)
Now try
while True:
if ir1.iRcheck():
print("Detected")
else:
print("Not Detected")

I hope this helps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants