IoT Haunted Doorstep - Table of Contents

Project Introduction - Part 1 |  Breadboard Basics - Part 2 | The Build - Part 3 | Giving it a Try - Part 4

Return to Halloween |  Dave Edward's VCP Profile

 

 

 

Thank you for joining me again for the final part of my Halloween build. It's finally here, to hook up all the electronics and polish the final script!

 

There is a lot going on in the final script, so I figure it is best to break down the elements of it:

 

Video Control:

I was intending to make something really cool for the video, and still hope to have it done for the 31st! Unfortunately, I was a little behind with the big reveal. I ended up hacking together two small video clips, one that looped every 45 Seconds of a "twitchy zombie", and the other of the "zombie" rush toward the door. As the looping video is largely in the same position, the "jump" from the loop to the "rush" doesn't seem out of place with the sounds and lights.

 

To control the video playback from Python:

 

import os                           #Import operating system control
from subprocess import Popen        #Import Process Open

loopVid = ("/home/pi/Desktop/loop.mp4")      #Name the file and path of the looping video
rushVid = ("/home/pi/Desktop/rush.mp4")      #Name the file and path of the "rush" video

os.system('killall omxplayer.bin')                #Stop and video that is currently playing
omxc = Popen(['omxplayer', '-b --loop',looptVid])        #Set up the looping video

 

This has set up the video that can play in a loop until the capacitive touch is triggered. When it is, we stop the loop, play the "rush" video, then restart the loop after it has played:

 

os.system('killall omxplayer.bin')           #Stop playing the loop video 
omxc = Popen(['omxplayer', '-b', rushVid])   #play the "rush" video 
time.sleep(5)                                #wait the length of the "rush" video 
print("Reset")                               #output to the console that the loop is being reset 
os.system('killall omxplayer.bin')           #ensure that the rush video is removed 
omxc = Popen(['omxplayer', '-b --loop', loopVid])   #restart the loop video

 

Remember that the video playback only shows on the HDMI output. I was using VNC at this point, and thought it wasn't working!

Relay Control:

Relay control is really easy, that is just using the GPIO control to write an output high and low. With the GPIO control already in the script, there is no need to import any additional controls. However, I did add the pin I was using for control to the variables declared at the begining, then switch it!

relay_output=26      #Define the GPIO number as a variable  

GPIO.setup(relay_output, GPIO.OUT)      #Add this to the script where we define the GPIO modes 
 
GPIO.output(relay_output,GPIO.HIGH)      #Used to turn the relay off (because of the way i wired mine) 
GPIO.output(relay_output,GPIO.LOW)      #Used to turn the relay on (your "HIGH" and "LOW" may be the other way)

 

"Smart Light" Control:

This is very specific to the equipment I have, but it is useful for other things too (local network unsecure communications). Once I have set up my home device with the MAC address of the PI (Which i did twice, once for the WIFI and once for the LAN I had used in testing!) I could send some UDP strings that it would respond to.

 

import socket      #Import the socket library for network connections  
UDP_IP = "192.168.1.7"      #define the local IP of the home device 
UDP_PORT = 9760      #The port that the device listens on 

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)      #Configures the type of network socket I want to open  

sock.sendto("11,!R1D1F0", (UDP_IP, UDP_PORT))      #Send the command to turn off the light 
sock.sendto("11,!R1D1F1", (UDP_IP, UDP_PORT))      #Send the command to turn on the light

 

 

Capacitive Sense:

Tuning the times, resistance and capacitance of the sensor was the last part of the puzzle. I ended up needing to reduce the resistance (added another 10MΩ resistor in parallel to give 5MΩ) to my circuit as the capacitance was so high, the lag was longer than the pulse time.

 

With that all in place, all I need are some unsuspecting trick or treaters!

 

 

Final Thoughts?

I had an enormous amount of fun building this project, and hope that it will be even more fun come Halloween.

 

I am very pleased with the actual build, how it functions and the modular nature of the project, allowing for additions and modifications for next year. Once again, I feel I have stretched my knowledge and learned from it, which is key for me with anything I undertake.

 

If I were to start the project again or make large improvements, I think I would replace a lot of the internal wiring and internal perf board with a custom PCB. This is not something I have experience in, but would definitely improve the quality of the build.