import time import grovepi from grovepi import * # Connect the Grove Light Sensor to analog port A0 # SIG,NC,VCC,GND light_sensor = 0 # Connect the LED to digital port D4 # SIG,NC,VCC,GND led = 4 # Turn on LED once sensor exceeds threshold resistance threshold = 10 # Connect the Motion Sensor to digital port D3 pir_sensor = 8 motion=0 grovepi.pinMode(pir_sensor,"INPUT") grovepi.pinMode(light_sensor,"INPUT") grovepi.pinMode(led,"OUTPUT") while True: try: # Get sensor ValueError sensor_value = grovepi.analogRead(light_sensor) # Calculate resistance of sensor in K resistance = (float)(1024 - sensor_value) * 10 / sensor_value if resistance > threshold: motion=grovepi.digitalRead(pir_sensor) elif motion==0 or motion==1: time.sleep(1) if motion==1: print("sensor_value = %d resistance = %.2f" %(sensor_value, resistance)) time.sleep(.3) grovepi.digitalWrite(led,1) else: if motion==0: grovepi.digitalWrite(led,0) time.sleep(1) print ('-') except IOError: grovepi.digitalWrite(led,0) print ("Error")