Devices & Components
Arduino Uno Rev3
PIR Sensor, 7 m
Software & Tools
Arduino IDE
Python (IDLE)
Project description
Code
Arduino Code
arduino
1int ledPin = 13; // LED on Pin 13 of Arduino 2int pirPin = 7; // Input for HC-S501(PIR-sensor) 3int pirValue; // Place to store read PIR Value 4 5void setup() { 6 pinMode(ledPin, OUTPUT); 7 pinMode(pirPin, INPUT); 8 digitalWrite(ledPin, LOW); 9 Serial.begin(9600); 10} 11 12void loop() { 13 pirValue = digitalRead(pirPin); 14 digitalWrite(ledPin, pirValue); 15 if(pirValue==HIGH){ 16 Serial.println("1"); 17 pirValue=0; 18 } 19} 20 21
Arduino Code
arduino
1int ledPin = 13; // LED on Pin 13 of Arduino 2int pirPin = 7; // Input 3 for HC-S501(PIR-sensor) 4int pirValue; // Place to store read PIR Value 5 6void 7 setup() { 8 pinMode(ledPin, OUTPUT); 9 pinMode(pirPin, INPUT); 10 digitalWrite(ledPin, 11 LOW); 12 Serial.begin(9600); 13} 14 15void loop() { 16 pirValue = digitalRead(pirPin); 17 18 digitalWrite(ledPin, pirValue); 19 if(pirValue==HIGH){ 20 Serial.println("1"); 21 22 pirValue=0; 23 } 24} 25 26
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")
1#Libaries 2import serial #to install type 'pip install serial' in cmd 3import time #to install type 'pip install time' in cmd 4import os #to install type 'pip install os' in cmd 5#import pyttsx3 #not necessary only if you want(for sound) 6 7 8 9#classes 10def read(): 11 ArduinoSerial = serial.Serial('com3',9600) #CHANGE IF NECESARRY! 12 time.sleep(2) 13 line = ArduinoSerial.readline() 14 line = line.replace(b'\ \ 15',b'') 16 line = line.decode("utf-8") 17 line = int(line) 18 if (line==1): 19 close() 20 #talk() 21 22def close(): 23 try: 24 print("Worked!") 25 os.system('TASKKILL /F /IM ^chrome.exe') #application which closes 26 except Exception as e: 27 print (e) 28 29def wait(): #to prevent mailfunctions 30 s=20 31 for n in range(0,20): 32 s=s-1 33 print("Please wait") 34 print("Ready in: ",s) 35 time.sleep(1) 36 os.system('cls') #deletes content on cmd (not in python shell) 37 read() 38 39#def talk(): #delete the hashtag if it should talk 40# saythis = pyttsx3.init() 41# saythis.say("Oh shit") 42# saythis.runAndWait() 43 44 45 46#to start the programm 47wait()
Downloadable files
circuit diagram
circuit diagram
circuit diagram
circuit diagram
Comments
Only logged in users can leave comments