Things used in this project

Hardware components:
Servo (generic)
×1
Photon new
Particle Photon
×1
Fairchild semiconductor pn2222abu. image
General Purpose Transistor NPN
×1

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

Particle Photon Doorbell
Intermediate
  • 621
  • 9

Full instructions

Get notified when the doorbell is pressed for about 1/6 the price of the RING doorbell!

DIYSprinkler Controller
Intermediate
  • 422
  • 3

Full instructions

Make your own sprinkler controller and I have the software to control it. Must have an existing sprinkler system or you could make your own

DIYSprinkler Controller

Team dougefresh89

Magic Eyeball
Intermediate
  • 781
  • 7

Full instructions

It's like a magic eight ball. But with Alexa, and two eyeballs.

Spoil your Valentine with Particle + Spoil + AWS
Intermediate
  • 478
  • 3

Full instructions

Instead of giving a box of chocolates this Valentines Day, keep the chocolates. Lets give a smart self-gifting box instead!

Pebble + Photon = IoT Watch Switch
Intermediate
  • 50
  • 1

Full instructions

When I arrive in my house I switch on the light with my Pebble Watch! The procedure to make this is very simple.

Automated Cat Feeder with Particle Photon
Intermediate
  • 1,544
  • 19

Work in progress

The goal was to make it possible to feed my cats when I'm not at home.

Add projectSign up / Login
Respect project