Introduction: LED Strip Controlled by Amazon Echo

Picture of LED Strip Controlled by Amazon Echo

Hello! This is a guide on how to control an RBG LED Strip from your Amazon Echo. You will be able to tell the Echo to turn on and off the LED strip along with changing its brightness and fading between colors. However, there is also more you can do if you customize this further.

Here is a video of it working:

Step 1: What You Will Need

Amazon Echo

Raspberry Pi B+ with breadboard kit (Any raspberry pi will work just make sure you have a Micro SD card, power supply, and a way to get internet connected to it as well)


Three MOSFETS (max threshold voltage of 3.3v)

Power Supply (12V DC ~2A)

Power jack


Jumper wires (Male to male) and (Male to Female)

You probably could find some of these laying around instead of buying the whole kit above but either way it’s a good way to get into electronics with the Pi.

Step 2: Setting Up the RGB LED Strip With the Raspberry Pi

First we will start with the setting up the RGBLED Strip with the Pi. This has been done before so you can follow this guide by Popoklopsi:

He explains it perfectly! The only difference however is that my Red wire from the RGB Strip is connected to pin 17 on my Pi’s GPIO, blue is connected to pin 24, and green is connected to 27. Once you can successfully change between the Red, Green, Blue or any other mix of colors from the command “pigs p 17 255” etc. you are ready for the next part.

Step 3: Setting Up Nginx

So we now can change the color of the light strip from the command line of the Raspberry Pi. This is pretty awesome! But we want to allow us to change the colors from the Amazon Echo.

To do so first let’s set up a web server for the Echo to communicate with on the Pi. Follow this official guide to set up nginx on your Raspberry Pi.

Make sure to also install PHP with it!

You now should be able to type in your Pi’s IP into your URL and connect to its website from any computer in your home. It will have the nginx default screen displayed or the default PHP page.

Step 4: Setting Up a Static IP

We need make sure that this IP stays the same so we will make your Raspberry Pi have a static IP. Here’s a simple guide to do it.

You may have to go searching else if this is outdated, also it might be slightly different if you are setting up one with a wired connection vs wireless.

Great! Now your Pi is hosting a web server with a static IP so you always know where it is hosting.

Step 5: Setting Up the Pi to Work With the Amazon Echo

Picture of Setting Up the Pi to Work With the Amazon Echo

Next we will write a script in python to check the contents of text file on the Pi. This script we will call The text file will be called settings.txt. The script will run a loop to constantly check the contents of the settings.txt file. Based on the contents of the settings.txt file the script will change the Raspberry Pi’s GPIO pins(17, 24, 27) to either be on or off from our pigpio library installed on the Pi. And by doing this the LED will change as you saw as you did before from the pigs p command.

The settings.txt file will have 5 numbers, the first 3 will determine the brightness of the lights, anything from 0 to 255. The forth number will be 0 or 1 to indicate whether or not the fade effect will be active, in order to fade between different colors (0 for off, 1 for on). The last number will indicate the color 0-9, and the script will change the GPIO pins to show a certain color from the LED strip based off the number you assign it.

The script is running a loop to constantly check the values of the settings.txt file. It gets the 5 numbers from the file and parses them to read the information correctly. It then uses the pigpio library to run the pigs p command based on the numbers from the file in order to change the LED colors.

One last thing in order for the script to get the contents of the settings.txt file it must send a request to a php file. We will call this getColors.php and this file will simply grab the contents of settings.txt for us.

The code for these three files can be found in my git hub repository located here:

When you download these files place in the same location where nginx is hosting its web server. Most like will be here:

cd /var/www/html

Step 6: Completing the RGB LED Strip With the Pi

This current configuration has the lights changing to full brightness for the color green with the fade effect turned off. You can see this because the first three numbers from the settings.txt file is 255 which is max brightness. The forth number is for the fade and it is zero so the fade settings is off. And the last number is 1, where as you can see in the file if this number is 1 it sets pin 27 high for green.

Once the files are in that directory we can test this part of the application. Run the python script by typing:


