Introduction: Homemade Security System Using Sensor Fusion
The idea behind this project is to create a cheap and easy to make security sensor that can be used to alert you when someone has crossed it. The original goal was to create something that could notify me when someone walked up the stairs but I also use it as a security sensor for the front door. The provided software in this instructable is compatible with macOS. Slight changes will have to be made for it to work with Windows. For the full source code for any of these scripts, refer to this GitHub repo.
Step 1: Circuit Set Up
Follow the circuit schematic as shown above. When you upload the Arduino sketch to the nano, make sure to disconnect the wires from the RX and TX pins on the nano. It has been found that uploading to the Arduino can lead to errors if these pins are connected to the bluetooth module. Upload the sketch first and then connect those pins to the bluetooth module.
- Arduino Nano - Microcontroller
- HC-SR04 - Ultrasonic Sensor
- HC-05 Module - Bluetooth Module
- OMRON Switch - Button Used to Switch Sensor On/Off
Step 2: Software Set Up: Arduino
- Download Software Serial to your Arduino Library
- Make sure to select the port and board that matches your Arduino
- Download the provided info file and upload the sketch once you make sure that the RX/TX pins on the Arduino are disconnected from the bluetooth module.
Step 3: Software Set Up: Python
To successfully alert you on your laptop, you will need to run a python script. For help downloading python and the needed libraries please refer to this helpful Instructable by TalalKhalil.
The provided readingValuesV2.py script reads in values sent by the bluetooth module, determines if it signifies that someone has crossed the sensor and creates an alert on your laptop. It also creates and stores a folder within that directory with all the measurements it read since the script started with a time stamp.
- Download Python and all dependencies. (I used pip install)
- Make sure to turn on bluetooth on your laptop and connect to a device named HC-06. You should find it listed under the other devices list in the bluetooth part of your system settings. The passcode for the module is '1234'.
- The variable named distance_wall is the one that determines when the sensor goes off. So depending on sensor location, make sure to change this value which is represented in cms to your environment.
- Connect the RX/TX pin on the bluetooth module and now run the readingValuesV2 script. It will ask you for a the recording number so it can properly name the file it generates.
It is likely that you may have to do a lot of debugging so refer to the last section in this Instructable for further help.
Step 4: Likely Debugging Issues
1) avrdude: stk500_getsync(): not in sync: resp=0x0: This often happens with when trying to upload a sketch to an Arduino.
- Ensure that the right COM port and board is chosen
- If you are currently using the 'ATmega328P' try the 'ATmega328P (Old Bootloader)'
- Make sure that the RX/TX pin on the Arduino is disconnected
2) Busy Comport Error
- Ensure that the right COM port is chosen. Since you are trying to upload the sketch to the Arduino, make sure that the python script is not running.
1) [Errno 16] Resource busy: '/dev/tty.HC-06-DevB': This happens when you haven't connected your laptop to the bluetooth module
- To solve this you need to ensure that you have properly connected the HC module to your laptop. You also have to ensure that this module remains connected, it will become disconnected after you are done running the script.
2) ValueError: The bluetooth module is not connected
- This is a manually thrown error if the Serial Port Connection with the bluetooth module is not connected properly.
3) Python Packages Dependencies Error
- I used pip install to download the needed packages for python. Refer to stack overflow for any errors that pop up on that end
4) Errors Due to OS
- I expect that some errors will pop up if the os being used is Windows. Some areas that may be troublesome is the logging of data recording and notification system on your laptop.
5) serial.serialutil.SerialException: device reports readiness to read but returned no data
- This sometimes happens if the power supply is turned off. This occurred to me when I toggled the device off using the switch.
1) Ensure that the switch is properly paced between the line divider on the breadboard so that the connections don't get mixed.
Step 5: Demoing the Completed Device
Please feel free to check out the video to see the device in action using the embedded link or this YouTube link: https://youtu.be/Ab1wKr2ORbM. Overall, this is something that I use regularly now and have found that it does not drain the power supply too quickly or stress out my old laptop in terms of processing power. If you have any issues, feel free to create an issue post on the associated GitHub repo for this project!
Participated in the
Battery Powered Contest