Isha Hans - Skills Dev 4

Made by ihans

get familiar with particle.function by using a servo or solenoid

Created: November 30th, 2021

0

Goal

    • Taking inspiration from Google's Paper signal experiment, use a servo motor to create an ambient movement of the servo motor. 
0

Process

  • Exercise 1: Learning how to work with servo motor and use particle.function, particle.variable
  • Exercise 2: Learning how to control the speed at which the servo motor moves.

0
// myServoName.write(60);
int servoPin = A1;
Servo myservo;
int servoPosition = 0;


void setup() {
    myservo.attach(A1);
    Particle.function("servo", servoControl);
    Particle.variable( "servoPosition" , &servoPosition , INT );
}

void loop() {
    
}

int servoControl(String move){
    int newPosition = move.toInt();
    servoPosition = constrain( newPosition, 10 , 150);
    myservo.write( servoPosition );
    return 1;
}
Click to Expand
0
Designing for IoT 4.1: Controlling servo motor through particle console
Isha Hans - https://youtu.be/F_mdClFN3Yw
0
int servoPin = A1;
Servo myservo;
int servoPosition = 0;
// int servospeed = 200;

void setup() {
    myservo.attach(A1);
    // Particle.function("servo", servoControl);
    // Particle.variable( "servoPosition" , &servoPosition , INT );
}

void loop() {
 for (servoPosition = 0; servoPosition<90; servoPosition++){
        myservo.write( servoPosition );
        delay (150);
    }
for (servoPosition = 00; servoPosition>0; servoPosition--){
        myservo.write( servoPosition );
        delay (150);
    }    

}
Click to Expand
0
Designing for IoT 4.2: Controlling the speed of servo motor
Isha Hans - https://youtu.be/PruTOPNKoMw
0

Reflection

If I had more time, I would have liked to combine the ambient motion of the servo with particle.function or IFTT so that I can trigger it to start instead of it being on as soon as the particle is connected to power. The reason I haven't been able to get around to this is because, for using the particle.function the code is written as a separate function after the void loop whereas to control the speed of the servo I've used the void loop. I'm not fully sure how to write the syntax to do both simultaneously. 

x
Share this Project

Courses

About

get familiar with particle.function by using a servo or solenoid