The lights should turn to green if 25501 is the current contents of the settings.txt file. Open a second terminal and navigate to the settings.txt file:

cd /var/www/html

Open the settings.txt file:

sudo nano settings.txt

Play around with the numbers in the file and make sure when you save and exit the LED Strip changes colors accordingly. Remember the first the numbers are the intensity, the forth is if you want to turn fading on, and the last is the number of the corresponding color.

Sweet! We now can change the color the LED’s based of the contents of the settings.txt file. Cool but we still haven’t even touch the Echo yet, but we are almost there!

So we somehow need the Echo to be able to communicate to the web server that the Pi is hosting to change the contents of the settings.txt file that will change the color of the LED Strip. We can make this happen from our web server. First we need to change the contents of the index.php file inside the directory /var/www/html. We need this file to allow a get request from an outside source to change the contents of the settings.txt. The index.php file is located in the same repository as before so make sure that you download that and overwrite your index.php with that one.

Step 7: Setting Up Access for Your Echo

Hosting this file on our webservers allows someone to write to the contents of the settings.txt file. You can see this file has the variables color, intensity, and fade. We write their values into the settings.txt file. But how do we set the variables to equal something? Since we are hosting this code on a webserver we can set the values through a query string. The code then gets the value from the query string that we write. For example, we can type:


Into our browser and the sever will set the intensity, fade, and color variables based on what you typed above. Make sure you are still running the script on your Pi and then type in the line above into any browser from any computer in your home. Make sure you replace my IP with the static IP you set for your Pi. The lights should change! Well actually they probably won’t because we don’t have high enough permissions to write the settings.txt file. To allow us to do so go to the /var/www/html directory on your Pi and type the following command:

sudo chmod 757 settings.txt

Now this is super unsafe as anyone can edit the file but since we are only testing a lights switch they can’t do that much damage. Just don’t ever use this on something very important. You can research other ways to do this safety but this is quick and I want to make it easy for beginners.

Okay so now go back and re run your script. And now type in the request into your browser and your lights should change accordingly. If not make sure that the settings.txt file is changing from the request and check and see if your stopped running with an error.

For this previous part I must credit 5errated from YouTube

Although my code is different he provided with the knowledge to combine a text file with a looping python script and a web server to change the contents of the text file and eventually change the color of the lights.

Alright so now it’s is time for the Echo. The Amazon Echo allows you to create skills such as a skill where you could request domino’s pizza or a twenty question game. We are going to create our own skill to change the colors of the lights. If you have never created a skill on the Echo I suggest you get some basic understanding from here first.

The code we write for the Echo needs to send a get request to our web server to change the lights. Here is the code I used to do so.

Step 8: How the Amazon Echo Code Works

Basically this code does the same thing you did with your web browser to change the lights on/off, its color, and the fade effect on/off. In the exports.js I have the different functions for the echo to perform based on what you say. So if you say “Alexa, turn on the lights” it runs the intent lights on, which runs the function LightsOn in the exports.js file. See the function code below.

