a harbinger of events or things.

Overview

Herald: Intrusion Detection System using IR and ML

Herald - noun; a harbinger of events or things.

Overview

Herald is an intrusion detection system using infrared radiation and anomaly detection using machine learning and Bolt IoT wifi module. The IoT device makes use of IR sensor and cloud technology for alerting the stakeholders of the detected anomaly.

Things used in this project

Hardware Most of the hardware components can be found in the Bolt IoT starter kit and digital components are relatively inexpensive.

Hardware Components

  • Bolt IoT Wifi Module - 1 unit
  • Male-Male jumper wires - 3 units
  • Mini Breadboard - 1 unit
  • FC-51 or TCRT5000 Infrared Radiation Sensor - 1 unit
  • Powerbank capable of providing at least 5V - 1 unit
  • USB cable to power the module - 1 unit
  • Bolt IoT Starter box (for containing) - 1 unit

Software/digital requirements

  • Python
  • Cloud VPS
  • SMTP Credentials
  • Bolt Cloud Pro Account (for better API rate limit, not required for testing)

Story

Introduction

An intrusion detection system monitors an area for malicious activity or privacy violations. These are reported to the person(s) whom it concerns via an alert system. It can protect your home/office by detection intrusion.

Our system utilizes machine learning to adjust the alert parameters and emails the concerned entities via Simple Mail Transfer Protocol.

FC-51 or TCRT5000. Which one to use?

TCRT5000 and FC-51 Both IR sensors are capable to provide valid results for this experiment however, for anomaly detection, the TCRT5000 should work better than FC-51. The reason being that TCRT5000 can provide both analog and digital output depending upon the proximity of the object and the FC-51 sensor can only provide either HIGH or LOW output depending upon the detection and doesn't consider the proximity of the object.

While creating this project, I tried to purchase the TCRT5000 sensor but due to COVID-19 lockdown and restrictions on online shopping, I was unable to purchase it. So, I had to settle with an FC-51 sensor. Ideally, I should have used a TCRT5000.

I have written this and the code with compatibility of both sensors and either can be used without changing the code and connections.

Procedure

Setting up the hardware

Step 1: Connect the sensor to breadboard. This is optional. In case you want to connect the sensor directly to the Bolt IoT Wifi Module, you may do so.

breadboard and sensor

Step 2: Connect the male-male jumper wires to the corresponding pins on the breadboard.

jumper with breadboard and sensor

Step 3: Connect the other end of jumper wires to the Bolt module. Connection should match as:

Sensor to Bolt Module connections:
VCC <-> 5V
GND <-> GND
OUT <-> A0

bolt

Step 4: Power on the bolt module via a power bank or direct connection of at least 5V.

Step 5: Verify connectivity on bolt module and connections. The IR sensor should show an LED for power and another LED may light up in case it detects some object in proximity. You may adjust the sensitivity by adjusting the potentiometer.

Loading the software

The code is written in the Python language and is coded to be suitable with both types of hardware described above. You will need to install Python which can be done easily (just google it if you don’t have it) and then install the Bolt IoT library via pip.

For deployment purpose, you will need a VPS for hosting the script and SMTP credentials for emailing. You may create a VPS via DigitalOcean or AWS and use Gmail credentials for sending emails (you should create a new Gmail account for this instead of using a personal account). However, if you are just trying the project, you may skip these and run on your PC.

Step 1: Log in to your server

Step 2: Assuming you already have python3 installed, run this command to install the Bolt IoT library

$ pip3 install boltiot

Step 3: Clone the git repository containing the code and navigate to it

$ git clone https://github.com/muhammadmuzzammil1998/herald; cd herald

git clone

Configuring the system

After cloning the repository, you have to edit the configuration file config.py as per your own configurations and requirements. The contents of config.py are used in the main code and have description along the line as well.

You might want to adjust the api_limit_margin and api_limit_per_minute as per your bolt account or use the pro account.

$ nano config.py # To edit the configurations
# API and Device configurations #

api_key = ""              #Bolt user API key
device_id = ""            #Bolt device ID
cooldown = 10             #Cooldown after an unsuccessful api call to device in seconds
frame_size = 5            #Frame size for computing z-score
factor = 2                #Factor for computing z-score
api_limit_per_minute = 20 #Ratelimit for the API requests per minute
api_limit_margin = 1      #API calls to leave as margin
interval = 60 / (api_limit_per_minute - api_limit_margin) #Optional edit: Interval for checking status

# Email configurations #

smtp_server = ":587"  #SMTP server with port in format smtp.gmail.com:587
sender_name = "Herald - the intrusion detector" #Sender's name to display
sender_email = ""     #Username for SMTP server
sender_password = ""  #Password for SMTP server
recipients = ""       #Single recipient in string or a list of recipients in array form
  • api_key: You can obtain it from cloud.boltiot.com
  • device_id: Same as cloud.boltiot.com
  • cooldown: Time to pause after an unsuccessful api call to device
  • frame_size: Used to calculate the boundary for data
  • factor: Used for anomaly detection
  • api_limit_per_minute: Ratelimit for the API requests per minute
  • api_limit_margin: API calls to leave for other stuff
  • interval: Automatically calculated as per above two parameters
  • smtp_server: Address of your SMTP server with port. We are using TLS encryption with 587 port. Gmail uses smtp.gmail.com:587.
  • sender_name: Name to display on email alert
  • sender_password: Password for your gmail account
  • recipients: Email addresses of the stakeholders who should be informed. Can be string or list of strings.

Starting Herald

final

Ensure that you have correctly connected the pins as VCC to 5V, GND to GND, and OUT to A0.

