I want to use the photoelectronic with the Raspberry Pi for a micromouse maze.
Using sensors to detect the presence of micromouse at specific locations. I was given all this from my father since he's very into robotics but doesn't have time to help me since he's always~ busy but I do find it interesting. My friends and I usually do all kinds of things with the Raspberry Pi but first time with sensors and we're stuck.
The sensor will be placed under the white plastic,overall i'm expecting it to look like this:
Which is not working, it's just an example. I want to know how to use this sensor with the raspberry and the programming codes. I believe it should be python. If I can do this I would want to make other fun application with the sensor.So when the micromouse goes through this thing it will detect and starts the timer and the next time it goes through it detects again that something went past and stops the timer. Running on raspbian and ssh using putty.
as my sensor need 12-24V which the raspberry doesn't have enough power to power it up. So I connect the Raspberry Pi to ground but not using the raspberry pi"s power supply. The codes are from the website above:
#!/usr/bin/python #+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ #|R|a|s|p|b|e|r|r|y|P|i|-|S|p|y|.|c|o|.|u|k| #+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ # # pir_1.py # Detect movement using a PIR module # # Author : Matt Hawkins # Date : 21/01/2013 # Import required Python libraries import RPi.GPIO as GPIO import time # Use BCM GPIO references # instead of physical pin numbers GPIO.setmode(GPIO.BCM) # Define GPIO to use on Pi GPIO_PIR = 7 print "PIR Module Test (CTRL-C to exit)" # Set pin as input GPIO.setup(GPIO_PIR,GPIO.IN) # Echo Current_State = 0 Previous_State = 0 try: print "Waiting for PIR to settle ..." # Loop until PIR output is 0 while GPIO.input(GPIO_PIR)==1: Current_State = 0 print " Ready" # Loop until users quits with CTRL-C while True : # Read PIR state Current_State = GPIO.input(GPIO_PIR) if Current_State==1 and Previous_State==0: # PIR is triggered print " Motion detected!" # Record previous state Previous_State=1 elif Current_State==0 and Previous_State==1: # PIR has returned to ready state print " Ready" Previous_State=0 # Wait for 10 milliseconds time.sleep(0.01) except KeyboardInterrupt: print " Quit" # Reset GPIO settings GPIO.cleanup()
Once, I connect it up the code stuck at :
Waiting for PIR to settle ... Ready
Eventhough my sensor was turn green red as it detects my hand,the code should have display motion detected but it didn't. I don't know what is the problem. I check the output voltage of the sensor and it was 0.735 V when nothing is detected but when it detects it goes to 42.4 mV. So I think that when nothing its detected it is a close circuit but when it detects it opens the circuit so the input change state by seeing the code above then it displays motion detected. I don't know whether the problem is that the input voltage when has'nt been detected is not enough for the Raspberry Pi to recognized it or receive as the voltage is too low which concludes the reason why it stays at ready even though the sensor changes from green to red when it detects my hand.