F12: All Your Base are Belong to You

From Embedded Systems Learning Academy
Jump to: navigation, search

All Your Base are Belong to You

CmpE146 F12 AYB Raspberry-Pi.jpg

Abstract

The Automated Security system will monitor a home, and trip an if an intruder passes by the sensor by wirelessly sending a signal to the central unit. The system will incorporate several hardware devices, managed by a Web based GUI for easy activation and deactivation of both the alarm and the system

Objects & Introduction

This system will automate your security and home functions for a higher quality of life

Security Thermal Sensor

  • Security Thermal Sensor will capture movement and heat from intruders
  • Security Thermal Sensor will send an alarm signal to the server after the thermal value reaches a certain threshold
  • Alarm Signal from the Security Thermal Sensor will be sent to the server through Wi-Fi communication

Raspberry Pi or Receiving Server (server)

  • Server will receive data from the Security Thermal Sensor
  • Server will receive alarm signal and be set to an alarm state until it is deactivated

Team Members & Responsibilities

  • Christopher Cheng
    • Wi-Fi Hardware and Software Design
  • Tyler Gray
    • Raspberry Pi (server) Research and Web UI
  • Prateek Grover
    • Thermal Motion Sensor Hardware and Software Design

Schedule

Week Number Scheduled Items Actual

1

  • Identify Team
  • Identify Hardware
  • Acquire Hardware
  • Design Security Sensor Wire Diagram
  • Done
  • Done
  • Done
  • Done

2

  • Wire up Security Sensor to the LPC MicroController and read sensor data
  • Have Raspberry Pi Wi-Fi Connectivity
  • Set up communication from MicroController to Hercules using Wi-Fi Module
  • Done
  • Done
  • Done

3

  • Connect Server to Security Sensor Slave Module
  • Create Security Sensor Alarm Protocol
  • Establish Communication Between Raspberry Pi and Microcontroller through Wi-Fi
  • Done
  • Done
  • Done

4

  • Create Basic UI
  • Done

5

  • Integrate UI with the Server
  • Improve UI Functionality
  • Done
  • Done
Week Number Scheduled Items Actual

Parts List and Cost

Item Number Items Cost

1

  • Raspberry Pi

$86.54

2

  • 3x RN-XV WiFly Module - Wire Antenna
  • WRL-10822
  • Total = $104.85
  • Each = $34.95

3

  • Infrared Thermometer - MLX90614
  • SEN-09570

$19.95

4

  • EdiMax EW-781UN

$9.99

5

  • LPC2148 Microcontroller

$60

Item Number Items Cost

Raspberry Pi

Setting up the Raspberry Pi

Setting Up the OS
  1. Download latest Raspbian Distribution and Win32DiskImager from RaspberryPi.org[1]
  2. Use the Disk Imager to create a bootable SD card of the Distribution[2]

Operating System

Once the OS has been installed onto an SD card with the use of the Disk Imager from a PC, the SD card can go straight into the Raspberry Pi. The first time the Raspberry Pi has been started, it must be plugged into a ethernet cord that has internet access in order to download any necessary files that has not been installed by the image file.

    Raspbian "Wheezy" from RaspberryPi.org
  • Debian Linux variant
  • Made Specifically for the Raspberry Pi

Wireless Connectivity

The Raspberry Pi does not have Wi-Fi Capabilities built in, so we used an Edimax EW 71UN nano adapter to give it that functionality. This adapter was chosen because it has the following qualities:

  • IEEE 802.11 b/g/n capabilities
  • nano adapter, so it won't stick out
  • plug and play ability for Raspbian Wheezy Linux distribution
  • cheap(cost $10 at time of purchase)

Configure Networking

In order for the Server to be able to connect with the sensor devices

  • Created a shell script that runs on boot that will sets the ip and essid to an existing network

LAMP Server

    Linux, Apach, MySQL, PHP
  • Makes Raspberry Pi a Web Server
  • Hosts WebUI
Setting up the LAMP Server

With the Raspberry Pi OS set up, a few command line instructions were executed on the Pi to set it up as a Web Server. the following steps were taken from Penguin Tutor[3](an internet connection is necessary to install the LAMP elements):

  1. Update Repositories: sudo apt-get update
  2. Install Apache: sudo apt-get install apache2
  3. Install MySQL(needs password setup as part of the process): sudo apt-get install mysql-server
  4. Install PHP: sudo apt-get install php5
    sudo apt-get install php5-mysql

