Datasheet

6
4.Navigate to the demos' directory:
cd yourpath/GrovePi/Software/Python/
To see the code
nano grove_relay.py # "Ctrl+x" to exit #
import time
import grovepi
# Connect the Grove Relay to digital port D4
# SIG,NC,VCC,GND
relay = 4
grovepi.pinMode(relay,"OUTPUT")
while True:
try:
# switch on for 5 seconds
grovepi.digitalWrite(relay,1)
print "on"
time.sleep(5)
# switch off for 5 seconds
grovepi.digitalWrite(relay,0)
print "off"
time.sleep(5)
except KeyboardInterrupt:
grovepi.digitalWrite(relay,0)
break
except IOError:
print "Error"
5.Run the demo.
sudo python grove_relay.py