Photoresistor
Hardware
Raspberry Pi |
Photoresistor |
1 uf
|
GPIO 4 |
PIN A |
|
GND |
GND |
GND |
+5V
|
|
+VCC |
Python
$ sudo nano photoresistor.py
DEBUG = 1 GPIO.setmode(GPIO.BCM) def RCtime (RCpin): reading = 0 GPIO.setup(RCpin, GPIO.OUT) GPIO.output(RCpin, GPIO.LOW) time.sleep(0.01) GPIO.setup(RCpin, GPIO.IN) # This takes about 1 millisecond per loop cycle while (GPIO.input(RCpin) == GPIO.LOW): reading += 1 return reading while True: print RCtime(4) # Read RC timing using pin #18
Test and Result
Test :
$ sudo python phtotresistor.py
Result :
1800
374
2507
403
398
502
1804
385
4373
390
369
|
|
|
|
|