Alexa Controlled Smart Fan
Created by Alvin O'garro and Clay Eckman
Introduction

Alexa Controlled Smart Fan allows the user to use voice commands via Alexa to remotely control a fan. Available commands include those to turn the fan on/off, control fan speed, and set the fan to mode which sets fan speed based on temperature feedback.
Commands
- Turn off
- Turn on manual mode
- Turn up speed
- Turn down speed
- Turn on temperature feedback mode
- Set target temperature to "__"
Wiring
| Mbed | TB6612FNG H Bridge Breakout Board | DC Motor/Fan | TMP36 Temp Sensor | RJ45 Ethernet Port | External 5V |
| p5 | AIN2 | ||||
| p6 | AIN1 | ||||
| p15 | Vout | ||||
| RU- | p8 | ||||
| RU+ | p7 | ||||
| TU- | p2 | ||||
| TU+ | p1 | ||||
| Vout | Vcc, STBY | Vs | |||
| GND | GND | GND | |||
| p23 | PWMA | ||||
| AO1 | Lead+ | ||||
| AO2 | Lead- | ||||
| VMOT | X |
Video Demo
Alexa Code
Alexa Intent Code:
/* eslint-disable func-names */
/* eslint quote-props: ["error", "consistent"]*/
/**
* This sample demonstrates a simple skill built with the Amazon Alexa Skills
* nodejs skill development kit.
* This sample supports multiple lauguages. (en-US, en-GB, de-DE).
* The Intent Schema, Custom Slots and Sample Utterances for this skill, as well
* as testing instructions are located at https://github.com/alexa/skill-sample-nodejs-fact
**/
'use strict';
const http = require('http');
var stringify = require('querystring').stringify;
const Alexa = require('alexa-sdk');
//const APP_ID = undefined; // TODO replace with your app ID (OPTIONAL).
const serverResponses = {
'TurnOnFan' : '11',
'TurnOffFan' : '01',
'SpeedUp' : '11',
'SlowDown' : '10',
'EnterControlMode' : '20',
'ExitControlMode' : '10'
}
const alexaResponses = {
'TurnOnFan' : 'Turning On Fan',
'TurnOffFan' : 'Turning Off Fan',
'SpeedUp' : 'Turning Up Fan',
'SlowDown' : 'Turning Down Fan',
'EnterControlMode' : 'Entering Control Mode',
'ExitControlMode' : 'Exiting Control Mode'
};
//helper method to send data to server
var sendCommand = function (command, alexaContext) {
var data = stringify({ 'command' : command});
var options = {
//host: 'http://webhook.site/e9291d8d-4142-4e02-9c20-d12208762c49',
host: '104.236.83.105',
//port: '5000',
path: '/',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(data)
}
};
var callback = function(response) {
var str = ''
response.on('data', function (chunk) {
str += chunk;
});
response.on('end', function () {
console.log(str);
alexaContext.emit(':tell', alexaResponses[command]);
});
}
var req = http.request(options, callback);
req.on('error', function(e) {
alexaContext.emit("i could not connect to m bed server");
});
req.write(data);
req.end();
};
const handlers = {
'LaunchRequest': function () {
//this.emit('GetFact');
this.emit('TurnOnFan');
},
'TurnOnFan': function () {
sendCommand('TurnOnFan', this);
},
'TurnOffFan': function () {
sendCommand('TurnOffFan', this);
},
'SpeedUp': function () {
sendCommand('SpeedUp', this);
},
'SlowDown': function () {
sendCommand('SlowDown', this);
},
'EnterControlMode': function () {
sendCommand('EnterControlMode', this);
},
'ExitControlMode': function () {
sendCommand('ExitControlMode', this);
},
'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'));
*/
},
};
exports.handler = function (event, context) {
const alexa = Alexa.handler(event, context);
//alexa.APP_ID = APP_ID;
// To enable string internationalization (i18n) features, set a resources object.
//alexa.resources = languageStrings;
alexa.registerHandlers(handlers);
alexa.execute();
};
lambdafunction.txt
Open with Google Docs
Displaying lambdafunction.txt.
Mbed Code
Import programFinal_Project_Alvin_Clay
Alexa Smart Fan
Please log in to post comments.
