The Explorer PCB has an infrared proximity sensor at each of it's four corners. This consists of three little LEDs (or LED like things). Two of them are side by side hanging from under the board. One of these is the IR emitter and the other is the reader. On the top of the board is a little LED that lights when the IR emitter is active (since you can't see IR).
Power for these sensors is provided by the board so connecting them is a matter of four wires from the board to digital pins on the Arduino for triggering the IR and another four to analog input pins for reading the proximity.
The code below shows my test code reading the Right Front corner. Note that this code is based on my Python to Arduino Interface but is 1-1 analogous to what you would code in Arduino directly.
import time
from Py2Ard import interfaceClass
# Instantiate the interface class
my_board = interfaceClass('/dev/ttyUSB0')
# Pin assignments for operations
TriggerRF = 36
InputRF = 10
# Set the pin modes
my_board.pinModeOutput(TriggerRF)
my_board.pinModeInput(InputRF)
while 1==1:
# Turn on the infra red
my_board.setHigh(TriggerRF)
# Take a reading
my_board.analogRead(InputRF)
reading = int(my_board.returnValue)
# Turn off the infra red
my_board.setLow(TriggerRF)
# Take a reading (this will be the ambient light)
my_board.analogRead(InputRF)
ambient = int(my_board.returnValue)
# Subtract ambient for your proximity reading
print "RF = " + str(reading - ambient)
time.sleep(1)
No comments:
Post a Comment