Some months ago, I made a post on Home Automation system and Security System. It have been a while and the project is almost 98% complete but that won’t stop me from posting the update.
- 4×4 keypad Arduino and Save passkey to EEPROM
- Lithium Battery level indicator with Arduino Uno and LCD
- Control Devices with Arduino and Radio Frequency (RF) communication
I early developed an Android mobile app based on Ionic Framework but didn’t like the experience so I have to settle with with where my strength lies but I will still try another version with Flutter. The materials/components are listed below:
- Raspberry Pi 3
- Servo Motors (x3)
- Bunch of LEDs
- materials to build body
- Intellij IDE or Android Studio
- Relay module
- 5volts DC Fan
- PIR sensor (x3)
- Straws for security light
Please, I don’t have access to a 3D printer or any knowledge of Architecture so I have to cut and join everything. I looks raw.
Android Application Based on JAVA
The Home automation system (HAS) can be remotely controlled from an android app, I think I have said that earlier. The app just consist of bunch of textviews to display sensor data from HAS, a webview to display camera feed, some buttons to move the Camera mounted on a Servo motor, switch buttons to control the DC fan and doors (Mounted on Servo motors). As usual, Pubub Data streaming network was fully utilized here. I had to use the pubnub Android Java SDK.
I made a post earlier on camera/video feed streaming remotely using webview so that should cover the part of webview:
I also made a post earlier on how to control servo motors using pubnub and android app but here is a snippet on how to implement that:
In order to avoid ANR (Application not responding), all pubnub subscription and publishing were done from a separate thread:
when the application starts up, it will publish to HAS requesting for Sensors’ data and has the ability to automatically reconnect to internet:
The final code and files for the Android app is available [DOWNLOAD CODE].
Since it is a python script, I had to find a way to keep it running. I used while loop only and the experience was bitter so I had to run the loop in a different process. I can say that the performance was alot more better:
To operate the lights, the values coming from the Android App Seekbar was mapped into 0 – 100 for GPIO Software PWM with numpy:
I had to use RPIO library to control the servos, all the other ones I tried didn’t give me what I wanted. My servos starts making noise when a pulse signal of 500us or 2400us is sent to it so I had to track its position to avoid getting there. To track the position of the Servo, I had to come up with a trick which I will share here:
To detect motion in the rooms, I used three PIR sensors in different rooms. On detecting motion, if internet connection is active and it is not on security mode, the camera will just move to that position and blink light in that room but if internet connection is not active or the system is on security mode; the alarm will go off coupled with other things. The user is also alerted via the android app on both occasions (via alarm ringtone):
The full code for the Python script is avaliable on my Github Page.
I will try to improve on this post and project so feel free to drop your comments and observations and don’t forget to follow our Social media channels for tutorials like this.