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

Next we will write a script in python to check the contents of text file on the Pi. This script we will call controller.py. The text file will be called settings.txt. The controller.py 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 controller.py 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 controller.py script will change the GPIO pins to show a certain color from the LED strip based off the number you assign it.

The controller.py 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 controller.py 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 controller.py 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 controller.py python script by typing:

python controller.py

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 controller.py 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 controller.py 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 controller.py stopped running with an error.

For this previous part I must credit 5errated from YouTube https://www.youtube.com/watch?v=n6u-H1sza-w

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 = intent.name;

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

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!



  • Faux-Real Contest

    Faux-Real Contest
  • Remix Contest

    Remix Contest
  • Epilog X Contest

    Epilog X Contest

51 Discussions


1 year ago

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

i think it can but i am not sure

2 replies

Reply 1 year ago

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.


Reply 1 year ago

Do i then need To do step 10 or not


1 year ago

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?


1 year ago

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


1 year ago

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 "controller.py", line 18, in <module>

response = requests.get("",)

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

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

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

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

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

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

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

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

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

raise ConnectionError(err, request=request)

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

3 replies

Reply 1 year ago

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


1 year ago

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?

5 replies

Reply 1 year ago

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?


Reply 1 year ago

"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


Reply 1 year ago

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.


Reply 1 year ago

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.


Reply 1 year ago

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.


1 year ago

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

3 replies

Reply 1 year ago

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?


Reply 1 year ago

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.