Things used in this project

Schematics

Architecture
High level architecture
Screen shot 2016 12 24 at 12 27 08 am adcpjhby83 k3kpmwldh8

Code

hook.io codeJavaScript
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");
}
FirmwareArduino
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

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,535
  • 7

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,633
  • 595

Full instructions

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

Carbon Fiber Vacuum Chamber
Intermediate
  • 2,905
  • 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
  • 841
  • 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,044
  • 67

Full instructions

A whimsical weather clock powered by Particle and forecast.io

Garage Door Opener with Blynk
Intermediate
  • 367
  • 2

Open, close and monitor a garage door opener with a smart phone using a Particle Photon and the Blynk application.

Add projectSign up / Login