I have been always fascinated by home automation devices and ever wanted to get one of these security home camera, home temperature monitor or even lights and air conditioner.
Even more, I dreamed of remotely control things in my home from outside by using my phone. That takes me to create my own customized home automation project that integrates IoT technology, into only one device... an IoT home automation device!
So, let's get started with the idea...
IdeaThe device is placed near the home door and is always connected to the internet via my wifi router. And you can monitor your home environment and control things by using just an app on your smartphone, called IoT MQTT Panel.
The device has 3 sensors to monitor:
- Door lock status using ultrasonic sensor
- Temperature
- Gas level
And allows you to control 3 things:
Once you are outside home you can monitor your home light and control it from the app by using a relay.
Also, you can monitor gas level inside your home with the gas sensor and once it gets a dangerous level, an email will be sent to you automatically from the device so you can take a quick action upon it and also the alarm buzzer will be turned on and will stay alarming until someone notice it and press it down.
And even take multiple pictures from different angles and they will be sent to your email.
And when you are about to leave the office back to your home then you can cool things by checking the home temperature and turn on the AC with an auto-optimization mode.
This is done by using an IR sensor directed to the AC and the auto-optimization mode will increase the AC temperature set point automatically each 2 minutes for 2 times so that once you get arrived your home is cooled nicely, not frozen!
Once you arrive home and open the door, the ultrasonic sensor will detect your door movement and the device will tell you (with a text-to-speech) to enter your pre-saved fingerprint so that the device knows that you are an authorized person.
What if he wasn't an authorized one? Then the device will wait for 30 seconds and if the fingerprint hasn't been entered and matched, then it will take a photo of that stranger and send it back to the owner's email.
In addition, once you press the speak button on your app, the device will activate the voice-commands and listen to what you want like playing music or turning lights on/off. Here, you can get relaxed reading your favourite book and listening to your favorite music after a heavy working day!
I am going to use Arduino with the IoT shield existed in 1Sheeld. 1Sheeld is basically an Arduino shield that collects 40+ shields into only one shield!
Just a perfect and cheap board that empowers me to use the required shields in this project:
- IoT Shield for making the communication with the CloudMQTT online server.
- FingerPrint Scanner Shield to authorize the home entrance.
- Buzzer Shield to act like an alarm for the high gas level.
- Camera Shield to take photos of inside home.
- Email Shield to get emails of photos taken by the phone's camera and gas alet's emails.
- Music Player Shield for playing music from phone.
- Terminal Shield acts like a serial monitor "for debugging only."
- Text-to-Speech Shield to say what I want. It acts like my own voice assistance ")
- Voice Recognition Shield which is the way I order the device to do what I want orally.
And going to use 2 phones:
- An iPhone to be connected with the 1Sheeld so that Arduino can connect to the internet (and to the IoT online server, indeed) through the IoT shield in the iPhone's 1Sheeld app.
- An Android phone to use it as my personal phone that has the IoT MQTT Panel App. And these of course in addition to the listed components and fabrication materials.
So, I will go with you step by step to build this project from scratch but please be patient since there is quite steps, components and coding here.
Before You Start Building ItI recommend you go for this 1Sheeld getting started tutorial to get familiar with 1Sheeld.
Also, check this simple IoT tutorial with Arduino+1Sheeld to get familiar with the IoT shield of 1Sheeld and how to setup the IoT MQTT Panel App and the cloud MQTT server.
Step 1: Prepare the Materials and Cut the Box FacesFirst, get the cardboard foam material and cut it into the below described dimensions so you get 6 faces of the box.
Don't forget to make the holes for the components like ultrasonic, gas sensor, etc.
Finally, you should get the box faces ready like that:
Note: the size of the 3D parts and the servo motor arm is up to you according to your servo motor size and your iPhone. But in general, you can use any alike plastic/wood pieces around you. Just make it easy for yourself :)
Step 2: Build the BoxNow comes the assembly part where you glue the 5 faces of the box using the glue gun.
And the 6th face which is the box's door you should install it with a tape from its bottom side to act like a door to be able to open and close it freely, like this:
Note: the box door is fixed to its closing position by using 2 small magnets placed on the box door and 2 metal pieces placed on the correct faced closing place.
You better start with plugging the 1Sheeld over the Arduino and install it inside the box.
You should do it without messing things up inside the box by:
1 - Connect the jumper wires to the components: DHT sensor, ultrasonic, servo, LEDs, buttons, etc.
2 - Glue each component to its hole over its place in the box using the glue gun.
3 - Connect the other jumper wires terminal to the Arduino or power.
I have designed a sticker profile to cover the box so that it gets a visual polish. The sticker is divided into 6 faces, indeed where you can download them from here. Or you can use your own customized sticker.
After all, it will look like this:
Then it's time to adjust the device near your home door with a helping 3D printed 4 parts (2 over the box itself and 2 over the wall). You will find the (.gcode) for it in the CAD part of the project so that your can print them directly with the 3S printer.
Finally, connect the 2 relay output wires to the wall light switch.
And tape the IR to be pointed to face your air conditioner.
Before uploading the code to your Arduino mega you should edit this part which contains the Air Conditioner IR remote codes to your own in-home Air Conditioner IR code:
// AC on/off at temp 23
unsigned int power[] = {4712, 2580, 384, 376, 380, 952, 380, 976, 356, 396, 360, 976, 356, 376, 380, 396, 356, 396, 360, 396, 356, 976, 356, 400, 356, 396, 356, 400, 356, 976, 356, 396, 360, 396, 356, 396, 360, 396, 356, 976, 356, 400, 356, 396, 356, 400, 356, 976, 356, 376, 380, 396, 356, 400, 356, 396, 356, 976, 360, 396, 356, 396, 360, 396, 356, 400, 356, 396, 356, 400, 356, 396, 356, 400, 356, 976, 356, 396, 360, 396, 356, 396, 360, 976, 356, 396, 356, 400, 356, 396, 360, 972, 360, 396, 360, 396, 356, 396, 356, 976, 360, 972, 360, 396, 356, 400, 356, 396, 356, 976, 356, 400, 356, 396, 360, 396, 356, 396, 360, 396, 356, 976, 360, 972, 360, 976, 356, 396, 360, 956, 356, 20116, 4676, 6568, 9276, 5012, 384, 396, 356, 396, 360, 396, 356, 400, 356, 396, 360, 396, 356, 396, 356, 400, 356, 396, 360, 396, 356, 396, 360, 396, 356, 976, 356, 976, 360, 396, 356, 396, 360, 396, 356, 396, 360, 396, 356, 396, 360, 396, 356, 400, 356, 976, 356, 396, 356, 400, 356, 396, 360, 396, 356, 396, 360, 396, 356, 400, 356, 396, 356, 396, 360, 396, 356, 400, 356, 396, 356, 400, 356, 396, 360, 396, 356, 396, 356, 400, 356, 396, 360, 396, 356, 400, 356, 396, 356, 396, 360, 396, 360, 396, 356, 396, 356, 400, 356, 396, 356, 400, 356, 396, 360, 396, 356, 396, 360, 396, 356, 396, 360, 396, 356, 396, 360, 396, 356, 396, 360, 976, 356, 976, 356, 976, 356, 380, 360, 20116, 4672};
// AC temp+ from 23 to 24
unsigned int temp24[] = {4716, 2604, 360, 396, 356, 976, 356, 976, 360, 396, 356, 976, 356, 400, 356, 396, 356, 400, 356, 396, 356, 976, 360, 396, 356, 396, 360, 396, 356, 976, 360, 396, 356, 396, 360, 972, 360, 396, 356, 980, 352, 400, 356, 396, 360, 396, 356, 396, 360, 396, 356, 976, 356, 400, 356, 396, 356, 976, 360, 396, 356, 400, 356, 396, 356, 400, 356, 396, 356, 400, 356, 396, 356, 400, 356, 976, 356, 396, 360, 396, 356, 400, 356, 976, 356, 396, 360, 396, 356, 396, 360, 976, 356, 396, 356, 400, 356, 396, 360, 396, 356, 396, 356, 976, 360, 396, 356, 400, 356, 976, 356, 396, 360, 396, 356, 396, 360, 396, 356, 396, 360, 396, 356, 400, 356, 976, 356, 396, 356, 380, 360, 20104, 4684, 6596, 9276, 5012, 356, 396, 360, 396, 356, 396, 360, 396, 356, 400, 356, 396, 356, 400, 356, 400, 356, 396, 356, 396, 356, 400, 356, 396, 360, 976, 356, 976, 356, 396, 360, 396, 356, 396, 360, 396, 356, 396, 360, 396, 356, 400, 356, 396, 356, 976, 356, 400, 356, 396, 356, 400, 356, 396, 360, 396, 356, 400, 356, 396, 356, 400, 356, 396, 356, 400, 356, 396, 356, 400, 356, 396, 356, 400, 356, 396, 356, 400, 356, 396, 356, 400, 356, 400, 356, 396, 356, 400, 352, 400, 356, 400, 356, 396, 356, 400, 356, 396, 356, 400, 356, 396, 356, 400, 356, 400, 352, 400, 356, 400, 352, 400, 356, 400, 356, 396, 356, 400, 352, 400, 356, 980, 352, 980, 352, 980, 356, 380, 356, 20104, 4684};
// AC temp+ from 24 to 25
unsigned int temp25[] = {4716, 2604, 356, 400, 356, 976, 356, 976, 360, 396, 356, 976, 356, 396, 360, 396, 356, 400, 356, 396, 356, 976, 360, 396, 356, 396, 360, 396, 356, 976, 356, 400, 356, 396, 356, 400, 356, 396, 356, 976, 360, 396, 356, 396, 360, 396, 356, 976, 360, 396, 356, 396, 360, 396, 356, 396, 360, 972, 360, 396, 356, 400, 356, 396, 356, 400, 356, 396, 356, 400, 356, 396, 360, 396, 356, 976, 356, 400, 356, 396, 356, 400, 356, 976, 356, 396, 360, 396, 356, 396, 360, 976, 356, 396, 360, 396, 356, 396, 356, 976, 360, 396, 356, 976, 356, 400, 356, 396, 360, 972, 360, 396, 356, 396, 360, 396, 356, 396, 360, 396, 356, 400, 356, 976, 356, 396, 360, 976, 356, 380, 356, 20108, 4684, 6592, 9276, 5012, 356, 396, 360, 396, 360, 396, 356, 396, 360, 396, 356, 396, 360, 396, 356, 396, 360, 396, 356, 400, 356, 396, 356, 396, 360, 976, 356, 976, 356, 396, 360, 396, 356, 396, 360, 396, 356, 400, 356, 396, 356, 400, 356, 396, 360, 976, 356, 396, 356, 396, 360, 396, 356, 400, 356, 396, 360, 396, 356, 396, 360, 396, 356, 396, 360, 396, 356, 396, 360, 396, 356, 396, 360, 396, 356, 400, 356, 396, 356, 400, 356, 396, 356, 400, 356, 396, 356, 400, 356, 396, 360, 396, 356, 396, 360, 396, 356, 396, 360, 396, 356, 396, 360, 396, 356, 396, 360, 396, 360, 396, 356, 396, 356, 400, 356, 396, 356, 400, 356, 396, 360, 972, 360, 976, 356, 976, 356, 380, 356, 20080, 4712};
So, you need to know the IR codes responsible for:
- Turning your Air Conditioner on/off at a temperature of 23.
- Increasing your Air Conditioner temperature from 23 to 24.
- Increasing your Air Conditioner temperature from 24 to 25.
The last 2 codes are required for the Auto-Optimization mode.
For me, this was the most difficult part of the whole code since all IR remote libraries on the internet for Arduino aren't compatible with long range of the codes generated by the Air Conditioner IR remotes since these remotes generates IR codes with much more number of complex bits that popular Arduino IR remote libraries can't recognize.
After a long search and trying combinations of codes I finally got it working! You just need to make these connections between the Arduino and an IR receiver:
Connections:
IR Receiver Arduino
V+ -> +5v
GND -> GND
Signal Out -> Digital Pin 2
Then, upload this code to your Arduino:
/*
Author: AnalysIR
Revision: 1.0
This code is provided to overcome an issue with Arduino IR libraries
It allows you to capture raw timings for signals longer than 255 marks & spaces.
Typical use case is for long Air conditioner signals.
You can use the output to plug back into IRremote, to resend the signal.
This Software was written by AnalysIR.
Usage: Free to use, subject to conditions posted on blog below.
Please credit AnalysIR and provide a link to our website/blog, where possible.
Copyright AnalysIR 2014
Please refer to the blog posting for conditions associated with use.
http://www.analysir.com/blog/2014/03/19/air-conditioners-problems-recording-long-infrared-remote-control-signals-arduino/
Connections:
IR Receiver Arduino
V+ -> +5v
GND -> GND
Signal Out -> Digital Pin 2
(If using a 3V Arduino, you may connect V+ to +3V)
*/
#define LEDPIN 13
//you may increase this value on Arduinos with greater than 2k SRAM
#define maxLen 300
volatile unsigned int irBuffer[maxLen]; //stores timings - volatile because changed by ISR
volatile unsigned int x = 0; //Pointer thru irBuffer - volatile because changed by ISR
void setup() {
Serial.begin(115200); //change BAUD rate as required
attachInterrupt(0, rxIR_Interrupt_Handler, CHANGE);//set up ISR for receiving IR signal
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(F("Press the button on the remote now - once only"));
delay(5000); // pause 5 secs
if (x) { //if a signal is captured
digitalWrite(LEDPIN, HIGH);//visual indicator that signal received
Serial.println();
Serial.print(F("Raw: (")); //dump raw header format - for library
Serial.print((x - 1));
Serial.print(F(") "));
detachInterrupt(0);//stop interrupts & capture until finshed here
for (int i = 1; i < x; i++) { //now dump the times
if (!(i & 0x1)) Serial.print(F("-"));
Serial.print(irBuffer[i] - irBuffer[i - 1]);
Serial.print(F(", "));
}
x = 0;
Serial.println();
Serial.println();
digitalWrite(LEDPIN, LOW);//end of visual indicator, for this time
attachInterrupt(0, rxIR_Interrupt_Handler, CHANGE);//re-enable ISR for receiving IR signal
}
}
void rxIR_Interrupt_Handler() {
if (x > maxLen) return; //ignore if irBuffer is already full
irBuffer[x++] = micros(); //just continually record the time-stamp of signal transitions
}
And open the serial monitor and press the on/off key from the IR remote towards the IR receiver. You will get something like this on the screen:
Copy and paste the code you got in a text file. Code will be something like this:
Raw: (267) 4644, -2604, 384, -416, 312, -1020, 316, -1016, 316, -440, 312, -1020, 312, -440, 312, -444, 312, -440, 312, -444, 312, -1016, 316, -440, 312, -440, 316, -1016, 316, -440, 312, -444, 312, -440, 312, -444, 312, -1016, 316, -1016, 316, -440, 316, -1016, 320, -436, 312, -1016, 316, -440, 316, -1016, 316, -440, 312, -440, 316, -440, 312, -440, 312, -440, 316, -440, 312, -440, 316, -440, 312, -440, 316, -440, 312, -440, 316, -1016, 316, -440, 312, -440, 316, -440, 312, -440, 316, -440, 312, -440, 316, -436, 316, -1016, 316, -440, 316, -436, 316, -440, 316, -436, 316, -440, 316, -1016, 316, -436, 316, -440, 316, -1016, 316, -436, 316, -440, 316, -436, 316, -440, 316, -436, 316, -1016, 316, -440, 312, -1020, 316, -1016, 316, -420, 316, -20132, 4648, -6592, 9272, -5008, 384, -412, 316, -440, 312, -440, 316, -436, 316, -440, 316, -436, 316, -440, 312, -440, 316, -440, 312, -440, 316, -440, 312, -440, 316, -440, 312, -440, 316, -436, 316, -440, 316, -436, 316, -440, 316, -436, 316, -440, 312, -440, 316, -440, 312, -1020, 312, -440, 312, -444, 312, -440, 312, -444, 312, -440, 312, -444, 312, -440, 312, -440, 316, -440, 312, -440, 316, -440, 312, -440, 312, -444, 312, -440, 316, -440, 312, -440, 312, -444, 312, -440, 312, -440, 316, -440, 312, -440, 316, -440, 312, -440, 312, -444, 312, -440, 312, -444, 312, -440, 312, -444, 312, -440, 312, -440, 316, -440, 312, -440, 316, -440, 312, -440, 316, -440, 312, -440, 316, -440, 312, -440, 312, -444, 312, -1016, 316, -424, 312, -20136, 4648,
If you noticed, the IR code for on/off switch has negative numbers. Many of them, actually. Here, you must remove all these (-) signs and copy the whole code with all numbers are positive to your project code.
Going to do all this manually! What's the hill!! Surely not, however, I did it manually to test a new code I have made to take the IR remote code with its negative numbers, removes all negative signs (-) and generates the required clean IR code for you. All automatically! Yeah, here is it:
// ir received array
int irArray[] = {4716, -2604, 360, -396, 356, -976, 356, -976, 360, -396, 356, -976, 356, -400, 356, -396, 356, -400, 356, -396, 356, -976, 360, -396, 356, -396, 360, -396, 356, -976, 360, -396, 356, -396, 360, -972, 360, -396, 356, -980, 352, -400, 356, -396, 360, -396, 356, -396, 360, -396, 356, -976, 356, -400, 356, -396, 356, -976, 360, -396, 356, -400, 356, -396, 356, -400, 356, -396, 356, -400, 356, -396, 356, -400, 356, -976, 356, -396, 360, -396, 356, -400, 356, -976, 356, -396, 360, -396, 356, -396, 360, -976, 356, -396, 356, -400, 356, -396, 360, -396, 356, -396, 356, -976, 360, -396, 356, -400, 356, -976, 356, -396, 360, -396, 356, -396, 360, -396, 356, -396, 360, -396, 356, -400, 356, -976, 356, -396, 356, -380, 360, -20104, 4684, -6596, 9276, -5012, 356, -396, 360, -396, 356, -396, 360, -396, 356, -400, 356, -396, 356, -400, 356, -400, 356, -396, 356, -396, 356, -400, 356, -396, 360, -976, 356, -976, 356, -396, 360, -396, 356, -396, 360, -396, 356, -396, 360, -396, 356, -400, 356, -396, 356, -976, 356, -400, 356, -396, 356, -400, 356, -396, 360, -396, 356, -400, 356, -396, 356, -400, 356, -396, 356, -400, 356, -396, 356, -400, 356, -396, 356, -400, 356, -396, 356, -400, 356, -396, 356, -400, 356, -400, 356, -396, 356, -400, 352, -400, 356, -400, 356, -396, 356, -400, 356, -396, 356, -400, 356, -396, 356, -400, 356, -400, 352, -400, 356, -400, 352, -400, 356, -400, 356, -396, 356, -400, 352, -400, 356, -980, 352, -980, 352, -980, 356, -380, 356, -20104, 4684};
signed int irArraySize= sizeof(irArray) / sizeof(irArray[0]);
int i;
void setup() {
Serial.begin(9600);
delay(2000);
Serial.println("Wait .. I will convert your signed IR array now ...");
delay(1000);
Serial.println("");
/* print the old signed array */
Serial.println("Your original IR array with negative numbers:");
Serial.print("{");
for(i=0; i<irArraySize; i++)
{
Serial.print(irArray[i]);
Serial.print(", ");
}
Serial.print("}");
Serial.println("");
Serial.println("");
/* remove '-' sign from the original array and over right elements */
for(i=0; i<irArraySize; i++)
{
if(irArray[i] < 0 )
{
irArray[i] = irArray[i] * ( (signed int)(-1) );
}
}
/* print the new unsigned array */
Serial.println("Your new all positive numbers IR array:");
Serial.print("{");
for(i=0; i<irArraySize; i++)
{
Serial.print(irArray[i]);
Serial.print(", ");
}
Serial.print("}");
Serial.println("");
Serial.println("");
Serial.println("All finished .. ready to be copied");
}
void loop() {
// put your main code here, to run repeatedly:
}
Just replace the (irArray[]) content with the code you got which contains the negative (-) numbers and upload the code to the Arduino and you will get your new positive numbers IR code ready to be copied to the project code.
And repeat that with the temp (+) button when Air Conditioner is turned on at 23 c and temp (+) button again when Air Conditioner is on at 24 c.
Finally, you will get 3 IR array codes for the 3 positions we mentioned before:
- Turning your Air Conditioner on/off at a temperature of 23.
- Increasing your Air Conditioner temperature from 23 to 24.
- Increasing your Air Conditioner temperature from 24 to 25.
Copy these arrays to replace them with those in the project code.
Step 7: Arduino Code- Connect the Arduino via your PC using Arduino USB cable.
- Switch the 1Sheeld power to operate on 5v (Not the 3.3v):
- 1Sheeld have 2 modes: Uploading mode and Operating mode. You can switch between them using the switch close to the Digital pins and is called “UART SWITCH” on 1Sheeld and “SERIAL SWITCH” on 1Sheeld+.
Firstly, you slide the switch towards the “SWITCH” notation which turns the 1Sheeld board into the Uploading mode to let you upload the Arduino code.
Note: You have to add these attached code files [dht.cpp - dht.h - TimerOne.cpp - TimerOne.h] in the same folder of the Arduino code file as they are libraries I used in the Arduino code.
Secondly, after you finish uploading the code, slide the switch towards the “UART” notation (or “SERIAL” at 1Sheeld+ board) which turns the 1Sheeld board into the Operating mode to communicate with your smartphone 1Sheeld app.
Finally, open the 1Sheeld app and connect it to the 1Sheeld board via Bluetooth.
Step 8: Configuring the AppNow move on to download the IoT MQTT Panel App. You need to configure the app with MQTT server instance credentials you have gotten from the CloudMQTT online server.
I have made it with the help of this IoT tutorial which will show you how to add just the light button widget and use it with the app:
And this IoT Temperature sensor tutorial which will show you how to add a sensor reading widget and use it with the app.
After that, you will be able to add all other widgets easily like AC button, Auto-Optimization button, Speak, Camera Capture button, Camera Servo slider, gas level reading widget, Door Status widget. You should finish it with a full panel like this:
Once finished all the steps, insert the batteries:
Then turn the device on from the left side switch:
And connect your iPhone with the 1Sheeld then press the reset button on the device left side.
Then open the IoT MQTT Panel App and you are ready to go and control and monitor your home anytime, anywhere with just your own smartphone!
Hope you enjoyed it, guys!
If you have any comment or feedback please let me know in the comments below.
Comments