Two Questions: Hello in the video at 1:40, i had replaced the 4.3k resistor with 4.7k resistor, what would be the change in the gpio input when the ir phototransistor is active and unactive (light falls and doesn't fall). Thanks And https://www.youtube.com/watch?v=KLeQTd1Ll_g Here is the video for my current project. I was going to modify the code given after trying it but the code did not work at all or atleast did not return any values. Nothing shows up after I activate the code. Just the main screen for python 3 home and a restart statement. I have built the circuit.(circuit without the extra led and the first given code in pyhton 3 on raspberry pi 2. I have updated and upgraded. What should I do?) The print function does not work. I doubt that the rest of the funcetion in while function works. If i add print before while, it prints that comment like: print "ok" prints ok when run (the rest of the code is the same. only added, didn't remove anything) but the rest of the function does not work. How do I fix it? Thanks
Sorry about the incomplete question. (i'll leave the previous questions for reference) Here is the code:
import RPi.GPIO as GPIO import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.IN)
start = time.time() stop = time.time() gateState = False
try:
while True:
if (GPIO.input(11) != gateState):
gateState = not gateState
if (gateState == True):
start = time.time()
else:
stop = time.time()
if stop - start > 0.0001:
print "Time: ", stop - start, "s"
print "Speed: ", 1.5/(stop-start), "m/s"
print " " except KeyboardInterrupt:
GPIO.cleanup()
When I execute this code, it causes false data to appear.
afterwards. more random digits start appearing as data. I know this is wrong because blocking the ir led has no effect and pushing the ground pin to the side creates rapid data of very small speed. What am i doing wrong. My circuit is: [![Here is the circuit except that the 4300 ohms R1 is 4700 Ohms instead][2]][2]
[2]: image 2[Here is the circuit except that the 4300 ohms R1 is 4700 Ohms instead. as a comment because i cant post more than 1 image. sorry][2]