GM5539 Photocell

  • http://www.amazon.com/dp/B00AQVYWA2/
    • Maximum Wattage: 100mW
    • Operating Temperature: -30 ~ +70 deg C
    • Spectral Peak: 540nm
    • Light Resistance (10 Lux): 50-100 Kohm
    • Dark Resistance: 5Mohm

Setup

because these are Light Dependent Resistors, a 10kΩ resistor is used to complete a resistive divider to read the sensors with an ADC.


In [4]:
!ls /dev/ttyACM*


/dev/ttyACM0

In [1]:
import time
from pyfirmata import Arduino, util
import pyfirmata
board = Arduino('/dev/ttyACM0')
it = util.Iterator(board)
it.start()
for an in board.analog:
    an.enable_reporting()
def readan(an):
    return an.read()

In [2]:
%%timeit
for an in board.analog:
    an.read()


100000 loops, best of 3: 2.6 µs per loop

In [3]:
%timeit map(readan, board.analog)


100000 loops, best of 3: 3.22 µs per loop

In [69]:
map(readan, board.analog)


Out[69]:
[0.4125, 0.3656, 0.3314, 0.4194, 0.3959, 0.4066]