Satish krishnanArivazhagan.GSuhas.SArokiaselvam
Published © MIT

Smart Maid

Hack your existing iRobot Create with Particle and control it through Alexa.

IntermediateFull instructions provided4 hours2,424
Smart Maid

Things used in this project

Hardware components

Amazon Echo
Amazon Alexa Amazon Echo
×1
Photon
Particle Photon
×1
iRobot Create 2
×1

Software apps and online services

Alexa Skills Kit
Amazon Alexa Alexa Skills Kit
Particle cloud API
AWS Lambda
Amazon Web Services AWS Lambda

Story

Read more

Schematics

Block diagram

Code

Lambda Code

JavaScript
Node.js code
/**
 * App ID for the skill
 */
//var APP_ID = "amzn1.ask.skill.3ce2c39d-7a38-4873-ae14-d91330631fc3"; //replace with "amzn1.echo-sdk-ams.app.c4cbe4a8-2f9c-4386-a274-0a595b7b3c54";
var APP_ID = "amzn1.ask.skill.d530a113-a542-45de-aa5c-e5a43d31eaf1";
/**
 * The AlexaSkill prototype and helper functions
 */
var http = require('https');
var AlexaSkill = require('./AlexaSkill');
/*
 *
 * Particle is a child of AlexaSkill.
 *
 */
var Particle = function () {
    AlexaSkill.call(this, APP_ID);
};
// Extend AlexaSkill
Particle.prototype = Object.create(AlexaSkill.prototype);
Particle.prototype.constructor = Particle;
Particle.prototype.eventHandlers.onSessionStarted = function (sessionStartedRequest, session) {
    console.log("Particle onSessionStarted requestId: " + sessionStartedRequest.requestId + ", sessionId: " + session.sessionId);
};
Particle.prototype.eventHandlers.onLaunch = function (launchRequest, session, response) {
    console.log("Particle onLaunch requestId: " + launchRequest.requestId + ", sessionId: " + session.sessionId);
    var speechOutput = "Hi," + " I am i Robot create" + "Tell me what to do? ";
    response.ask(speechOutput);
};
Particle.prototype.eventHandlers.onSessionEnded = function (sessionEndedRequest, session) {
    console.log("Particle onSessionEnded requestId: " + sessionEndedRequest.requestId + ", sessionId: " + session.sessionId);
};
Particle.prototype.intentHandlers = {
    // register custom intent handlers
    ParticleIntent: function (intent, session, response) {
        var sensorSlot = intent.slots.sensor;
        var lightSlot = intent.slots.light;
        var onoffSlot = intent.slots.onoff;
        var sensor = sensorSlot ? intent.slots.sensor.value : "";
        var light = lightSlot ? intent.slots.light.value : "";
        var onoff = onoffSlot ? intent.slots.onoff.value : "off";
        var speakText = "";
        console.log("Sensor = " + sensor);
        console.log("Light = " + light);
        console.log("OnOff = " + onoff);
        var op = "";
        var pin = "D0";
        var pinvalue = "";
        // Replace these with action device id and access token
        var deviceid = "36003c000347343339373536";
        var accessToken = "8fa8860eb069d5e519a51312df8d1ad9e59b49ea";
        var sparkHst = "api.particle.io";
        console.log("Host = " + sparkHst);
        // User is asking to turn on/off actions
         if(pin.length > 0){
            if(onoff == "clean"){
                pinvalue = "HIGH";
            }
            else if(onoff == "stop"){
                pinvalue = "LOW";
            }
            else if(onoff == "dock"){
                pinvalue = "HOME";
            }
            else if(onoff == "song"){
                pinvalue = "SONG";
            }
            else if(onoff == "fanon"){
                pinvalue = "VACON";
            }
            else if(onoff == "fanoff"){
                pinvalue = "VACOFF";
            }
            else if(onoff == "blink"){
                pinvalue = "BLINK";
            }
            
            var sparkPath = "/v1/devices/" + deviceid + "/ctrlled";
            console.log("Path = " + sparkPath);
            var args = pin + "," + pinvalue;
            makeParticleRequest(sparkHst, sparkPath, args, accessToken, function(resp){
                var json = JSON.parse(resp);
                console.log("Temperature: " + json.return_value);
                response.tellWithCard("OK, " + onoff, "Particle", "Particle!");
                //response.tellWithCard("OK, "+ "  turned " + onoff, "Particle", "Particle!");
                //response.ask("Continue?");
            });
        }
        else{
            response.tell("Sorry, I could not understand what you said");
        }
    },
    HelpIntent: function (intent, session, response) {
        response.ask("You can ask me to do your cammand actions" + " your command like clean , home, stop ,play song");
    }
};
// Create the handler that responds to the Alexa Request.
exports.handler = function (event, context) {
    // Create an instance of the Particle skill. 
    var particleSkill = new Particle();
    particleSkill.execute(event, context);
};
function makeParticleRequest(hname, urlPath, args, accessToken, callback){
    // Particle API parameters
    var options = {
        hostname: hname,
        port: 443,
        path: urlPath,
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Accept': '*.*'
        }
    }
    var postData = "access_token=" + accessToken + "&" + "args=" + args;
    console.log("Post Data: " + postData);
    // Call Particle API
    var req = http.request(options, function(res) {
        console.log('STATUS: ' + res.statusCode);
        console.log('HEADERS: ' + JSON.stringify(res.headers));
        var body = "";
        res.setEncoding('utf8');
        res.on('data', function (chunk) {
            console.log('BODY: ' + chunk);
            body += chunk;
        });
        res.on('end', function () {
            callback(body);
        });
    });
