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.

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

Drop of Life
Intermediate
  • 515
  • 16

Full instructions

A display to remind me when I can donate blood and save lives, powered by the Red Cross API and Particle.

IoT Drone - Part 2 - Sensors
Intermediate
  • 54
  • 1

Work in progress

Part 2 incorperates a GPS receiver, 10 DOF IMU, and Ultrasonic distance sensor to be used for flight controls.

How to run Particle on Raspberry Pi (Headless on Pi Zero W)
Intermediate
  • 1,433
  • 18

Protip

Use the most popular single-board computer with the most popular IoT tools.

Wireless Tank and Pump Monitoring System with Mobile App
Intermediate
  • 412
  • 3

Particle and Blynk to wirelessly monitor a 4,000 gallon water distribution system.

IoT Controlled Planter Lights
Intermediate
  • 468
  • 6

This is a shelf for starting plant seeds, controlled over the internet with automatic lights.

Your Wife is Hot!
Intermediate
  • 529
  • 6

Full instructions

Not hot like she looked at your browser history, hot as in temperature hot! This can be avoided with an A/C Condensate Monitoring System.

Your Wife is Hot!

Team Is it Summer Yet?

Add projectSign up / Login
Respect project