The Problem Statement
Like many people, I work in a room with a workbench, lights, fans, Air-Conditioning and bench test equipment etc. During work hours I have a habit of taking trips away from the bench for a multitude of reasons which includes
- visits to the little boy’s room,
- taking personal phones calls,
- 15 minutes fresh air breaks after an hour or an hour and a half and even
- little snack breaks.
These away from bench breaks vary in time and have no fixed schedule(well at least not one that I have established) and during this time, every electrical equipment consumes power. The short wastage durations can accumulate to large annual ones and this is the basis for my problem statement.
The solution is much more than the simple Motion detector because we add a connectivity as well as programability to the design.
The system is composed of 4 major components.
A Raspberry Pi 2 is used to run OpenHAB Software that provides the GUI as well as other features. An MFRC522 board is used to scan RFID tags and a relay board is used to interface with electrical appliances. The Analog Coprocessor reads sensors and stores the values in its internal memory. The raspberry pi 2 communicates with the PSOC kits over I2C and retrieves this data. A python script is used to parse the sensor values and then passes them on to an MQTT broker at iot.ecliplse.org . This architecture is chosen to facilitate future customisation where the PSOC may talk to an MSP430(Code provided) and send the data either via USART or other means.
The python script also enables reading of the RFID tag and listens to specific MQTT topics for commands. These commands are used to toggle the relays which in turn controls appliances. The rules engine, GUI and data logging is provided by OpenHAB which is a free home automation software solution. It runs on the Raspberry Pi 2 as well but can be a remote installation as well for IoT like applications.
All the code as well as Design Files for the 3D printed enclosure are included with this instructable. For beginners, the instructions are enough to compile their own system and for the advanced people reading this, the avenues of modification await.
The video is a very brief look at the design and working of the project.
For this project you will need the following items:
Step 1: Setup a Raspberry Pi 2.
Connect the network cable, a display and keyboard and power on the Pi. Once the GUI boots up, click the Terminal icon shown in the image and type the following commands.
sudo apt-get update && sudo apt-get upgrade
This will update the OS and make sure everything is running the latest version.
Next we need a Raspberry Pi (2) where we download the rest of the files. Follow the instruction at
Install the dependencies using
sudo apt-get update && sudo apt-get upgrade && sudo apt-get install sudo apt-get install python-smbus
Now the Pi is almost ready. Next we prepare the PSOC, RFID and Relay Board.
Step 2: Prepare and Connect the PSOC and RFID Boards and Connect the Relays
In this step, we first desolder the headers on the PSOC Board. This is not necessary and you can use jumper wires instead but I feel better with short soldered leads.
Next cut the jumper wires so that their length is just enough to go from the PSOC board to the RPI. Strip them at one end and solder them to the PSOC Board as shown.
If you have removed the jumpers for the power selection then you need to make wire jumps as shown as well.
For the Relay board, connect the Relay IN-Pins to GPIOS 11, 12, 13 and 15 on the Raspberry Pi 2 Connector. You may change these in the coprocessor.py code file if required.
The last hardware is the Mifare RFID which should be connected as shown in https://github.com/mxgxw/MFRC522-python .
Again cut the jumpers and connect for more reliable connections.
Next we move to the software.
Step 3: Download My Code
Type in the following command
git clone https://github.com/inderpreet/Project-WhileYouWereOut.git
This should create a folder and download all the necessary and unnecessary code. We don't need the PSOC files but they get downloaded anyway.
Install the dependencies using
sudo apt-get update&& sudo apt-get upgrade&& sudo apt-get install sudo apt-get install python-smbus
Next run the setup script from the SPI folder using
sudo python setup.py install
Finally, run the software using
sudo python coprocessor.py
If everything is done right it should start the service. If you get I2C errors, check the connections for loose wires. They are the most common culprit
Step 4: Setup the Cypress Software
Install PSOC Creator from http://www.cypress.com/products/psoc-creator-inte... and compile and program my PSOC design to the kit. I have added a tutorial video for getting comfortable with the PSOC Creator IDE
The code for the PSOC project can be downloaded from https://github.com/inderpreet/Project-WhileYouWereOut/archive/master.zip
Next open the project in PSOC Creator and build and debug with the Analog CoProcessor Kit. I made a tutorial to help get started.
Step 5: Setting Up OpenHAB
Next, Install and setup openHAB as per instructions
Check out http://docs.openhab.org/installation/ for updated instructions.
Copy the Sitemap, Items file and rules file that you downloaded from my github.com page
Phew! that a lot of work but its worth it.
Finally start OpenHAB and it should work.
Step 6: Enclosure Time and Finish Test
Download the STL Files for the enclosure from https://pinshape.com/items/32437-3d-printed-psoc-w...
The components can be fit into the enclosure and once you run both the python script and OpenHAB, you should be able to see a website at localhost:8080 on the Pi. Test things out. The rules I have written are pretty self-explanatory but basically you should be able to see events like PIR sense, RFID Swipes etc.
The project is quite complex however in addition to being a learning experience, you get a pretty flexible office management solution.
Participated in the
Microcontroller Contest 2017