RPi with IR Sensor - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: RPi with IR Sensor (/thread-11134.html) |
RPi with IR Sensor - pimlicosnail - Jun-24-2018 Hello, I'm building a IRSensing robot (obstacle avoiding) using information I got from a beginner's website. I can't tell whether the problem I'm having is with the IR Sensors or with the code I'm using. I had to make several changes to the code from what the website posted to stop receiving syntax and indentation errors, but now all I get is nothing when I run the python file. Can someone check the code to make sure I don't still have something wrong with it? import RPi.GPIO as GPIO import time GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(3, GPIO.IN) #Right sensor connection GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Left sensor connection while True: i=GPIO.input(3) #Reading output of right IR sensor j=GPIO.input(16) #Reading output of left IR sensor if i==0: #Right IR sensor detects an object print "Obstacle detected on Left",i time.sleep(0.1) elif j==0: #Left IR sensor detects an object print "Obstacle detected on Right",j time.sleep(0.1) RE: RPi with IR Sensor - Larz60+ - Jun-24-2018 are you receiving any errors? if so, please post. Just an FYI, indentations should be 4 spaces per level {per PDP 8) |