This shows you the differences between two versions of the page.
iothings:proiecte:2022:smart_home_system_with_alexa_app [2023/01/20 00:01] catalina.sirbu [Software information] |
iothings:proiecte:2022:smart_home_system_with_alexa_app [2023/01/20 04:17] (current) catalina.sirbu [Hardware Description] |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Smart Home System with Alexa App ====== | ====== Smart Home System with Alexa App ====== | ||
- | Author: Catalina Sirbu \\ | + | Author: Catalina Sirbu ACES 2023\\ |
- | Master: ACES \\ | + | |
[[https://alexa-firebase-945fb.firebaseapp.com/|Web application]] \\ | [[https://alexa-firebase-945fb.firebaseapp.com/|Web application]] \\ | ||
- | Source code on Github: \\ | + | [[https://github.com/dragosmacovei/alexa-esp32-wroom32|Source code on Github]]\\ |
[[https://youtu.be/6lvnHSm-Qok|Demo video]] \\ | [[https://youtu.be/6lvnHSm-Qok|Demo video]] \\ | ||
[[https://www.canva.com/design/DAFYDyiL1wc/etq0lGd37NICMMhhaSqxyg/view?utm_content=DAFYDyiL1wc&utm_campaign=designshare&utm_medium=link2&utm_source=sharebutton|Presentation Link]] | [[https://www.canva.com/design/DAFYDyiL1wc/etq0lGd37NICMMhhaSqxyg/view?utm_content=DAFYDyiL1wc&utm_campaign=designshare&utm_medium=link2&utm_source=sharebutton|Presentation Link]] | ||
Line 30: | Line 29: | ||
All these components are connected together to create a final project that allows the control of lightbulbs. The result is a fully-automated and voice-controlled Smart Home System that gives the user the ability to control various aspects of their home with ease. | All these components are connected together to create a final project that allows the control of lightbulbs. The result is a fully-automated and voice-controlled Smart Home System that gives the user the ability to control various aspects of their home with ease. | ||
- | ===== Software Description == | ||
- | ===== Conclusion ===== | + | The final diagram of all the components can be seen below and was made with the help of the EasyEDA program. |
+ | {{ :iothings:proiecte:2022:alexa-catalina-sirbu.png?500 |}} | ||
+ | ===== Software Description ==== | ||
+ | |||
+ | ==== Libraries === | ||
+ | * [[https://github.com/me-no-dev/AsyncTCP|AsyncTCP]] - This is a fully asynchronous TCP library, aimed at enabling trouble-free, multi-connection network environment for Espressif's ESP32 MCUs. | ||
+ | * [[https://www.arduinolibraries.info/libraries/button|Button-1.0.0]] - This is a tiny library to make reading buttons very simple. It handles debouncing automatically, and monitoring of state. | ||
+ | * [[https://github.com/mobizt/Firebase-ESP-Client|Firebase-ESP-Client]] - The managed, complete, fast and secure Firebase Client Library that supports ESP8266 and ESP32 MCU from Espressif | ||
+ | * [[https://github.com/vintlabs/fauxmoESP|fauxmoESP]] - This is a library for ESP8266/ESP32-based/Raspberry Pi Pico W devices that emulates Philips Hue lights and thus allows you to control them using this protocol, in particular from Alexa-powered devices like the Amazon Echo or the Dot | ||
+ | |||
+ | ==== Functionality === | ||
+ | Depending on how you want to change the state of the light bulb between on and off, we will go through each situation. | ||
+ | |||
+ | == Manual switches == | ||
+ | This traditional method is the most used for controlling light bulbs. The user can turn on or off the light using 2 buttons that transmit the information to the ESP and further the controller checks and turns on or off the status of the lights depending on the situation. A few stages of the entire program are described below: | ||
+ | * Performing the initial settings: implementing pins 1 and 2 for the 2 lightbulbs. | ||
+ | <file cpp Alexa-esp32.ino> | ||
+ | // LED | ||
+ | pinMode(RELAY_PIN_1, OUTPUT); | ||
+ | digitalWrite(RELAY_PIN_1, LOW); | ||
+ | |||
+ | pinMode(RELAY_PIN_2, OUTPUT); | ||
+ | digitalWrite(RELAY_PIN_2, LOW); | ||
+ | </file> | ||
+ | |||
+ | * Status change function. At the push of a button, if the light bulb is on, it will turn it off and if it is off, it will turn it on. | ||
+ | <file cpp Alexa-esp32.ino> | ||
+ | fauxmo.onSetState([](unsigned char device_id, const char* device_name, bool state, unsigned char value) | ||
+ | { | ||
+ | event_processed = false; | ||
+ | |||
+ | if ((strcmp(device_name, LAMP_1) == 0)) | ||
+ | { | ||
+ | alexa_flag_turn_on_red_lamp = state ? true : false; | ||
+ | alexa_flag_turn_off_red_lamp = state ? false : true; | ||
+ | } | ||
+ | if ((strcmp(device_name, LAMP_2) == 0)) | ||
+ | { | ||
+ | alexa_flag_turn_on_blue_lamp = state ? true : false; | ||
+ | alexa_flag_turn_off_blue_lamp = state ? false : true; | ||
+ | } | ||
+ | }); | ||
+ | </file> | ||
+ | |||
+ | == Alexa App == | ||
+ | This method allows us to use voice control with the help of an Echo Dot with the included Alexa application in order to change the state of the lights. The user can give the following commands: | ||
+ | * "Alexa, turn on the red light." / "Alexa, turn off the red light." | ||
+ | * "Alexa, turn on the blue light." / "Alexa, turn off the blue light." | ||
+ | * "Alexa, turn on/off the bedroom lights." - the 2 lightbulbs are configured in the "bedroom" group | ||
+ | * "Alexa, good morning!" - this will turn on the lightbulbs | ||
+ | * "Alexa, good night!" - this will turn off the lightbulbs | ||
+ | |||
+ | Implementation of switching the blue lamp between the two states using Alexa App. | ||
+ | <file cpp Alexa-esp32.ino> | ||
+ | Serial.println(fbdo_write.dataType()); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | error_flag = true; | ||
+ | } | ||
+ | } | ||
+ | else if (alexa_flag_turn_on_blue_lamp) | ||
+ | { | ||
+ | digitalWrite(RELAY_PIN_2, LOW); | ||
+ | alexa_flag_turn_on_blue_lamp = false; | ||
+ | |||
+ | // Write an Int number on the database path test/int | ||
+ | if (Firebase.RTDB.setInt(&fbdo_write, "lamp/blue", 1)) | ||
+ | { | ||
+ | Serial.print("Successfully wrote in RTDB to [data path]:"); Serial.print(fbdo_write.dataPath()); Serial.print(", [data type]: "); Serial.println(fbdo_write.dataType()); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | error_flag = true; | ||
+ | } | ||
+ | } | ||
+ | else if (alexa_flag_turn_off_blue_lamp) | ||
+ | { | ||
+ | digitalWrite(RELAY_PIN_2, HIGH); | ||
+ | alexa_flag_turn_off_blue_lamp = false; | ||
+ | |||
+ | if (Firebase.RTDB.setInt(&fbdo_write, "lamp/blue", 0)) | ||
+ | { | ||
+ | Serial.print("Successfully wrote in RTDB to [data path]:"); Serial.print(fbdo_write.dataPath()); Serial.print(", [data type]: "); | ||
+ | </file> | ||
+ | At each modification, the change is checked. If the status cannot be changed, it displays an error message. | ||
+ | <file cpp Alexa-esp32.ino> | ||
+ | Serial.println(fbdo_write.dataType()); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | error_flag = true; | ||
+ | } | ||
+ | } | ||
+ | if (error_flag) | ||
+ | { | ||
+ | Serial.println("Failed to update the RTDB :( "); Serial.println("REASON: " + fbdo_write.errorReason()); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </file> | ||
+ | |||
+ | |||
+ | == Firebase App == | ||
+ | |||
+ | Within the **buttonsHandling()** function, all the necessary changes are made to transmit the information to Firebase. The status of each lightbulb is checked and if any changes have been made, this will be displayed in real-time in the application. The stages of implementation are: changing the status, ascertaining the status, and implementing the application. | ||
+ | |||
+ | The web page consists of 2 buttons where you can see the status of the 2 lights. The page is interactive and we can press the buttons to change the state of the lights. | ||
+ | Also, if the status has been changed by voice command or by pressing the physical buttons, this can be seen in real-time on the web page. | ||
+ | |||
+ | {{ :iothings:proiecte:2022:firebase-catalina-sirbu.png?500 |}} | ||
+ | |||
+ | |||
+ | ===== Conclusion ===== | ||
+ | * In the case of this type of application using ESP32 and Firebase, I found many well-documented projects on the Internet and I was able to easily find solutions to problems encountered along the way. | ||
+ | * This application implements 3 simple ways to control 2 lights: with the help of physical buttons, with the help of the Alexa application, and with the help of a Firebase application where you can see the status of the lights in real-time. | ||
+ | * By introducing the application in everyday life, some activities can be made easier and the level of comfort can be increased, improving the quality of life. | ||
===== Resources ===== | ===== Resources ===== | ||
Line 42: | Line 157: | ||
* [[https://ardushop.ro/ro/electronica/96-buton-mare-push-button.html|Buttons]] | * [[https://ardushop.ro/ro/electronica/96-buton-mare-push-button.html|Buttons]] | ||
* [[https://www.sigmanortec.ro/modul-releu-cu-optocuplor-nivel-high-sau-low-selectabil-2-canale-5v|Optocoupler relay module]] | * [[https://www.sigmanortec.ro/modul-releu-cu-optocuplor-nivel-high-sau-low-selectabil-2-canale-5v|Optocoupler relay module]] | ||
- | ==== Components and their usage ==== | ||
==== Software information ==== | ==== Software information ==== |