Shama_Motor

Made by Shama Patwardhan

To use a servo motor

Created: November 21st, 2024

0

Intention

The intention was to experiment and learn how a servo motor works. 

0

Process

When I first attempted to get the motor working, I encountered some difficulties. Despite my efforts, the motor wouldn't respond as expected. After troubleshooting for a while, I discovered that the issue was due to a loose connection. Once I secured the connection properly, the motor started working perfectly, confirming that my code was correct all along.

0

Outcome

I added a small arrow to indicate the direction in which the motor moved the arm. While this was a helpful addition, I realized that I could have taken a more elaborate approach by experimenting with various possibilities and enhancements.

0

Reflection

I learned that sometimes the solution is simpler than you think! I spent a lot of time questioning what was going wrong, but in the end, I just needed to reattach the jumper wires to get the correct output.

0
int servoPin = A3;
Servo myServo;
int servoPos = 0;
void setup() {
  // attaches the servo on the A3 pin to the servo object
  myServo.attach( A3 );
   //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()
{
  delay(100);
}
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
x