Yuchuan Shan – Skills Dev IV

Made by Yuchuaun Shan

Working with Outputs - Motors and Movement

Created: December 14th, 2021



    • For this project, I created a self-celebration tool with a servo motor and a switch button. When user switches on the tool, the servo will be activated and shows the message – "Great Job!"
Servo myServo;
int servoPin = A3;
int servoPos = 0;
int buttonPin = D3;
int buttonState;

void setup() {
    pinMode( buttonPin , INPUT_PULLUP); // sets pin as input

    //Register our Particle to control the servo
    Particle.function("servo", servoControl);
    // Keep a cloud variable for the current position
    Particle.variable(  "servoPos" , &servoPos , INT );


void loop() {
    int buttonState = digitalRead( buttonPin );
    if(buttonState == LOW){


// function that takes an integer to set servo position
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 , 100);
    // Set the servo
    myServo.write( servoPos );
    // done
    return 1;

Click to Expand
Skills Dev IV
Yu Chuan Shan - https://youtu.be/A4Adn0orfPs


This skills dev helped me to get familiar with using servo. One takeaway is that the servo moves rather fast, which serves the purpose of this tool. But if I need smoother movement in the future, I will probably need to write the servo position step by step with delays between the steps.