Badr M
Published © GPL3+

"Internet-Controlled" Nespresso Machine

Using a chatbot and a Nespresso machine to make coffee remotely.

IntermediateShowcase (no instructions)2 hours6,368
"Internet-Controlled" Nespresso Machine

Things used in this project

Hardware components

Servos (Tower Pro MG996R)
×1
Photon
Particle Photon
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×1

Story

Read more

Schematics

Architecture

High level architecture

Code

hook.io code

JavaScript
This is the hook used to trigger from API.io
module['exports'] = function coffeenator (hook) {
  var myResponse;
  var Particle = require('particle-api-js');
var particle = new Particle();
  
  function output(data) {
    hook.res.end(JSON.stringify(data, true, 2));
  }
  
  var token = 'PUT YOUR TOKEN HERE';


  
  
  
   console.log(hook.params.result.parameters.action + " coffee request recieved");
  
  
  if(hook.params.result.parameters.action=="warm")
  {
	warmCoffeeMachine();
   
  
  var fnPr = particle.callFunction({ deviceId: 'PUT YOUR DEVICE ID HERE', name: 'warmmachine', argument: 'D0:HIGH', auth: token });;
  
    fnPr.then(
      function(data) {
        console.log("success called warmcoffee succesfuly");
 //      output('Function called succesfully:', data);
        myResponse =new MyResponse("Warming coffee machine for you","Coffee Machine Being Warmed","Coffee Machine");
   	   hook.res.writeHead(200, {"Content-Type": "application/json"});
  
  		hook.res.end(JSON.stringify(myResponse, true, 2));
        
      }, function(err) {
        output('An error occurred:', err);
      });
    
    myResponse =new MyResponse("Warming coffee machine for you","Coffee Machine Being Warmed","Coffee Machine");
    
    
  }else if (hook.params.result.parameters.action=="make")
  {
    makeCoffeeMachine();
    
    var fnPr = particle.callFunction({ deviceId: 'PUT YOUR DEVICE ID HERE', name: 'makecoffee', argument: 'D0:HIGH', auth: token });;
  
    fnPr.then(
      function(data) {
                console.log("success called make coffee succesfuly");
     //  output('Function called succesfully:', data);
        myResponse =new MyResponse("Making coffee  for you","Coffee Being made ","Coffee Machine");
          hook.res.writeHead(200, {"Content-Type": "application/json"});
  
  			hook.res.end(JSON.stringify(myResponse, true, 2));
 
      }, function(err) {
        output('An error occurred:', err);
      });
    
        myResponse =new MyResponse("Making coffee  for you","Coffee Being made ","Coffee Machine");
        
 
  }
   
	console.log("****************end end end end end end ");
  

  
  function MyResponse(aSpeech,aDisplaytext,aSource){
    this.speech = aSpeech;
    this.displayText= aDisplaytext;
   
    this.source=aSource;
    
  }
  

};

function warmCoffeeMachine()
{
  
  console.log("machine is warming");
    
}
function makeCoffeeMachine()
{
  console.log("machine is making");
}

Firmware

Arduino
This firm ware receives commands such as warm or make coffee and moves the servo
int servoPin = D0;
Servo myServo;
int servoPos = 0;

int servoOn = D7;


void setup() {

pinMode(servoOn, OUTPUT);

myServo.attach( servoPin );

     Particle.function("press", press);
     Particle.function("servo", servoControl);
     Particle.function("makecoffee", makecoffee);
     
     Particle.function("warmmachine", warmmachine);
     
     
     digitalWrite(servoOn, LOW);

}

void loop() {

//   myServo.write( 100 );
//   delay(2000);
//   myServo.write( 120 );
//   delay(3500);
}


int servoControl(String command)
{
    
    
     digitalWrite(servoOn, HIGH);

    // Convert
   int newPos = command.toInt();
   // Make sure it is in the right range
   // And set the position
   servoPos = constrain( newPos, 0 , 180);

   // Set the servo
   myServo.write( servoPos );


 digitalWrite(servoOn, LOW);
   // done
   return 1;
}

int press(String command) {
 digitalWrite(servoOn, HIGH);
  myServo.write( 130 );
  delay(2000);
  myServo.write( 150 );
  delay(1500);
  myServo.write( 125 );
   delay(1000);
 digitalWrite(servoOn, LOW);
   return 1;
}


int  makecoffee(String command) {


     digitalWrite(servoOn, HIGH);

  myServo.write( 125 );
  delay(2000);
  myServo.write( 150 );
  delay(1500);
  myServo.write( 125 );
  
  delay(3000);
  
   myServo.write( 125 );
  delay(2000);
  myServo.write( 150 );
  delay(1500);
  myServo.write( 125 );
  delay(1000);
 digitalWrite(servoOn, LOW);
  
   return 1;
}


int  warmmachine(String command) {
    
     digitalWrite(servoOn, HIGH);

  myServo.write( 125 );
  delay(2000);
  myServo.write( 150 );
  delay(1500);
  myServo.write( 125 );
  
  delay(1000);
 digitalWrite(servoOn, LOW);
  
   return 1;
}

Credits

Badr M

Badr M

5 projects • 4 followers

Comments