Skip to content

RPi-based IoT-project for a course on Ambient Intelligence

Notifications You must be signed in to change notification settings

tildeeine/home_safety_iot

Repository files navigation

Home Security Monitoring

The purpose of this project is to design a prototype of an ambient system that will allow at-risk individuals to live independently and safely at home for longer. This is done by integrating software and hardware to monitor home appliances that could be a possible danger if left unsupervised. For this prototype we have implemented monitoring of a stove and a door. The system comes with a webpage that is easy to read and use.

General Information

Our project entails two components focusing on equipment monitoring. The first component is a oven monitoring system. A heat source is used to surveill the oven. If the oven has been on for an extended period a warning will display on a webpage. If the warning is not acted upon, the system will activate a kill switch to turn of the oven. The implemented kill switch for this project is only for demonstrational purposes. It consist of a motor that drives a fan that will blow out the light of a candle (representing the stove).

The second component is a door monitoring system. Its purpose will be to alert the user if the front door remains open for an extended period. Real-time updates on the status of the door will be displayed on the web-page. To monitor the door, it is used an electric circuit that is closed whenever the door is closed, so that one can detect if there is any current in the circuit or not.

Built With

Hardware

  • Raspberry Pi 4 Model B - 1 unit - Development board for reading sensors and sending this information to our dashboard.

  • Raspberry Pi zero 2W - 1 unit - Development board for reading "door input", illustrated through an open/close circuit, and sending this information to our dashboard.

  • Arduino starter kit - Includes a range of the components we used for development. More specifically, we used the following components from the starter kit:

    • Arduino uno
    • Battery 9V
    • Breadboards
    • Buzzer
    • Capacitor
    • Diode
    • Jumper wires
    • Motor
    • Temperature sensor
    • Transistor
    • USB cable
  • Nicla Vision - 1 unit - Used for visual monitoring of the stovetop

  • Assorted cables:

    • 2 RPi power cables
    • 1 Arduino USB power connector
    • 1 MicroUSB to USB for Nicla Vision

Software

  • Raspberry Pi OS - Operating system
  • Python - Programming language for RPi
  • MicroPython - Programming language for Nicla Vision
  • Reference - Programming language for Arduino
  • Flask - Web framework, used for building API
  • React - Web framwork, used for building frontend
  • Tailwindcss - CSS framework for simplifying design of frontend

Getting Started

These instructions will get you a copy of the project up and running on for testing purposes.

  1. Set up the physical system according to the circuit drawings. RPi model 4 should be connected to the arduino via USB. While RPi model 2 has the door circuit. Both RPis should be connected to a power source. Connect both RPis to your mobile network.

Circuit

Circuit

Camera setup: a. Connect the camera to your computer with a USB cable. A folder will then appear which contains a file called "main.py". Copy the content from that file into OpenMV. Fill in the fields for SSID and KEY with you mobile network name and password. Save the file, and then click play. b. Now wait for the camera to connect to your network (you will see the camera blinking red while looking for your network). When it's connected it will tell so in the terminal, in addition to stop blinking. c. Navigate via "tools" to find the option that says "Save the open script to OpenMN Cam (as main.py)", as shown below. Wait for the red light to stop.

connecting camera

d. Disconnect(symbol below) and eject the device before you physically remove it. The camera should now have the file installed and can be connected to RPi 4 via USB. connect icon

  1. Clone the repository from github to both Raspberry Pi's.
  2. Install required packages (visible under "Software Prerequisites")
  3. Identify IP addresses for both RPis and the camera: nmap -sn xxx.xxx.xxx.0/24 (xxx is the network ip mask)
  4. Identify your mobile network name and password. The IP addresses and mobile network information should be added to the file called "/dashboard/srs/network_info.json" in the following format:
    {
        "SSID": "",
        "password": "",
        "OvenRPiIP": "",
        "DoorRPiIP": "",
        "CameraIP": ""
    }

Starting the system when all installments has been done

Navigate to the folder where you have cloned the github repository.

Connect to both RPis by writing the following in two different terminals: ssh g14@<IP address of respective RPi>

Enter the password: g14

In RPi 4 navigate to /rpi-oven/rpi and create and activate a virtual environment:

python -m venv rPi4env
source rPi4env/bin/activate
pip intall flask flask_cors pyserial
source <name of envirnoment>/bin/activate

Run the file for the oven monitoring: python app.py In RPi 2 run the file for the door monitoring: python door.py In a new terminal write: npm start in order to start sending images from the camera over the network.

Software Prerequisites

  • OpenMV for programming nicla vision

  • Arduino IDE for programming arduino

  • Some IDE on your computer to program RPis

  • Arduino-cli

  • Libraries and dependencies

    • flask
    • flask_corse
    • gpiozero
    • network
    • sensor
    • serial
    • signal
    • socket
    • threading
    • time
  • Node package manager

npm install react
npm install --save @fortawesome/free-solid-svg-icons
npm install --save @fortawesome/react-fontawesome

Installation

Arduino code

Installing arduino-cli is needed to run the arduino code. Navigate to the folder /arduino. Then do the following commands:

curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
mv bin/arduino-cli .
chmod a+x arduino-cli
sudo ./arduino-cli core install arduino:avr
sudo ./arduino-cli core search
sudo ./arduino-cli compile --fqbn arduino:avr:uno start_buzzer/
sudo ./arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:uno start_buzzer/

Each time you make changes to the .ino file a compile and upload is necessary. This must be done inside the folder /arduino.

If you have issues with this you could try to list the board to check if its name has changed from ttyACM0 to something else, as this happens from time to time: sudo ./arduino-cli board list

For further information about the arduino-cli commands see: https://www.caronteconsulting.com/en/news/how-to/raspberry-arduino-cli/

Additional Information

Authors

Francisca Silva

Tilde Eine

Tuva Tholo