WEB UI

    Gives user control over Security System
  • Uses Twitter Bootstrap framework
  • Allows User to Activate and Deactivate the Security System
  • Uses Bootswatch to make it more visually appealing

SSH Tutorial

You can use an SSH from a PC to remotely access the Raspberry Pi to install packages, firmware upgrades, or applications.

  • Open up the terminal on the Raspberry Pi
  • Type in ifconfig
  • Enter the ip address into the putty terminal then click on open
  • The default login is: pi
  • The default password is: raspberry
  • Once logged in, use any Linux terminal command to remotely access the RPi

Design and Implementation

Hardware Design

CmpE146 F12 AYB TMSensorHW Diagram.png
Figure 1: Hardware design for I2C Ir Thermal Motion Sensor and UART Wifly


CmpE146 F12 AYB PIRThermalMotionSensor.jpeg
Figure 2: Implementation of Sensor/Wifly Design


CmpE146 F12 AYB RaspberryPiHW.jpg
Figure 3: Raspberry Pi Hardware

Hardware Implementation

The hardware implementation for the project required the use of I2C bus for establishing communication between the temperature sensor and the micro controller. Along with that, wifly modules that would relay the information to the server were interfaced with the LPC board using Uart communication protocol.

Thermal Motion Sensor

The sensor chosen to measure temperature readings was Melexis MLX90614 IR Temperature sensor[4]. This sensor required an input voltage of 3.3 V which is achieved by pulling the 3.3V output from the LPc2148 microcontrollers. In addition to that a decoupling capacitor with a value of 0.1 uF was interfaced between Vss and GND. Figure 1 shows the complete hardware circuit for the sensor.

I2C communication

The pins used for realizing this communication were Pin 0.2 for SCL and P 0.3 for SDA, which require a 4.7KOhm pull up resistor in order for the communication between SDA and SCL pins to function properly.

Wifly Interface

Wifly was interfaced over Uart line requiring two pins:Pin 0.8 TX for transmission and Pin 0.9 RX to receive data. A driver was Uart was already on hand(Uart 0) but it had to be modified to get Uart 1 since Uart 0 was already used by USB port.

Software Design

The Software Design consisted of:
1. Raspberry Pi server generates requests using a WiFi microUSB adapter over the network.
2. The Web Server on the RPi will transmit the CMD Request to the Wi-Fly device with the corresponding IP Address.
3. Request is received by the LPC microprocessor which then controls sensor depending on the command received.
4. The GUI then stores the data given by sensor module.

Figure 4. RPi and Trip Sensor Communication

Software Implementation

Security Trip Function

If the Sensor device is active, the security sensor will allow the data it receives from the MLX90614 Infrared Thermometer to activate the alarm.

Figure 5. Security Function Flowchart

Command Parsing

Upon receiving the request, the command parser decodes the incoming command which is received on the Uart RX line. The commands received manipulates security and alarm as shown in the figure below. Status of the system can send back to the server on the Uart TX line.

Figure 6. Command Parser Decoding

1. If the received byte is 0x61 or character "a", the system is armed and security is enabled.
2. If the received byte is 0x62 or character "b", the system is disarmed and security is disabled.
3. If the received byte is 0x63 or character "c", this means the sensor has crossed the threshold value and alarm gets enabled.
4. If the received byte is 0x64 or character "d", alarm gets disabled. It is used when the user wants to put the system out of alarm state.
5. Command "e" grabs the current alarm state status and send it to server: 1 for ON state , and 0 for OFF state.
6. Byte "f", send the current sensor value to the server.

CParse(Command, enable, alarm)
{
If (Command=0x61) // a
  Enable Security
Else If (Command=0x62) // b
  Clear Alarm bit
  Disable Alarm
  Disable Security
Else If (Command=0x63) // c
  Set Alarm bit
  Enable Alarm
Else If (Command=0x64) // d
  Clear Alarm bit
  Disable Alarm
Else if (Command=0x65)//e
  If Alarm is set
     Send 1
  Else 
     Send 0
Else if (Command=0x66)//f
  data = I2cRead
  Send data to server

}


Testing and Technical Challenges

Testing

All the testing of the All Your Base are Belong to You Home automation and security system will be described in this section.

Testing Data of MLX90614 Thermal Sensor

First we must determine that we are gathering all 3 bytes gathered from the I2C read function, and ensure that it can be usable data for a security system. Then determine the distance of the Thermal sensor for the possible use as a motion sensor.

  • The change in byte value by waving a hand over the sensor will confirm the functionality of the sensor
Figure 7: Command Parser Test

Raspberry Pi Communication Test

