adrian_h
Published © GPL3+

Python + PIR-Sensor + Arduino = Display Privacy at Work

If somebody approaches your computer or the sensor (PIR), the programm closes automatically any application, so nobody sees what you do

BeginnerFull instructions provided713
Python + PIR-Sensor + Arduino = Display Privacy at Work

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
PIR Sensor, 7 m
PIR Sensor, 7 m
×1

Software apps and online services

Arduino IDE
Arduino IDE
Python (IDLE)

Story

Read more

Schematics

circuit diagram

Code

Arduino Code

Arduino
int ledPin = 13;  // LED on Pin 13 of Arduino
int pirPin = 7; // Input for HC-S501(PIR-sensor)
int pirValue; // Place to store read PIR Value

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(pirPin, INPUT);
  digitalWrite(ledPin, LOW);
  Serial.begin(9600);
}

void loop() {
    pirValue = digitalRead(pirPin);
    digitalWrite(ledPin, pirValue);
    if(pirValue==HIGH){
      Serial.println("1");
      pirValue=0;
    }
}

Python

Python
Make sure, you have the right port selected.
You have to import the libaries first. To do this go to cmd and enter "pip install serial". After this you also have to import the other libaries! ("pip install time"; "pip install os")
#Libaries
import serial         #to install type 'pip install serial' in cmd
import time           #to install type 'pip install time' in cmd
import os             #to install type 'pip install os' in cmd
#import pyttsx3    #not necessary only if you want(for sound)



#classes
def read():
    ArduinoSerial = serial.Serial('com3',9600) #CHANGE IF NECESARRY!
    time.sleep(2)
    line = ArduinoSerial.readline()
    line = line.replace(b'\r\n',b'')
    line = line.decode("utf-8")
    line = int(line)
    if (line==1):
        close()
        #talk() 
        
def close():
    try:
        print("Worked!")
        os.system('TASKKILL /F /IM ^chrome.exe') #application which closes
    except Exception as e:
        print (e) 
        
def wait(): #to prevent mailfunctions
    s=20
    for n in range(0,20):
        s=s-1
        print("Please wait")
        print("Ready in: ",s)
        time.sleep(1)
        os.system('cls')  #deletes content on cmd (not in python shell)
    read()
    
#def talk():      #delete the hashtag if it should talk
#    saythis = pyttsx3.init()
#    saythis.say("Oh shit")
#    saythis.runAndWait() 



#to start the programm
wait()

Credits

adrian_h
0 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.