Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RPi with IR Sensor
#1
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)
Reply
#2
are you receiving any errors? if so, please post.
Just an FYI, indentations should be 4 spaces per level {per PDP 8)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Code Wireless Temperature sensor and send sensor readings to google sheet jenkins43 0 2,198 Nov-29-2018, 12:44 PM
Last Post: jenkins43

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020