/*  req.on('error', function(e) {
        //console.log('problem with request: ' + e.message);
    });*/
    // write data to request body
    req.write(postData);
    req.end();
}

Particle code

Arduino
particle.ino code
int ddPin = D0;                                      // ddPin used to communicate over serial with Roomba
int ledPin = D7; 
void setup() {
  //Serial.begin(57600);
  //Serial.println("ParticleExample started.");
  
  pinMode(ddPin,  OUTPUT);                          // sets the pins as output
  pinMode(ledPin, OUTPUT);                          // sets the pins as output
  Serial1.begin(115200);
  Serial.begin(57600);
digitalWrite(ledPin, HIGH);                       // say we're alive
Particle.function("ctrlled",myFunction);
  
  // wake up the robot
  digitalWrite(ddPin, HIGH);                        // Make sure the pin line is high to start
  delay(100);
  digitalWrite(ddPin, LOW);                         // 500ms LOW signal wakes up the robot
  delay(500);
  digitalWrite(ddPin, HIGH);                        // Send it back HIGH once the robot is awake
  delay(2000);
  
  // Get the Roomba into control mode 
  Serial1.write(128);                               // Passive mode
  delay(150);
  Serial1.write(131);                               // Safe mode
  delay(150);
//  Serial1.write(132);                               // Full Control mode
//  delay(150);
  digitalWrite(ledPin, LOW);  
  delay(300);// Setup is complete when the D7 user LED goes out
  delay(5000);
}
void loop() {
  // put your main code here, to run repeatedly:
}
int myFunction(String command) {
    Serial.println("myFunction called.");
   int pos = command.indexOf(',');
    
    if(-1 == pos){
        return -1;
    }
    
    String strPin = command.substring(0, pos);
    String strValue = command.substring(pos + 1);
    if(strValue.equalsIgnoreCase("HIGH")){
            run();
            return 1;
    }
    if(strValue.equalsIgnoreCase("LOW")){
            stop();
            return 1;
    }
    if(strValue.equalsIgnoreCase("HOME")){
            goHome();
            return 1;
    }
    if(strValue.equalsIgnoreCase("SONG")){
            playSong();
            return 1;
    }
  if(strValue.equalsIgnoreCase("VACON")){
            vacuumOn();
            return 1;
    }
    if(strValue.equalsIgnoreCase("VACOFF")){
            vacuumOff();
            return 1;
    }
    if(strValue.equalsIgnoreCase("BLINK")){
            vibgyor();
            return 1;
    }
    // We don't need to return anything.
    // Just return an easy to recognize number for testing
   return 123;   
}
void run(){
            delay(1);
            Serial1.write(135);
            delay(20000);
}
void goHome() {                                     // Sends the Roomba back to it's charging base
  Serial1.write(135);                               // Starts a cleaning cycle, so command 143 can be initiated
  delay(5000);
  Serial1.write(143);                               // Sends the Roomba home to charge
}
void stop() {
Serial1.write(135);
delay(5000);
}
void playSong() {                                   // Makes the Roomba play a little ditty
  Serial1.write(140);                               // Define a new song
  Serial1.write(0);                                 // Write to song slot #0
  Serial1.write(8);                                 // 8 notes long
  Serial1.write(60);                                // Everything below defines the C Major scale 
  Serial1.write(32); 
  Serial1.write(62);
  Serial1.write(32);
  Serial1.write(64);
  Serial1.write(32);
  Serial1.write(65);
  Serial1.write(32);
  Serial1.write(67);
  Serial1.write(32);
  Serial1.write(69);
  Serial1.write(32);
  Serial1.write(71);
  Serial1.write(32);
  Serial1.write(72);
  Serial1.write(32);
 
  Serial1.write(141);                               // Play a song
  Serial1.write(0);                                  // Play song slot #0
}
void vacuumOn() {                                   // Turns on the vacuum
  Serial1.write(138);
  Serial1.write(7);
}
void vacuumOff() {                                  // Turns off the vacuum
  Serial1.write(138);
  Serial1.write(0);
}
void vibgyor() {                                    // Makes the main LED behind the power button on the Roomba pulse from Green to Red
Serial1.write(139);
for (int i=0;i<255;i++){ 
  Serial1.write(139);                             // LED seiral command
  Serial1.write(0);                               // We don't want any of the other LEDs
  Serial1.write(i);                               // Color dependent on i
  Serial1.write(255);                             // FULL INTENSITY!
  delay(5);                                       // Wait between cycles so the transition is visible
  }
for (int i=0;i<255;i++){ 
  Serial1.write(139);
  Serial1.write(0);
  Serial1.write(i);
  Serial1.write(255);
  delay(5);
  }
for (int i=0;i<255;i++){ 
  Serial1.write(139);
  Serial1.write(0);
  Serial1.write(i);
  Serial1.write(255);
  delay(5);
  }
for (int i=0;i<255;i++){ 
  Serial1.write(139);
  Serial1.write(0);
  Serial1.write(i);
  Serial1.write(255);
  delay(5);
  }
Serial1.write(139);
Serial1.write(0);
Serial1.write(0);
Serial1.write(0);
}

