Table of Contents

Smart Home System with Alexa App

Author: Catalina Sirbu ACES 2023
Web application
Source code on Github
Demo video
Presentation Link

Description

The control of 2 light bulbs is achieved in 3 ways:

Hardware Description

The proper use and integration of hardware components is crucial for the successful functioning and performance of any computer system or electronic project. The following components were chosen based on the ability to achieve a desired functional outcome while minimizing expenses.

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.

The final diagram of all the components can be seen below and was made with the help of the EasyEDA program.

Software Description

Libraries

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:

Alexa-esp32.ino
    // LED
    pinMode(RELAY_PIN_1, OUTPUT);
    digitalWrite(RELAY_PIN_1, LOW);
 
    pinMode(RELAY_PIN_2, OUTPUT);
    digitalWrite(RELAY_PIN_2, LOW);
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;
        }
    });
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:

Implementation of switching the blue lamp between the two states using Alexa App.

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]: ");

At each modification, the change is checked. If the status cannot be changed, it displays an error message.

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());
        }
    }
 
}
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.

Conclusion

Resources

Pictures sources

Software information