function LightsOn(intent, session, callback) {

var cardTitle =;

var repromptText = "";

var sessionAttributes = {};

var shouldEndSession = true;

var speechOutput = "";

var tools = require('./tools');

tools.ChangeColorRequest("255", "pass", "pass", function(result) {

speechOutput = "The lights are now on.";

repromptText = "The lights are now on.";


buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession));



The lights on uses the tools.js file to send a request to the index.php web server hosted on your Pi. I pass in the value 255 for the lights intensity, and type “pass” for the color and fade so that only the intensity changes in the settings.txt file. So when you turn the lights off the next time you turn it on it will be the same color as before. The other functions work similarly, when changing the color, I type pass for the intensity and fade and then pass in a number for the last option to change the last number in the settings.txt file to the correct color.

In the tools.js make sure you change the hostname to your IP that your ISP gives you. Just type into google “what’s my IP” and it will be the first result.

I used the test.js file to test that I can change the value of the settings.txt file from my computer. I typed up this code in notepad++ and added a plugin to let me run node.js code from it. Here’s how you allow notepad++ to run node.js code

To make this code work with your echo you need to make a lambda function from this site (Amazon Management Console).

Make sure when you set up your function in the amazon management console to change "handler" to "exports.js" because I called the main file exports.

When you upload this code to the amazon management console you have to make a zip file since there is more than one file we are uploading. So zip the exports.js and tools.js files together and name that compressed folder exports. Then upload that compressed file to your lambda function in the amazon management console.

Step 9: Setting Up the Echo on the Amazon Developer Service Site

Now to make the skill on your Echo you need to go to this site:

Click on the Alexa tab and then click on Alexa Skills Kit. Here you will make the settings for your Alexa Skill to change the light strip. You will also link this to your Lambda Function that you just made on your last step so it knows what code to run.

Down on the interaction modal for when you create the skill you will need an intent schema. Here is mine below.


"intents": [


"intent": "ChangeColor",

"slots": [


"name": "Color",

"type": "COLOR"





"intent": "ChangeIntensity",

"slots": [


"name": "Intensity",






"intent": "LightsOn"



"intent": "LightsOff"



"intent": "DimLights"



"intent": "BrightenLights"



"intent": "MaxIntensity"



"intent": "MinIntensity"



"intent": "FadeOn"



"intent": "FadeOff"



"intent": "Exit"




Below that is the samples utterances. Here is mine.

ChangeColor change color to {Color}

ChangeColor change to {Color}

ChangeColor turn lights to {Color}

LightsOn turn lights on

LightsOff turn lights off

LightsOn lights on

LightsOff lights off

Exit exit

Exit quit

Exit quit god

Exit goodbye god

Exit goodbye

ChangeIntensity change intensity to {Intensity}

ChangeIntensity change brightness to {Intensity}

ChangeIntensity change intensity {Intensity}

ChangeIntensity change brightness {Intensity}

DimLights dim the lights

BrightenLights brighten the lights

DimLights intensity down

BrightenLights intensity up

DimLights brightness down

BrightenLights brightness up

MaxIntensity turn to maximum intensity

MaxIntensity turn to maximum brightness

MaxIntensity maximum intensity

MaxIntensity maximum brightness

MinIntensity turn to minimum intensity

MinIntensity turn to minimum brightness

MinIntensity minimum intensity

MinIntensity minimum brightness

FadeOn turn fade on

FadeOn fade on

FadeOff turn fade off

FadeOff fade off

Also for the custom slot types in the interaction modal I created my own called “COLOR” and the values in there are as follows:











Step 10: Configuring Your Pi So That the Echo Can Communicate With It

Picture of Configuring Your Pi So That the Echo Can Communicate With It

Alright so all seems fine but we need to do one last thing. Since your Amazon Echo’s code is hosted in the cloud it won’t be able to access index.php on your web server if you haven’t set up port forwarding. We do this in you router however for every router it’s different and hopefully you don’t have to go through multiple routers because that may complicate things. Anyways go to your main routers home page from your browser, most likely or 192.168.200. And in their search for a port forwarding tab and configure it like so.

Make sure to change the IP address to the static IP you gave your Pi. Also hopefully your ISP doesn’t block port 80 but if it does not big deal. You will just have to change the port nginx is hosting on and change the port corresponding above. Google should help you find that out.

Alright so now you can test your skill from the Amazon Developer Service under the test tab. If it all works out, you should be able to run any of the sample utterances I provided above by invoking the skill! In the skill information tab in the amazon developer service I named the invocation name “lights”. So all I have to say is “Alexa, ask lights to turn on.” Or “Alexa, ask lights to change to cyan”. Pretty cool right!?

If it’s not working start at the lowest level, your Pi command line and work your way up to the Echo to see what part is failing.

Good Luck!


BramK7 (author)2017-11-14

Can you also do this project if you have Alexa on a rasperry pi

i think it can but i am not sure

AdamF109 (author)BramK72017-11-15

It will work! In step 9 you need to use an amazon account to set up the skill. Make sure to use this account when you set up Alexa on your Raspberry Pi.

BramK7 (author)AdamF1092017-11-15

Do i then need To do step 10 or not

TechSevy (author)2017-08-10

Hi, I am currently trying the service simulator on the testing tab. I type an interaction phase like "change color to blue" and I get "The response is invalid" on the Lambda Response pane. I have changed the port and hostname on tools.js What should I do to fix this?

JoshL131 (author)2017-07-29

Man, I got it to work. This is great - thanks so much!!

owenperkins111 (author)2017-06-08

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Andale Mono'; color: #28fe14; background-color: #000000; background-color: rgba(0, 0, 0, 0.9)}
span.s1 {font-variant-ligatures: no-common-ligatures}

raceback (most recent call last):

File "", line 18, in <module>

response = requests.get("",)

File "/usr/lib/python2.7/dist-packages/requests/", line 60, in get

return request('get', url, **kwargs)

File "/usr/lib/python2.7/dist-packages/requests/", line 49, in request

return session.request(method=method, url=url, **kwargs)

File "/usr/lib/python2.7/dist-packages/requests/", line 457, in request

resp = self.send(prep, **send_kwargs)

File "/usr/lib/python2.7/dist-packages/requests/", line 569, in send

r = adapter.send(request, **kwargs)

File "/usr/lib/python2.7/dist-packages/requests/", line 407, in send

raise ConnectionError(err, request=request)

requests.exceptions.ConnectionError: ('Connection aborted.', error(111, 'Connection refused'))

TechSevy (author)owenperkins1112017-07-08

How did you get rid of this error?

JoshL131 (author)TechSevy2017-07-22

Hi, I was able to get rid of this by changing all of the "https://" to "http://" in the file. Hope that helps!

TechSevy (author)JoshL1312017-07-23

Thanks!!! That worked.

owenperkins111 (author)2017-06-15

Hi now i am getting "have a nice day on the amazon develpoer console" however this is all i can get if i say "ChangeColor BLUE" i get "have a nice day" or if i type "ChangeIntensity" i get the same is this right?

AdamF109 (author)owenperkins1112017-06-15

ChangeColor is just the function name, you need to type/say one of the phrases associated with ChangeColor. Here are snippets of phrases we associated with ChangeColor in our interaction model:

1.) ChangeColor change color to {Color}

2.) ChangeColor change to {Color}

3.) ChangeColor turn lights to {Color}

So for example, try typing "change color to blue" in the testing tab. Does Alexa say something different now?

owenperkins111 (author)AdamF1092017-06-15

"The remote endpoint could not be called, or the response it returned was invalid."- this is what i get when i type change the color to blue

AdamF109 (author)owenperkins1112017-06-16

Sorry that you're getting so many errors I think I know what is wrong though.

In the "tools.js" file:

1.) (Line 8)Change the port from 443 to 80 (Assuming that's the one you opened in step 10)

2.) (Line 7)Switch out hostname '' with your EXTERNAL ip. This is different from the internal ip you assigned to your raspberry pi. On any computer in your home network open up the browser and search "external ip" and the one you have should pop up as the first result.

