IoTPythonRaspberry PiArduinoFlaskC++
SmartHome System
A remote server handling home and user client requests with a front-end UI to interact with IoT features, plus an automatic garage door mechanism that identifies vehicle proximity.
System Features
01.Flask Server and Browser client
The UI for the project is a dashboard using plain JavaScript and plain custom CSS for performance and served by a Flask server. The server was hosted online to allow remote connections (and not only within the LAN) by using a VPS and an Nginx reverse proxy server to deliver HTTPS encrypted connections and redirect connections to the upstream Flask server. The webserver offered an authentication system with login enabled to first authenticate any user before being able to toggle the lights in the SmartHome scale model. In addition, to handle the toggle request, the Flask server runs in combination with a SQL database using the SQLAlchemy toolkit to asynchronously save the user request and serve it to the smart home client once it is connected to the server and ready to execute the request.
02.The smart home client and Arduino vehicle
Most of the research outside the class material was done to make possible the use of the Raspberry Pi resources and allocate the required processing for the Raspbian OS. This includes handling real-time input from peripherals such as sensor reads of an IR sensor and two ultrasonic sensors, managing the client connection to the Flask Server in charge of getting requests stored in the database asynchronously, and toggling the lights accordingly. In addition, the main process takes care of fully automating the garage door by calculating the data from the sensors, identifying and authenticating the presence of the "vehicle", and making decisions to activate the stepper motors controlling the actual 3D printed door mechanism. There are also other peripherals such as two push buttons acting as a security system for the steppers, implemented to ensure the stability and integrity of the system, in addition to software like 'debouncing' to deal with issues that come with mechanical hardware such as push buttons bouncing signals.
In the "Vehicle" side of things, there is an Arduino nano wired up on a mini breadboard connecting the IR emitter. The main Arduino program, in basic terms, turns the IR LED on and off in a specific frequency and patterns of time for the IR receiver in the SmartHome. More in detail, the protocol was inspired by the NEC Infrared Transmission Protocol.
03.The IR listener
To help with the peripheral input of this sensor, there is an IR Python module that counts with a function `getIRData(<ir_pin>)` which essentially does all the reading, and ensures that it meets criteria by detecting: start of the protocol, burst patterns for 0s and 1s, closing for the protocol, and only listening on a specific frequency. The function runs indefinitely and consistently while the main process is up in a dedicated process. If no errors are detected in the protocol while the process is running, it then returns a nicely composed and finished byte which is then made available to the main process. This, along with data collected from the Ultrasonic sensors also running in a different process, collects information and takes a decision on whether to open or close the garage door.
04.The Garage door
As mentioned previously, the program for the Ultrasonic sensors runs in a separate process within the main program. One of its main functions is sending the right sequences to the stepper motor in order to open and close the door mechanism using the byte the IR receives and matching the byte with the secret or reserved byte defining a "Vehicle", allowing the system to differentiate another big object from a car. Initially, there was an issue found with the stepper motors, since it used to run the steppers with an estimate for 'x' time at 'y' speed, or simply 'x' steps to transition from a state of the door being closed to open and vice versa. But due to the inaccuracies that come as a result of working with 3D printed pieces such as friction, gears skipping, and just the physics of the mechanisms, the system would accumulate errors over time, causing the stepper motors to get stuck while trying to open/close the garage door beyond its limits, creating heat and excessive power consumption. To solve this issue, another feature of this process is to handle the pulse and debouncing of two push buttons located at both ends of the gate, which are pushed once the gate is either fully opened or closed as security mechanisms.
Technical Details
Project Context:
▹This project was a final assignment for my System Fundamentals core class as an undergraduate for Fall 2019.
▹All the students were faced with the challenge of creating a project that implemented most if not all the concepts learned throughout the semester.
▹The core idea for the project not only covered all chapters during the class but also was an opportunity to dig deeper and be curious, eventually making it possible to combine different technologies such as IoT, mechatronics, automation, wireless protocol design, hardware programming, and networking in a single objective to innovate homes.
Implementation Challenges:
▹In order to overcome some initial challenges such as the amount of tasks done by the Raspberry Pi simultaneously combined with the Infrared (IR) sensor and the use of multiple ultrasonic sensors, additional research than required for the course was needed to assemble all different features in a working prototype.
▹Some of the concepts were outside the scope of the class but made the project development a very hands-on and creative opportunity.
▹I became familiar with concepts such as: multi-thread and multi-core in Python using Raspberry, server architecture and client authentication, stepper motors and stepper motor programming, infrared light-emitting diodes (IR LED), IR protocols such as Infrared Transmission Protocol, and Arduino programming.
Materials:
▹Raspberry Pi & Arduino nano
▹SD card with Raspbian operating system
▹Breadboard, Pi ‘Wedge’ adapter & Ribbon cable
▹Power supplies for the Pi and monitor
▹4 LEDs, Two Resistors (220 ohm), Breadboard M-M wires
▹Customized 3D printed parts (Linear Actuator)
▹IR transmitter and Receiver modules
▹2 Ultrasonic Sensors
▹One stepper motor 28BYJ-48 and ULN2003 Driver