Skip to content

Instantly share code, notes, and snippets.

@fasmide
Created December 23, 2013 23:01
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fasmide/8106296 to your computer and use it in GitHub Desktop.
Save fasmide/8106296 to your computer and use it in GitHub Desktop.
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.setmode(GPIO.BCM)
GPIO.setup(11, GPIO.IN)
timer = False
monitor_is_on = True
def monitor_off():
global monitor_is_on
subprocess.call(['/opt/vc/bin/tvservice', '-o'])
monitor_is_on = False
def monitor_on():
global monitor_is_on
subprocess.call(['/opt/vc/bin/tvservice', '-p'])
subprocess.call(['fbset -depth 8'], shell=True)
subprocess.call(['fbset -depth 16'], shell=True)
subprocess.call(['xrefresh'], shell=True)
monitor_is_on = True
while True:
time.sleep(0.5)
movement = GPIO.input(11)
if movement:
if timer:
print "canceler timer"
timer.cancel()
timer = False
if not monitor_is_on:
print "Taender skaerm"
monitor_on()
else:
if not timer:
print "starter timer"
timer = Timer(60*5, monitor_off)
timer.start()
@ShazaibSohail
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