Let me know if that fixes it.

owenperkins111 (author)AdamF1092017-06-18

Hi yes i have done both of these things still getting the same result, however im just concerned that it may be the handler, on the option in the lambda console, is it the configuration tab and then the handler box that i should be changing from index.handler to "exports.handler"? could this be the problem and sorry for the slow reply i have been away, Thanks so much for your continuing help.

AdamF109 (author)owenperkins1112017-06-23

It should work either way, you could change it to index.handler, but then make sure you rename the local file to index.js and the zip to index.

owenperkins111 (author)2017-06-14

In the service simulator tab when i enter an utterance i get the lambda on the left but on the right where the response is i get "The remote endpoint could not be called, or the response it returned was invalid." i have invocation name as "rooms glow" and have tried everything. Thanks again for your help

AdamF109 (author)owenperkins1112017-06-14

One thing you should try is in the Lambda Management Console:

1.) select your function name

2.) Click on the code tab

3.) Click on the "Actions" drop down

4.) Select "configure test event"

5.) For sample event template choose "Alexa Start Session"

6.) Click "Save and test"

Does the output say "Hello, how may I help you today?" Or does it error out?

owenperkins111 (author)AdamF1092017-06-15

no i do get the Hello how may i help you today

AdamF109 (author)owenperkins1112017-06-14

