Maksim MitinIsaac Gibbs
Published

Fishy Feeder

Photon controlled servo motor that is used to remotely give my fishes a small snack.

BeginnerWork in progress2 hours1,355
Fishy Feeder

Things used in this project

Hardware components

Photon
Particle Photon
×1
Servos (Tower Pro MG996R)
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1

Story

Read more

Schematics

Circuit schematic

This is a schematic from the guide that we used found on learn.sparkfun.com

Code

Feed Fishies

Arduino
Tells the servo to find its true position and then a button tells it to rotate 180 degrees and then back to its original position. There are variables that control the speed and the length of the rotation.
Servo myservo;// create servo object using the built-in Particle Servo Library

int button = D1;    //declare variable for button
int servoPin = D0;  //declare variable for servo
int pos = 0;        //variable to keep track of the servo's position
bool flag = 1;      //variable to keep track of the button presses

// This routine runs only once upon reset
void setup()
{
  Serial.begin(9600);//Start the Serial port @ 9600 baud

  pinMode(button, INPUT_PULLUP);   // sets button pin as input with internal pullup resistor


  myservo.attach(servoPin);  //Initialize the servo attached to pin D0
  myservo.write(180);        //set servo to furthest position
  delay(500);                //delay to give the servo time to move to its position
  myservo.detach();          //detach the servo to prevent it from jittering

}

// This routine loops forever
void loop()
{
    if(digitalRead(button) == LOW) //if a button press has been detected...
    {
      //This is known a s state machine.
      //It will move the servo to the opposite end from where it's set currently
      if(flag == 1)
        pos = 0;
      if(flag == 0)
        pos = 180;

      myservo.attach(servoPin);
      myservo.write(pos);
      delay(500);           //debounce and give servo time to move
      myservo.detach();

      flag = !flag;         //set flag to the opposite of what it's currently set to
      Serial.println(pos);  //prints to the serial port to keep track of the position
    }

}

Credits

Maksim Mitin

Maksim Mitin

1 project • 0 followers
My name is Maks Mitin, i am a mechanical engineering student at UNCC.
Isaac Gibbs

Isaac Gibbs

1 project • 0 followers
Studying Mechanical Engineering

Comments

Add projectSign up / Login