Brian, Tiffany, Tianyi

Made by Tiffany Han, Brian Hernandez and Tianyi He

Creating a paired particle device that spins a servo motor the same degrees when a button is pushed

Created: December 5th, 2023

0

Outcome

    • For this project we wanted to created a pair of devices such that if one person pushes a button it will be synced to another person's particle console, making both people's servo motor spin the same number of degrees. 
    • Listed below are first person's code, second person's code, and a video.

0
int servoPin = A3;
Servo myServo;
int servoPos = 0;

int buttonPin = D3;

void setup() {
  myServo.attach( servoPin );
  Particle.function("servo", servoControl);
  Particle.variable(  "servoPos" , &servoPos , INT );
  pinMode( buttonPin , INPUT_PULLUP); // sets pin as input
  myServo.write( 0 );
}

void loop() {
    int buttonState = digitalRead( buttonPin );
    if( buttonState == LOW )
  {
    // turn the LED On
   Particle.publish( "buttonpushed");
   String degree = "90";
   int pos = degree.toInt();
   servoPos = constrain( pos, 0 , 180);
   myServo.write(pos);
   delay( 5000 );
   }

}


int servoControl(String command)
{
    // 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 );
  
  // done
  return 1;
}
Click to Expand
0
IMG 9359
Tiff467 - https://youtu.be/OZRr_hikufM
0

Process

We first integrated a button into one person's circuit. Then we tried creating and publishing a button pushed event to the particle cloud. After that is working, we worked on creating a webhook that allows one device to communicate to another. Then, we tested the webhook. We realized we should reset the servo motor degree before every try otherwise it does not move. After fixing that we have it working. 

x
Share this Project

Courses

48-675 Designing for the Internet of Things

· 11 members

A hands-on introductory course exploring the Internet of Things and connected product experiences.


About

Creating a paired particle device that spins a servo motor the same degrees when a button is pushed