Project tutorial
Light Control Using Arduino and Amazon Alexa

Light Control Using Arduino and Amazon Alexa © GPL3+

Control a light using Amazon skill kit and Arduino!

  • 16,186 views
  • 1 comment
  • 19 respects

Components and supplies

Apps and online services

About this project

How to control light using Amazon Alexa Skill and Arduino uno

I have explained how to control light which is connected to UNO and controlled by Alexa . There are many ways to use Alexa service . First we are going to install dependencies on RPi and then we create Alexa skill .

Raspberry Pi

1. Install the required libraries

sudo apt-get install python-pip  
sudo
sudo
sudo apt-get install python-serial 
sudo apt-get intall libpython2.7-dev 

2. Install Arduino IDE on RPi or you can program using your pc and then connect it serially with RPi

To install Arduino in RPi

1. Go to official site and download previous release.

https://www.arduino.cc/en/Main/OldSoftwareReleases#previous

After that unzip it and go to directory of arduino

and start it with ./arduino

Program to be used in Arduino

int led = 13; 
void setup() { 
 // put your setup code here, to run once: 
 pinMode(led, OUTPUT); 
   Serial.begin(9600); 
} 
void loop() { 
 if (Serial.read() == 'N') { 
    digitalWrite(led, HIGH); 
 }else if(Serial.read() == 'F') { 
    digitalWrite(led, LOW); 
 } 
} 

After uploading program,open serial terminal

when you write N led will turn on

When you write F led will turn off

2. Make a python script

from flask import Flask 
from flask_ask import Ask, statement 
import requests 
import json 
import serial 
ser = serial.Serial("/dev/ttyACM0", 9600)  // pls change here for your serial
app = Flask(__name__) 
ask = Ask(app, '/') 
@ask.launch 
@ask.intent("LightOn") 
def on(): 
   ser.write(b'N') 
   return statement("Hall light turned on.") 
@ask.intent("LightOff") 
def off(): 
   ser.write(b'F') 
   return statement("Hall light turned off.") 
if __name__ == "__main__": 
   app.run(debug=True) 

Run it using python lighcontrol.py

3. Download Ngrok

Ngrok is secure tunneling platform to make your device online. With this platform you can make your web application or any application goes online with a very simple way. For download go to official site and download for ARM.

https://ngrok.com/

Unzip it and go to directory where you extract it. Run it using command

./ngrok http 5000 

Amazon Site

1. We have to Login to Amazon account.If you have an account then login it, if not signup there and login.

https://developer.amazon.com/

2. Go to Developer Console on top right side.

3. Go to Alexa ==> Alexa skill kit ==> Add new skill

4. You will see page like this. On this page it will ask skill type, name, language and invocation name . You can give any name, in invocation name you have to give name which you say while giving command to Alexa.

Please note select appropriate language which is used in you country if you select different language while creating skill. It will not work.

At the end update it ,save it and press next.

5. On next page, it will ask intents.An intent represents an action that fulfills a user’s spoken request. For more information

https://developer.amazon.com/docs/custom-skills/define-the-interaction-model-in-json-and-text.html

If there is any error you will see in red color.

{ 
 "intents": [ 
   { 
     "intent": "LightOn" 
   }, 
   { 
     "intent": "LightOff" 
   } 
 ] 
} 

save it and move to next page.

6. On next page it will ask two option for end point one is AWS and HTTPS

Here i am using HTTPS . The secure link is generated in Ngrok server use that your link is different than mine. Save it and move to next page.

7. For SSL certificate choose second option. Save it and move to next page.

8. To test whether our service is working or not . Make sure your Ngrok server is working and Python script also running otherwise it will not work.

You can see servers are getting request and post it.

Demo

You can see video here.

Working Demonstration

Code

RPiArduinoPython
from flask import Flask
from flask_ask import Ask, statement
import requests
import json
import serial

ser = serial.Serial("/dev/ttyACM0", 9600)

app = Flask(__name__)
ask = Ask(app, '/')

@ask.launch

@ask.intent("LightOn")
def on():
    ser.write(b'N')
    return statement("Hall light turned on.")

@ask.intent("LightOff")
def off():
    ser.write(b'F')
    return statement("Hall light turned off.")

if __name__ == "__main__":
    app.run(debug=True)
ArduinoLedArduino
int led = 13;

void setup() {
  // put your setup code here, to run once:
  pinMode(led, OUTPUT);
    Serial.begin(9600);

  
}

void loop() {
  if (Serial.read() == 'N') {
     digitalWrite(led, HIGH);
  }else if(Serial.read() == 'F') {
     digitalWrite(led, LOW);
  }

  
 }

Schematics

RPiArduino
Rpi arduino icpzvxta0a
ArduinoLed
Arduinoled gzk5tq1xbf

Comments

Similar projects you might like

Enable Alexa Control to your Ceiling Fan

Project tutorial by Jithin Thulase

  • 3,123 views
  • 5 comments
  • 9 respects

Arduino-Powered Smart Light (Works with Amazon Echo)

Project tutorial by Tinker Project

  • 14,717 views
  • 7 comments
  • 29 respects

Alexa Doorman: Who Is at My Door?

Project tutorial by MD R. Islam

  • 9,151 views
  • 0 comments
  • 25 respects

Animated Smart Light with Alexa and Arduino

Project tutorial by Bruno Portaluri

  • 3,662 views
  • 9 comments
  • 23 respects

Amazon Alexa / Arduino YÚN Smart Home Light Sample

Project showcase by Noctuvigilus

  • 3,242 views
  • 0 comments
  • 9 respects

Anna: Alexa Powered Interactive Light

Project tutorial by vincent wong

  • 1,896 views
  • 0 comments
  • 7 respects
Add projectSign up / Login