Type the following command to start the program. Make sure your Bolt module is connected to the internet and cloud, as indicated by the blue and green LEDs on wifi module and LED on the sensor module.

$ python3 main.python3

execution

As you can see from the above output, an alert is sent when bounds changed. The bounds are calculated using Machine Learning so that minor object detection, such as curtain flowing in front, can be handled without triggering a false alert.

Bounds are calculated using z-score analysis for anomaly detection as:

zscore

Code explanation

z_score

z_score function takes in the dataset, frame size, and the factor to adjust the boundary of the given curve. It returns the range in which the next data point should fall.

sensor_data

sensor_data takes in the pin to read from and returns the value read when successful. In case there is an error, the function also deals with it.

verify_dataset

To ensure that we have sufficient data to generate boundaries for anomaly detection.

Why read analog instead of digital read?

The reason here for opting for analog is that the, as discussed earlier, I wished to build this with an advanced sensor but could not get my hands on it. Therefore, to be compatible with both sensors, I chose to read analog input.

Schematics

schematics

Conclusion

To conclude, we built an intrusion detection system using Bolt IoT which was able to sense the presence when passing through. I installed the device in my home and the device was powered by a power bank. It worked and I received emails when passing through the door.

Owner
Muhammad Muzzammil
I code stuff.
Muhammad Muzzammil
Python wrapper for Interactive Brokers Client Portal Web API

EasyIB: Unofficial Wrapper for Interactive Brokers API EasyIB is an unofficial python wrapper for Interactive Brokers Client Portal Web API. Features

39 Dec 13, 2022
A tool that helps keeping track of your AWS quota utilization

aws-quota-checker A tool that helps keeping track of your AWS quota utilization. It'll determine the limits of your AWS account and compare them to th

Max 63 Dec 14, 2022
A Python Script to automate searching of available vaccination centers in the city and hence booking

Cowin Vaccine Availability Notifier Cowin Vaccine Availability Notifier takes your City or PIN code as an input and automatically notifies you via ema

Jayesh Padhiar 7 Sep 05, 2021
Discord Rich Presence implementation for Plex.

Perplex Perplex is a Discord Rich Presence implementation for Plex. Features Modern and beautiful Rich Presence for both movies and TV shows The Movie

Ethan 52 Dec 19, 2022
A simple Telegram bot that analyses a given word, built with python-telegram-bot

Telegram Word Bot A simple Telegram bot that analyses a given word, built with python-telegram-bot. The bot is fairly useless - unless you often need

Chris N 2 Jul 14, 2022
Quot-a-lecture - Lecture transcript question extraction

Setup virtualenv venv source venv/bin/activate pip install -r requirements.txt

Pratyaksh Sharma 5 Sep 12, 2022
Group Chat Spammer For Discord

Group Chat Spammer For Discord Free and public gc spammer

Dreamy 20 Dec 27, 2022
A simple discord bot named atticus that sends you the timetable of your classes upon request

A simple discord bot named atticus that sends you the timetable of your classes upon request. Soon, it would you ping you before classes too!

Samhitha 3 Oct 13, 2022
AuthGG is a Python library for dealing with Auth.gg apis

AuthGG AuthGG is a Python library for dealing with Auth.gg apis Installation Use the package manager pip to install requests Add the auth.py file in y

ExtremeDev 1 Dec 20, 2021
Leveraged grid-trading bot using CCXT/CCXT Pro library in FTX exchange.

Leveraged-grid-trading-bot The code is designed to perform infinity grid trading strategy in FTX exchange. The basic trader named Gridtrader.py contro

Hao-Liang Wen 25 Oct 07, 2021
Gdrive-python: A wrapping module in python of gdrive

gdrive-python gdrive-python is a wrapping module in python of gdrive made by @pr

Vittorio Pippi 3 Feb 19, 2022
Google Sheets Python API v4

pygsheets - Google Spreadsheets Python API v4 A simple, intuitive library for google sheets which gets your work done. Features: Open, create, delete

Nithin Murali 1.4k Jan 08, 2023
A modern, easy to use, feature-rich, and async ready API wrapper improved and revived from original discord.py.

A Python API wrapper that is improved and revived from the original discord.py

Orion 19 Nov 06, 2021
A script to automatically update bot status at GitHub as well as in Telegram channel.

Support BotStatus ~ A simple & short repository to show your bot's status in your GitHub README.md file as well as in you channel. ⚠️ This repo should

Jainam Oswal 55 Dec 13, 2022
Pydapper - A pure python port of the NuGet library dapper

pydapper A pure python library inspired by the NuGet library dapper. pydapper is

Zach Schumacher 38 Jan 02, 2023
Let your friends know when you are online and offline xD

Twitter Last Seen Activity Let your friends know when you are online and offline Laser-light eyes when online Last seen is mentioned in user bio Also

Kush Choudhary 12 Aug 16, 2021
A bot can play all variants, but standard are abit weak, so if you need strongest you can change fsf instead of stockfish_14_Dev

MAINTAINERS Drdisrespect1 and drrespectable lichess-bot Engine communication code taken from https://github.com/ShailChoksi/lichess-bot by ShailChoksi

RPNS Nimsilu 1 Dec 12, 2021
A Simple Telegram Bot To Download And Upload Files

AquaDLBot ➠ I Can Download And Upload files To Telegram DEMO Copyright (C) 2020-2026 by [ema

Asia Argento 8 Feb 15, 2022
Torrent-Igruha SDK Python

Простой пример использования библиотеки: Устанавливаем библиотеку python -m

LORD_CODE 2 Jun 25, 2022
Posts locally saved videos to the desired subreddit

redditvideoposter posts locally saved videos to the desired subreddit ================================================================= STEPS: pip ins

Kyrus 2 Dec 01, 2021