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
  Averaging sensor results igorv1234 1 2,733 Jun-17-2021, 04:08 PM
Last Post: topfox
  Code Wireless Temperature sensor and send sensor readings to google sheet jenkins43 0 3,187 Nov-29-2018, 12:44 PM
Last Post: jenkins43
  need help with ultrasonic sensor code mpmm366 6 6,215 Jun-28-2018, 08:41 PM
Last Post: gontajones
Question DHT11 Sensor Programming bmakloski 3 4,899 Jun-28-2018, 06:59 PM
Last Post: bmakloski
  PIR Sensor to control screensaver toothie96 5 10,019 May-14-2017, 01:01 PM
Last Post: sparkz_alot

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.