Jun-24-2018, 08:01 AM
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?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
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 ) |