Skip to content

Instantly share code, notes, and snippets.

Created December 23, 2013 23:01
What would you like to do?
Turns the hdmi port on and off by reading a PIR sensor off a raspberry pi GPIO port 11
import RPi.GPIO as GPIO
import time
from threading import Timer
import subprocess
GPIO.setup(11, GPIO.IN)
timer = False
monitor_is_on = True
def monitor_off():
global monitor_is_on['/opt/vc/bin/tvservice', '-o'])
monitor_is_on = False
def monitor_on():
global monitor_is_on['/opt/vc/bin/tvservice', '-p'])['fbset -depth 8'], shell=True)['fbset -depth 16'], shell=True)['xrefresh'], shell=True)
monitor_is_on = True
while True:
movement = GPIO.input(11)
if movement:
if timer:
print "canceler timer"
timer = False
if not monitor_is_on:
print "Taender skaerm"
if not timer:
print "starter timer"
timer = Timer(60*5, monitor_off)
Copy link

1kohm commented Jan 23, 2016

Dear Fasmide,

that's nice piece of code and it works like a charm.
I'd like to start this code only in certain hours, for example: start @07:00AM and stop 10:00PM every day.
Due to fact that I'm Python beginner, could you guide me how to modify this code? I'm thinking about function time.time().

Copy link

ShazaibSohail commented Sep 12, 2018

Bro can you please show a hardware setup via picture, basically connection of PI Sensor to Raspberry Pi, I am newbie to Raspberry Pi environment, it will be great if you help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment