Things used in this project

Hardware components:
Echo
Amazon Alexa Amazon Echo
×1
Photon new
Particle Photon
×1
Fairchild semiconductor pn2222abu. image
General Purpose Transistor NPN
×1
Mfr 25frf52 100r sml
Resistor 100 ohm
×1
Mfr 25frf52 1k sml
Resistor 1k ohm
×1
LED Infrared 950nm
×1
IR receiver (generic)
Optional
×1
Software apps and online services:
Screen%20shot%202015 07 20%20at%206.10.26%20pm
Amazon Web Services AWS Lambda
Particle.io
Dp image kit 02
Amazon Alexa Alexa Skills Kit

Schematics

Schematics
Alexa photon tv remote steckplatine uoxlasec37

Code

Photon CodeC/C++
int sendIR(String s);
int IRledPin = A4;
int led = D7;

void setup() {
    pinMode(IRledPin, OUTPUT);
    pinMode(led, OUTPUT);
    Serial.begin(9600);
    Particle.function("send", sendIR);
}

void loop() {
}

void pulse(long microsecs) {
    while (microsecs > 0) {
        // 38 kHz is about 13 microseconds high and 13 microseconds low
        digitalWrite(IRledPin, HIGH); // this takes about 3 microseconds to happen
        delayMicroseconds(10); // hang out for 10 microseconds, you can also change this to 9 if its not working
        digitalWrite(IRledPin, LOW); // this also takes about 3 microseconds
        delayMicroseconds(10); // hang out for 10 microseconds, you can also change this to 9 if its not working
        // so 26 microseconds altogether
        microsecs -= 26;
    }
}

int sendIR(String s) {
    
    // visual confirmation
    digitalWrite(led, HIGH);
    delay(500);
    digitalWrite(led, LOW);
    
    pulse(5000);
    delayMicroseconds(5000);
    pulse(560);
    delayMicroseconds(1600);
    pulse(560);
    delayMicroseconds(1600);
    pulse(560);
    delayMicroseconds(1600);
    pulse(560);
    delayMicroseconds(560);
    pulse(560);
    delayMicroseconds(560);
    pulse(560);
    delayMicroseconds(560);
    pulse(560);
    delayMicroseconds(560);
    pulse(560);
    delayMicroseconds(560);
    pulse(560);
    delayMicroseconds(1600);
    pulse(560);
    delayMicroseconds(1600);
    pulse(560);
    delayMicroseconds(1600);
    pulse(560);
    delayMicroseconds(560);
    pulse(560);
    delayMicroseconds(560);
    pulse(560);
    delayMicroseconds(560);
    pulse(560);
    delayMicroseconds(560);
    pulse(560);
    delayMicroseconds(560);
    pulse(560);
    delayMicroseconds(560);
    pulse(560);
    delayMicroseconds(1600);
    pulse(560);
    delayMicroseconds(560);
    pulse(560);
    delayMicroseconds(560);
    pulse(560);
    delayMicroseconds(560);
    pulse(560);
    delayMicroseconds(560);
    pulse(560);
    delayMicroseconds(560);
    pulse(560);
    delayMicroseconds(560);
    pulse(560);
    delayMicroseconds(1600);
    pulse(560);
    delayMicroseconds(560);
    pulse(560);
    delayMicroseconds(1600);
    pulse(560);
    delayMicroseconds(1600);
    pulse(560);
    delayMicroseconds(1600);
    pulse(560);
    delayMicroseconds(1600);
    pulse(560);
    delayMicroseconds(1600);
    pulse(560);
    delayMicroseconds(1600);
    pulse(560);
    
    return 1;
}
Alexa Intent SchemaJSON
The intent schema has to be pasted in the intent schema box in the Interaction model section of the Alexa skill in the Alexa Skills Kit Ui.
{
  "intents": [
    {
      "intent": "SwitchOnIntent"
    },
    {
      "intent": "SwitchOffIntent"
    },
    {
      "intent": "AMAZON.HelpIntent"
    },
    {
      "intent": "AMAZON.StopIntent"
    },
    {
      "intent": "AMAZON.CancelIntent"
    }
  ]
}
Sample utterancessnippets
The sample utterances have to be pasted in the sample utterances box in the Interaction model section of the Alexa skill in the Alexa Skills Kit Ui.
SwitchOnIntent switch t v on
SwitchOnIntent switch television on
SwitchOnIntent switch t v set on
SwitchOnIntent on
SwitchOffIntent switch t v off
SwitchOffIntent switch television off
SwitchOffIntent switch t v set off
SwitchOffIntent off
AWS Lambda CodeJavaScript
Node.js code for a AWS Lambda Function for Alexa. Save it as index.js.
'use strict';
const Alexa = require('alexa-sdk');
const p = require('./particle.js');

const languageString = {
    "en-US": {
        "translation": {
            "WELCOME_MESSAGE": "t v remote is ready. ",
            "STOP_MESSAGE": "Stopped. ",
            "ON_MESSAGE": "I switch the t v on for you. ",
            "OFF_MESSAGE": "I switch the t v off for you. ",
            "HELP_MESSAGE": "Say: Switch on the t v or switch off the t v. ",
            "HELP_REPROMPT": "Say: Switch on the t v or switch off the t v. ",
            "ERROR_MESSAGE": "Something went wrong. "
        }
    },
     "en-GB": {
        "translation": {
            "WELCOME_MESSAGE": "t v remote is ready. ",
            "STOP_MESSAGE": "Stopped. ",
            "ON_MESSAGE": "I switch the t v on for you. ",
            "OFF_MESSAGE": "I switch the t v off for you. ",
            "HELP_MESSAGE": "Say: Switch on the t v or switch off the t v. ",
            "HELP_REPROMPT": "Say: Switch on the t v or switch off the t v. ",
            "ERROR_MESSAGE": "Something went wrong. "
        }
    },
    "de-DE": {
        "translation": {
            "WELCOME_MESSAGE": "Fernbedienung ist gestartet. ",
            "STOP_MESSAGE": "Beendet. ",
            "ON_MESSAGE": "Ich schalte den Fernseher für dich an. ",
            "OFF_MESSAGE": "Ich schalte den Fernseher für dich aus. ",
            "HELP_MESSAGE": "Sage: Schalte Fernseher an oder Schalte Fernseher aus. ",
            "HELP_REPROMPT": "Sage: Schalte Fernseher an oder Schalte Fernseher aus. ",
            "ERROR_MESSAGE": "Das hat leider nicht funktioniert. "
        }
    }
};

const password = process.env.PASSWORD;
const username = process.env.USERNAME;
const deviceid = process.env.DEVICEID;
const appid    = process.env.APPID;

exports.handler = function(event, context, callback) {
    var alexa = Alexa.handler(event, context);
    alexa.appId = appid;  
    alexa.resources = languageString;
    alexa.registerHandlers(handlers);
    alexa.execute();
};

const handlers = {
    'LaunchRequest': function () {
        const self = this; 
        p.particle_get_token(username,password).then(  
            access_token => {
                self.attributes["token"] = access_token;
                const speechOutput = self.t('WELCOME_MESSAGE');
                self.emit(':ask',speechOutput);
      
            },
            err => {
                console.log(`Fehler: ${err}`);
            }
        );
    },
    'SwitchOnIntent': function () {
        // function send is implemented in sendrawir.ino
        this.emit('Call','send',this.t('ON_MESSAGE')); 
    }      
    ,
    'SwitchOffIntent': function () {
        // function send is implemented in sendrawir.ino
        this.emit('Call','send',this.t('OFF_MESSAGE'));     
    },
    'Call': function(func,message) {
        const self = this; 
        if(this.attributes["token"]) {
            let access_token=this.attributes["token"];
            p.particle_function_call(access_token,deviceid,func).then( 
                body => {
                    const speechOutput = message; 
                    self.emit(':tell', speechOutput); 
                },
                err => {
                    console.log(`${err}`);
                    const speechOutput = this.t('ERROR_MESSAGE');
                    self.emit(':tell',speechOutput);
                }
            );
        }
        else {
           const speechOutput = this.t('ERROR_MESSAGE');
           self.emit(':tell',speechOutput); 
           // TODO: end here
        }

    },
    'AMAZON.HelpIntent': function () {
        const speechOutput = this.t('HELP_MESSAGE');
        const reprompt = this.t('HELP_MESSAGE');
        this.emit(':ask', speechOutput, reprompt);
    },
    'AMAZON.CancelIntent': function () {
        this.emit(':tell', this.t('STOP_MESSAGE'));
    },
    'AMAZON.StopIntent': function () {
        this.emit(':tell', this.t('STOP_MESSAGE'));
    },
    'SessionEndedRequest': function () {
        this.emit(':tell', this.t('STOP_MESSAGE'));
    }
};
AWS Lambda Code for Particle PhotonJavaScript
Node.js code for a AWS Lambda Function for Particle Photon. Save it as particle.js.
const rp = require('request-promise');
const request = require('request');

exports.particle_get_token = (username,password) => {
	
	const options = {

		method: 'POST',
		uri: 'https://api.particle.io/oauth/token',
		auth: {
			user: 'particle',
			pass: 'particle'
		},
		headers: {
			contentType: 'application/x-www-form-urlencoded',
		},
		form: {
			grant_type: 'password',
	    	username: username,
	    	password: password
		}
	}
	
	return rp(options).then(
		body => {
			const access_token = JSON.parse(body).access_token;
			return(access_token);
		},
		err => {
			console.log(`${err}`);
			return(err);
		}
	);
}

exports.particle_function_call = (access_token,deviceid,api_function) => {

	const options = {
	
		method: 'POST',
		uri: `https://api.particle.io/v1/devices/${deviceid}/${api_function}`,
		headers: {
			contentType: 'application/x-www-form-urlencoded',
		},
		form: {
			access_token: access_token,
		}
	}

	return rp(options).then(
		body => {
			return(body);
		}, 
		err => {
			console.log(`${err}`);
			return(err);
		}
	);
};
   

Credits

5a72c17e1c96dc7d87a5b71454201325
Moritz Strube

I’m an experienced technology manager and business developer with deep interest in technology, innovation and science.

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Lightweight Sliding Door Automator
Intermediate
  • 1,557
  • 8

Work in progress

Automate the opening and closing of a lightweight sliding door (e.g. a screen door), including remote controls on your phone.

Christmas Gift Box
Intermediate
  • 3,634
  • 595

Full instructions

Christmas Gift Box plays music and sends an email when it is opened.

Carbon Fiber Vacuum Chamber
Intermediate
  • 2,909
  • 94

Full instructions

Our project is a carbon fiber vacuum chamber that is monitored by multiple particle photons and various sensors.

ConnectTheDots with Particle Azure IoT Hub Integration
Intermediate
  • 844
  • 8

Protip

This project will allow you to connect your Particle device into an Azure IoT Hub for viewing data in real-time through an ASP.NET web app!

What should I wear outside?
Intermediate
  • 5,046
  • 67

Full instructions

A whimsical weather clock powered by Particle and forecast.io

LED Reflection Clock
Intermediate
  • 2,176
  • 35

Work in progress

Using 60 LED's facing a suitable wall, the time is projected in colour.

Add projectSign up / Login