Servo Tutorial

Luis Carbajal

Circuit #4A: Servo Position

Ryan Ferguson

#include <Servo.h>


Servo myservo;  // create servo object to control a servo

// twelve servo objects can be created on most boards


int pos = 0;    // variable to store the servo position


void setup() {

  myservo.attach(11);  // attaches the servo on pin 9 to the servo object

}


void loop() {


    myservo.write(45);              // tell servo to go to position 45 Degrees


  }

Circuit #4B: Servo Sweep

Ryan Ferguson

#include <Servo.h>


Servo myservo;  // create servo object to control a servo

// twelve servo objects can be created on most boards


int pos = 0;    // variable to store the servo position


void setup() {

  myservo.attach(11);  // attaches the servo on pin 9 to the servo object

}


void loop() {

  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees

    // in steps of 1 degree

    myservo.write(pos);              // tell servo to go to position in variable 'pos'

    delay(15);                       // waits 15ms for the servo to reach the position

  }

  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees

    myservo.write(pos);              // tell servo to go to position in variable 'pos'

    delay(15);                       // waits 15ms for the servo to reach the position

  }

}

Circuit #5: Potentiometer & Servo

Ryan Ferguson

#include <Servo.h>


Servo myservo;  // create servo object to control a servo

// twelve servo objects can be created on most boards


int pos = 0;    // variable to store the servo position


void setup() {

  myservo.attach(11);  // attaches the servo on pin 9 to the servo object

  // initialize serial communication at 9600 bits per second:


  Serial.begin(9600);

}


void loop() {


  // read the input on analog pin 0:

  int sensorValue = analogRead(A0);


  //remap sensorValue from 0-1024 to 0-255

  pos = map(sensorValue, 0, 1024, 0, 179);


  // tell servo to go to position in variable 'pos'

  myservo.write(pos);


  // print the value of variable "pos"

  Serial.println(pos);

}

Servo Motor

Chris Perry

Overview

We will be combining our fish mouths with the Arduino to create a robotic fish for this activity!

Part 1: Materials

In addition to your Arduino materials and fish mouth, you will need:

  1. Hot glue gun
  2. Cutting Mat
  3. Servo Motor
  4. Jumper Wires
  5. Floral Wire
  6. Pencil/pen