Alexa intent schema

JSON
{
"intents": [
  {
    "intent": "ParticleIntent",
    "slots": [
  {
        "name": "sensor",
        "type": "LITERAL"
      },
      {
        "name": "light",
        "type": "LITERAL"
      },
      {
        "name": "onoff",
        "type": "LITERAL"
      }
    ]
  },
  {
    "intent": "HelpIntent",
    "slots": []
  }
]
}

Sample utterance

Typescript
Sample utterance for refernce
ParticleIntent turn {clean|onoff} {action|light} 
ParticleIntent turn {stop|onoff} {action|light} 
ParticleIntent turn {home|onoff} {action|light} 
ParticleIntent turn {song|onoff} {action|light}
ParticleIntent turn {blink|onoff} {action|light}
ParticleIntent turn {fanon|onoff} {action|light}
ParticleIntent turn {fanoff|onoff} {action|light}

ParticleIntent do {clean|onoff} {action|light} 
ParticleIntent do {stop|onoff} {action|light} 
ParticleIntent do {home|onoff} {action|light} 
ParticleIntent do {song|onoff} {action|light}
ParticleIntent do {blink|onoff} {action|light}
ParticleIntent do {fanon|onoff} {action|light}
ParticleIntent do {fanoff|onoff} {action|light}

ParticleIntent {stop|onoff} {action|light}
ParticleIntent {clean|onoff} {action|light}
ParticleIntent {clean|onoff} my floor
ParticleIntent {stop|onoff}
ParticleIntent play {song|onoff}
ParticleIntent go to {dock|onoff}
ParticleIntent {blink|onoff} led

ParticleIntent {temperature|sensor}
ParticleIntent {humidity|sensor}
ParticleIntent {forward motor one|light} 
ParticleIntent {reverse motor one|light} 
ParticleIntent {forward motor two|light} 
ParticleIntent {reverse motor two|light} 
ParticleIntent {forward motor three|light} 
ParticleIntent {reverse motor three|light} 
ParticleIntent {forward motor four|light} 
ParticleIntent {reverse motor four|light}


HelpIntent help
HelpIntent help me
HelpIntent what can I ask you
HelpIntent get help
HelpIntent to help
HelpIntent to help me
HelpIntent what can you do
HelpIntent what do you do
HelpIntent how do I use you
HelpIntent how can I use you
HelpIntent what can you tell me

Credits

Satish krishnan

Satish krishnan

1 project • 0 followers
Contact
Arivazhagan.G

Arivazhagan.G

1 project • 0 followers
Contact
Suhas.S

Suhas.S

1 project • 0 followers
Contact
Arokiaselvam

Arokiaselvam

1 project • 0 followers
Contact

Comments

Add projectSign up / Login