Yeah that means there is something wrong, most likely in the lambda function code, I will get back to you later today with a more detailed walk through of how we can debug it.

owenperkins111 (author)AdamF1092017-06-14

Thankyou so much

owenperkins111 (author)2017-06-14

When you say change the handler to exports.js do u mean on the box or on the code? this may be the problem

AdamF109 (author)owenperkins1112017-06-14

You should name the javascript file "exports.js" the compressed zip to "exports" and in the lambda console the handler should be called "exports.handler"

owenperkins111 (author)AdamF1092017-06-15

with the javascript file u mean the one that is on github so leave the name as export.js? im just confused because on step 8 you said "Make sure when you set up your function in the amazon management console to change "handler" to "exports.js" because I called the main file exports."


owenperkins111 (author)2017-06-14

Also do i have to go through the publishing stuff on that page to get it published and stuff or can i use it without doing that ?

AdamF109 (author)owenperkins1112017-06-14

No, you do not need to publish the skill, it should work only for you right now.

owenperkins111 (author)2017-06-13

Okay now im just really confused at step 9 i think that i did step 8 correctly but am so confused at step 9

AdamF109 (author)owenperkins1112017-06-13

Step nine is where you create the settings for your alexa skill and how the user will interact with it. This article explains how to do this well: " Step 1 in the article is the same process as my step 8, and step 2 in the article is the same process in step 9 of mine just in further detail. Look how they did step two in the article and create your skill the same way following these differences:


In the Skill information tab, create an invocation name that is relevant, for example if the LED strip is for your desk, you could use the invocation name "desk lights" . That way when you use the skill you would say "Alexa, ask desk lights change colors to blue".


On the next tab called Interaction Model you should copy the Intent Schema, Custom Slot Type, and Sample Utterances I provided in step 9 and paste them into here. Also there is a BETA for the interaction model tab so if you're in it scroll to the bottom and click leave, then you will be at the screen where you can paste these values in.


On the configuration tab, select "AWS Lambda ARN" as the "service endpoint type". Then check mark North America. Now go back to the Amazon Management Console, select the lambda function you created, and copy the ARN in the top right corner. It should look similar this "arn:aws:lambda:us-east-1:xxxxxxxxxxx:function:MyLambdaFunction". And then paste this value back in the Developer Portal where it ask for the ARN value. Also make sure you created this lambda function in the "N.Virginia" region. You can change the region you are in the upper right hand corner of the Management Console.

Let me know if you get stuck anywhere or are still having trouble with the setup.

owenperkins111 (author)2017-06-09

hi sorry to be a pain, i have got that working so thanks for the reply it was also because i hadnt changed the server address to http instead of https on the However i cannot get the leds to change by using the web sever and typing in the url, i have made sure to use the correct ip and have made it accessible with the permissions but i dont get anything on the screen when i even try to access the server is this correct? and i have checked the settings file and the numbers are not changing when i do this any ideas and sorry aha im quite new to linux

AdamF109 (author)owenperkins1112017-06-10

No problem. What is the full URL you are typing in to change the LEDs? Also you are right that the screen should be blank. You can be sure you're reaching the right URL by putting <h1>LED Control Screen</h1> at the bottom of your index.php file. And then when you access the page you should see the text "LED Control Screen". Let me know if that helps.

owenperkins111 (author)AdamF1092017-06-11

Hi thanks again for helping i am typing in exactly as you have on the instructions as i have the same static ip but nothing happens even if i put the <h1>LED Control Screen</h1> at the end of index.php i cannot see it when i type in the ip

AdamF109 (author)owenperkins1112017-06-11

I would guess then that the nginx server isn't running on the Raspberry Pi, or the nginx server isn't pointing towards the index.php file. Can you retry the setup in step three where you set up the nginx server from this site: Specifically I would check the file "sudo nano /etc/nginx/sites-enabled/default" and ensure that you added "index.php" around line 25 so it looks like this "index index.php index.html index.htm;". Were you able to get this step to work before where the webpage showed "Welcome to nginx"?

