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

IoT Drone - Part 1 - Motor Control
Intermediate
  • 1,294
  • 27

Work in progress

After flying a friends drone I was hooked. However, I wanted to build my own, so this is part one of my drone project - motor control.

Bike Swarm
Intermediate
  • 588
  • 13

Work in progress

Cyclists will be able to connect seamlessly to form a synchronized swarm of riders to reduce traffic congestion and improving safety.

Bike Swarm

Team Bright Water Bottle

Smart Maid
Intermediate
  • 1,269
  • 21

Full instructions

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

Smart Maid

Team Yosnalab

IoT Smart Desk Drawer with Amazon DRS
Intermediate
  • 432
  • 4

Never run out of office supplies again. PostIt notes, stamps, paperclips, tape and paper replenished from the cloud.

Home Theater Accent Lights
Intermediate
  • 277
  • 1

Full instructions

Particle Photon and SmartThings controlled WS2812B.

Christmas Gift Box
Intermediate
  • 3,366
  • 595

Full instructions

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

Add projectSign up / Login
Respect project