Skill Dev IV - Kenny Harsono

Made by kharsono

Implementing motors in Particle

Created: December 3rd, 2021

0

Outcome

  • Using motors, particularly servo motors, with Particle & IoT application.
  • Implementing IFTTT for reminding people that it's trash day!
  • Below is the final circuit using a bigger servo motor (smaller has vibrations).
0

Process

Code & video are shown below to show how servo motors remind user to take out trash on particular time/day of the week.

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

void setup() {
    myServo.attach(A3);
    myServo.write(90);
    
    //Register our Particle to control the servo
    Particle.function("servo", servoControl);
    Particle.function("trashbin", binControl);
   
   // Keep a cloud variable for the current position
    Particle.variable(  "servoPos" , &servoPos , INT );
}

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;
}

int binControl(String args) {
    unsigned long now = millis();
    unsigned long initialized = millis();  
    
    while ((now - initialized) < 3600000) {
        myServo.write(90);
        delay(1000);
        myServo.write(5);
        delay(1500);
        now = millis();
    }
    
    return 1;
}

void loop() {
    
}
Click to Expand
0
0

Reflection

Lessons learnt:

                        • Servo motors are very easy to wire, and easy to code up in terms of position control.
                        • Small servo motors induce a lot of vibration problems & fragile.
                        • Bigger servo motors (used above) utilizes 5V power rather than 3.3V.
                        • IFTTT has a little lag/error not reading the right trigger.

    • Next Time:
                            • Knowing which servo motor to use right away for certain purpose (actuating wood - might be too heavy for small servo motor) is ideal.
                            • Knowing where to get servo motor replacements is crucial.

x