owenperkins111 (author)AdamF1092017-06-12

hi yes i know the server is working as if i change the index.php file to just <?php echo phpinfo (); ?> i get the info on the php as i should and yes i did get that screen the welcome to nginx screen

it seems to just be when i use your index.php file i cannot get anything from the server even if i include the same text to get the php info on screen i cannot do it again i am really sorry for this

AdamF109 (author)owenperkins1112017-06-12

This might be it. In line 30 of the index.php file does it say this: "file_put_contents('settings.txt', $combined);" I think I was missing the starting ' for 'settings.txt'. Let me know if that fixes it, I uploaded the new index.php file to my github already.

owenperkins111 (author)AdamF1092017-06-13

hi it worked thanks so much

owenperkins111 (author)AdamF1092017-06-13

Hi yes that fixed it!! Thank you so much for your help man

AdamF109 (author)owenperkins1112017-06-13

No problem! Let me know if you run into anymore problems.

owenperkins111 (author)2017-06-09

Hi thanks for the reply and yes it was not only this what you said but instead of it being https it was just http but that solved the problem thanks so much man

owenperkins111 (author)2017-06-08

every time i try to tun the i get this and i have tried everything im not sure if it is what bruster said about the auth=parameters but i am not sure on how to do that thanks any help would be appriciated

AdamF109 (author)owenperkins1112017-06-08

If you replace "response = requests.get("", verify=False)" in lines 18, 22, and 82 with "response = requests.get("", verify=False)" do you get the same error? I think I might have changed test1.php to getColors.php in my last push to github.

Cahsee1000 (author)2017-01-12

do you think this would work with a Google Home?

AdamF109 (author)Cahsee10002017-02-07

Hello Cashee,

I did some research and this would definitely be possible with the google home. You can create a skill for your google home at this link:

There are many ways to go about changing the LED strip after that. You could have your google home skill post to a AWS API endpoint that interacts with a AWS lambda function, which you would create both the API and Lambda Function in AWS. Your lambda function then could directly post to the web server on your pi like how I did from the inscrutables above. Or your lambda function could change the state of the LED strip in AWS IoT, and your pi could listen to the state changes in AWS IoT and change the gpio pins accordingly. I know that was a lot, let me know if you have any questions.

AdamF109 (author)Cahsee10002017-01-25

I'm not sure, if you are able to program your own skills on a Google Home similar to the Amazon Echo I would say so. I'll will do some research on it, please let me know if you find anything on it!

bruster999 (author)2017-01-24


Great tutorial. I'm trying to build this but there seems to be an indentation issue with the code in and since it's Python that detail is very critical. For example, line 33 is an "if" statement so the following lines must be indented but is the "while" statement on line 43 also under the same indentation or does it move back to the same level as the "if"?

I can probably guess the indentation needed but would you be able to update the git code by any chance?

Thanks again. Great instructable.

bruster999 (author)bruster9992017-01-26

That worked perfectly. Thanks for uploading the code! The only change I had to make was adding an auth= parameter to the requests.get command. I must not have security set up right to allow this from a script.

AdamF109 (author)bruster9992017-01-26

Awesome! I'm glad it worked for you. Let me know if you have any other questions

AdamF109 (author)bruster9992017-01-25

One more thing, make sure to replace your pi's ip with mine again, (I'm using a different IP on my raspberry pi now - Also I don't think you need the "verify=false" part after.

AdamF109 (author)bruster9992017-01-25

Okay I think I fixed it a while ago but never uploaded it to GitHub. It's up there now, let me know if it works for you!

AdamF109 (author)bruster9992017-01-25


Yes you are correct, the indentation got messed up somewhere when I uploaded it to GitHub. I'll try to re-upload it soon.

Swansong (author)2016-09-15

Thanks for sharing :)

About This Instructable




More by AdamF109:LED Strip Controlled by Amazon Echo
Add instructable to: