Office Monitoring and Control With PSOC and RPi



Introduction: Office Monitoring and Control With PSOC and RPi

About: I design things, I make them, I reinvent them and teach them. #DIY, #research, #IoT, #embedded, #RaspberryPi, #Arduino, #EEE

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 . 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:

  1. A Raspberry Pi 2 - Digikey
  2. A Cypress Analog Co-Processor Kit - Digikey
  3. A Mifare RFID Card - Ebay
  4. A 4 Relay Board
  5. Some jumper wires
  6. Access to a 3D printer or CNC Machine (Optional)
  7. Soldering Iron, solder and basic soldering skills - Parents Supervision for minors

Step 1: Setup a Raspberry Pi 2.

You may choose to follow the official Instructions or buy a NOOBS card from digikey

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

and then

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 code file if required.

The last hardware is the Mifare RFID which should be connected as shown in .

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

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 install

Finally, run the software using

sudo python

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 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

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 for updated instructions.

Copy the Sitemap, Items file and rules file that you downloaded from my 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

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.

Microcontroller Contest 2017

Participated in the
Microcontroller Contest 2017

Be the First to Share


    • Baking Contest

      Baking Contest
    • Make it Glow Contest

      Make it Glow Contest
    • Block Code Contest

      Block Code Contest