For the Raspberry Pi, we will use a Linux OS and download a telnet software that is usable by the terminal program.

  • First set up a Ad-hoc connection between the Raspberry Pi and the Motion Sensor Module
  • Use telnet on a linux terminal to directly connect to the motion sensor module's IP and port for a direct communication
  • Using hercules and the linux terminal, type in messages and hit enter on either hercules or the linux terminal to send a message
    • Hercules should send a message to the Linux Terminal
    • The Linux Terminal should send a message to the Hercules terminal
Testing the Slave Command Parser Function

The slave will be reading all data being transmitted from the website user interface. Once the data is received, the parser function will compare the hex and set global variables or send data depending on the command it has received.

Figure 8. Command Parser Test

User Interface Communication Test

With the use of a User interface to control the Motion Sensor, we will be using socket programming embedded in a website. The website will act as a user interface to enable to disable the device.

  • Enable Button is pressed
    • The sensor will be armed
      • When the sensor is armed, the sensor can go into an alarmed state if there is motion
  • Disable Button is pressed
    • The sensor will be disabled
      • Nothing will happen, even is there is motion
  • Panic Button is pressed
    • When the sensor is enabled, the sensor will be put into an alarm state and turn on an LED
    • When the sensor is disabled, nothing will happen
CmpE146 F12 AYB Website UI.png
Figure 9: Website User Interface

Technical Challenges

In this section, we will describe all the technical challenges that we ran into while building and testing this project.

Infrared Thermometer MLX90614

The sensor would not output data therefore the testing of the network connections between the motion sensor module and the raspberry pi could not be tested.

  • Could not continue the utilization of the design and could not test and verify the usability of the MLX90614 Thermal Sensor as a motion sensor.
Determine the Problem

The wrong voltage was being passed into the MLX90614 was determined with the use of a multimeter.

  • Requires around 3.3V but was getting voltage under 1V
  • While minimum pressure was applied to the GND and V_out pins on the LPC2148 microcontroller, the correct voltage was being sent into the MLX90614.
    • We have determined that the problem was with the LPC2148, the pins were not correctly soldered
Solving the Problem

Once we have determined the problem came from the LPC2148, we decided to re-solder a GND pin and a Voltage Out Pin to ensure that we can capture the full 3.3 Voltage going in and out of the MLX90614 system.

UI Communication Problems

The Javascript functions we created that sent an AJAX request that would trigger communication to the sensor module caused all of the Javascript functions to fail.

Determine the Problem

There was a mismatch in variable names in the AJAX request, and the PHP request handler. This caused the request to be called, but not finish execution.

Solving the Problem

By commenting out pieces of the javascript functions, and the PHP handler, adding them little by little, we were able to debug and correct the problem.

Conclusion

After completing this project, we have learned about the various issues that can come up when completing a Wi-Fi Project. Things such as hardware failures, occurred with our sensor being faulty at first, as well as it's proclivity towards reading inconsistency over a long period of time. We also ran into software errors with our UI, most of which were fixed through rigorous debugging.

More importantly, we have learned how expansive the capabilities a micro controller has, with just a few added hardware and software components. Furthermore, we learned that there is a lot of information on a wide range of subjects related to embedded systems out on the internet, if you know the right google search terms.


Project Video

[Thermal Motion Sensor Demo]

  • Utilizes Raspberry Pi as Web Server
  • Thermal Motion Trip Sensor
  • Uses Laptop to access Web Server on RPi

[Thermal Motion Sensor + MP3 Alarm Demo]

  • Uses WAMP localhost server on a laptop
  • Thermal Motion Trip Sensor
  • Mp3 Alarm Device
  • Bump Speaker

[Thermal Motion Sensor + MP3 Alarm First Person View Demo]

  • Uses WAMP localhost server on a laptop
  • Thermal Motion Trip Sensor
  • Mp3 Alarm Device
  • Bump Speaker

Project Source Code

Project source code is available at SourceForge

  • All code are zipped up in '.rar' files under the Files Tab

References

Acknowledgement

  • Dr. Haluk Özemek
  • Preet Kang

References Used

[1] http://www.raspberrypi.org/downloads
[2] http://www.softpedia.com/get/CD-DVD-Tools/Data-CD-DVD-Burning/Win32-Disk-Imager.shtml
[3] http://www.penguintutor.com/linux/raspberrypi-webserver
[4] http://www.melexis.com/Infrared-Thermometer-Sensors/Infrared-Thermometer-Sensors/MLX90614-615.aspx

Appendix

You can list the references you used.