Voice Control your devices with Alexa under $5 !!

Research

In this section, I would like to inform you about all the options that I explored to accomplish this. First I started with research about how microcontrollers works and started with understanding Arduino( I remember I worked on it in College Time for creating a line follower bot, but its an Advance version in current days)

  • Google Assistant( Accomplished)
  • Alexa Custom Skills(Partially Accomplished)
  • Alexa Custom Smart Home Skills(Partially Accomplished)
  • Existing Alexa Smart Home Skills(Accomplished, Easy and Cost Saving)
Architecture Diagram which I implemented

Actual Implementation

There are few hardware prerequisites for this functionality.

adding board to board manager.
  • Search ESP8266 and Install it.
Esp8266 library installation
select the board
  • NC (Normally Closed): the normally closed configuration is used when you want the relay to be closed by default. The NC are COM pins are connected, meaning the current is flowing unless you send a signal from the ESP8266 to the relay module to open the circuit and stop the current flow.
  • NO (Normally Open): the normally open configuration works the other way around: there is no connection between the NO and COM pins, so the circuit is broken unless you send a signal from the ESP8266 to close the circuit.
#ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#include <Espalexa.h>
// -------- WIFI INFORMATION -----
const char *WIFI_SSID = "---username";
const char *WIFI_PASSWORD = "----password---";
void bedroomLightChange(EspalexaDevice* dev);
Espalexa espalexa;
EspalexaDevice* bedroomLight;
// To Control Lights
int bedroomLightPin=5; // D1
void connectToWiFi(){

// This function will try to connect to WIFI
Serial.println(" Trying to connect to WiFi..");
Serial.println(WIFI_SSID);

WiFi.begin(WIFI_SSID,WIFI_PASSWORD);

// try only for 15 times and then take a pause.
int retries = 0;
while(WiFi.status() != WL_CONNECTED && retries < 15) {
delay(500);
Serial.print(".");
retries++;
}

Serial.println("WiFi Connected");
Serial.println("IP Address: ");
Serial.println(WiFi.localIP());

}
void bedroomLightChanged(EspalexaDevice* d){
if (d == nullptr) Serial.println("Sorry No device Found");
if(d->getValue()){
//Tune on the device
digitalWrite(bedroomLightPin,HIGH);
d->setValue(127);
Serial.println("Turned on the light");
}else{
// Turn off the device
digitalWrite(bedroomLightPin, LOW);
d->setValue(0);
Serial.println("Turned off the light");
}


}
void lightsInitalize(){// Setup the inbuilt LED Pin
pinMode(LED_BUILTIN, OUTPUT);
// Low BedroomLight_01
pinMode(bedroomLightPin,OUTPUT);
digitalWrite(bedroomLightPin,LOW);
}void setup() {
Serial.begin(9600);
lightsInitalize();
connectToWiFi();
bedroomLight = new EspalexaDevice("Bedroom Light", bedroomLightChanged,EspalexaDeviceType::dimmable);
espalexa.addDevice(bedroomLight);
espalexa.begin();
}void loop() {
// put your main code here, to run repeatedly:
espalexa.loop();
delay(1);
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(50); // wait for a second
}
#ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#include <Espalexa.h>
// -------- WIFI INFORMATION -----
const char *WIFI_SSID = "---username";
const char *WIFI_PASSWORD = "----password---";
void bedroomLightChange(EspalexaDevice* dev);
Espalexa espalexa;
EspalexaDevice* bedroomLight;
// TO Control Lights
int bedroomLightPin=5; // D1
void connectToWiFi(){

// This function will try to connect to WIFI
Serial.println(" Trying to connect to WiFi..");
Serial.println(WIFI_SSID);

WiFi.begin(WIFI_SSID,WIFI_PASSWORD);

// try only for 15 times and then take a pause.
int retries = 0;
while(WiFi.status() != WL_CONNECTED && retries < 15) {
delay(500);
Serial.print(".");
retries++;
}

Serial.println("WiFi Connected");
Serial.println("IP Address: ");
Serial.println(WiFi.localIP());

}
void lightsInitalize(){// Setup the inbuilt LED Pin
pinMode(LED_BUILTIN, OUTPUT);
// Low BedroomLight_01
pinMode(bedroomLightPin,OUTPUT);
digitalWrite(bedroomLightPin,LOW);
}
void setup() {
Serial.begin(9600);
lightsInitalize();
connectToWiFi();
bedroomLight = new EspalexaDevice("Bedroom Light", bedroomLightChanged,EspalexaDeviceType::dimmable);
espalexa.addDevice(bedroomLight);
espalexa.begin();
}
uploading sketch
Top right corner of Arduino IDE
Serial Monitor showing the IP acquired

Conclusion

So this is how I started the journey towards IOT, there are few more projects on which I am currently working. I will keep on posting my research. Thanks for reading 🙌

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store