Animation with Arduino Controlled Servos


The servo from Amazon: https://amzn.to/2LFxlO7



#include <VarSpeedServo.h>
VarSpeedServo myservo;

void setup() {
  myservo.attach(9);
}

void loop()
{

  myservo.write(5, 50);
  delay(4000);

  myservo.write(100, 50);
  delay(4000);

}






#include <Servo.h>

Servo myservo;


void setup() {
  myservo.attach(9);
}

void loop() {
  int pos;



  for (pos = 90; pos >= 25; pos -= 1) {
    myservo.write(pos);
    delay(15);
  }

  delay(random(1000, 2000));
  for (pos = 25; pos <= 90; pos += 1) {

    myservo.write(pos);
    delay(15);
  }

  delay(random(1000, 2000));
  for (pos = 90; pos <= 110; pos += 1) {

    myservo.write(pos);
    delay(15);
  }
  delay(random(1000, 2000));
  for (pos = 110; pos >= 80; pos -= 1) {
    myservo.write(pos);
    delay(15);
  }
  delay(random(1000, 2000));
  for (pos = 80; pos <= 145; pos += 1) {

    myservo.write(pos);
    delay(15);
  }
  delay(random(1000, 2000));
  for (pos = 135; pos >= 90; pos -= 1) {
    myservo.write(pos);
    delay(15);
  }
  delay(random(1000, 2000));
  for (pos = 90; pos <= 135; pos += 1) {

    myservo.write(pos);
    delay(15);
  }
  delay(random(1000, 2000));
  for (pos = 135; pos >= 60; pos -= 1) {
    myservo.write(pos);
    delay(15);
  }
  delay(random(1000, 2000));
  for (pos = 60; pos <= 145; pos += 1) {

    myservo.write(pos);
    delay(15);
  }
  delay(random(1000, 2500));
  for (pos = 140; pos >= 90; pos -= 1) {
    myservo.write(pos);
    delay(15);
  } delay(random(1000, 2000));
}


#include <VarSpeedServo.h>
VarSpeedServo CharlieBrown;
VarSpeedServo Linus;
VarSpeedServo Lucy;
VarSpeedServo Sally;
VarSpeedServo Schroeder;
VarSpeedServo Franklin;
VarSpeedServo PigPen;
int outPin10 = 10;
int outPin11 = 11;
int counter1 = 0;
int counter2 = 0;
void setup() {
  counter1 = 0;
  counter2 = 0; 
  pinMode (outPin10, OUTPUT);
  pinMode (outPin11, OUTPUT);
  digitalWrite (outPin10, LOW);
  digitalWrite (outPin11, LOW); 
  Sally.attach(2);
  Linus.attach(3);
  CharlieBrown.attach(4);
  Lucy.attach(5);
  Schroeder.attach(6);
  Franklin.attach(7);
  PigPen.attach(8);
  delay(500);
  CharlieBrown.write(90, 50);
  Lucy.write(90, 50);
  Linus.write(90, 50);
  Sally.write(90, 50);
  Schroeder.write(90, 50);
  Franklin.write(90, 50);
  PigPen.write(90, 50); 
    delay(1000);
    digitalWrite (outPin10, HIGH); 
}
void loop()
{  
   
  Schroeder.write(70, 50);
  delay(300);
  CharlieBrown.write(40, 50);
  Lucy.write(130, 50);
  delay(300);
  Franklin.write(130, 50);
  PigPen.write(35, 50);
  delay(300);
  Schroeder.write(110, 50);
  Linus.write(120, 50);
  Sally.write(40, 50);
  delay(500);
  Linus.write(35, 50);
  CharlieBrown.write(160, 50, true);
  delay(200);
  CharlieBrown.write(random(20, 1600), 50);
  Franklin.write(random(60, 160), 50);
  Lucy.write(random(40, 160), 50);
  delay(300);
  Schroeder.write(random(40, 140), 50);
  Linus.write(random(40, 140), 50);
  Lucy.write(random(40, 140), 50);
  Sally.write(random(50, 150), 50);
  delay(200);
  PigPen.write(random(20, 120), 50);
  Schroeder.write(random(40, 140), 50);
  Sally.write(random(50, 150), 50);
  Franklin.write(random(60, 160), 50);
  delay(300);
  Linus.write(random(40, 140), 50);
  PigPen.write(random(20, 120), 50);
  CharlieBrown.write(random(20, 160), 50);
  delay(400);
  Schroeder.write(70, 50);
  delay(300);
  CharlieBrown.write(40, 50);
  Lucy.write(130, 50);
  delay(200);
  Franklin.write(130, 50);
  PigPen.write(35, 50);
  delay(200);
  Schroeder.write(110, 50);
  delay(300);
  Linus.write(120, 50);
  Sally.write(40, 50);
  delay(400);
  CharlieBrown.write(random(20, 1600), 50);
  Franklin.write(random(60, 160), 50);
  Lucy.write(random(40, 160), 50);
  delay(300);
  Schroeder.write(random(40, 140), 50);
  Linus.write(random(40, 140), 50);
  Lucy.write(random(40, 140), 50);
  Sally.write(random(50, 150), 50);
  delay(200);
  PigPen.write(random(20, 120), 50);
  Schroeder.write(random(40, 140), 50);
  Sally.write(random(50, 150), 50);
  Franklin.write(random(60, 160), 50);
  delay(300);
  Linus.write(random(40, 140), 50);
  PigPen.write(random(20, 120), 50);
  CharlieBrown.write(random(20, 160), 50);
  delay(500);
  Schroeder.write(70, 50, true);
  CharlieBrown.write(40, 50);
  Lucy.write(130, 50);
  delay(200);
  Franklin.write(130, 50);
  PigPen.write(35, 50);
  delay(300);
  Schroeder.write(110, 50, true);
  Linus.write(120, 50);
  Sally.write(40, 50);
  delay(1000);
  Linus.write(35, 50);
  CharlieBrown.write(160, 50, true);
  delay(200);
  Linus.write(90, 50);
  delay(400);
  if (counter2 <= 3) digitalWrite (outPin11, HIGH);
   if (counter2 >= 3) digitalWrite (outPin11, LOW); 
    
   delay(300);
    Lucy.write(20, 50);
    delay(200);
    CharlieBrown.write(20, 50);
    delay(200);
    Linus.write(20, 50);
    delay(200);
    Sally.write(25, 50);
    delay(200);
    Schroeder.write(20, 50);
    delay(200);
    Franklin.write(20, 50);
    delay(200);
    PigPen.write(20, 50); 
    delay(400);
     Lucy.write(90, 50);
     delay(200);
  CharlieBrown.write(90, 50);
  delay(200);
  Linus.write(90, 50);
  delay(200);
  Sally.write(90, 50);
  delay(200);
  Schroeder.write(90, 50);
  delay(200);
  Franklin.write(90, 50);
  delay(200);
  PigPen.write(90, 50);
  delay(400);
    PigPen.write(160, 50);
    delay(200);
    Franklin.write(160, 50);
    delay(200);
    Schroeder.write(160, 50);
    delay(200);
    Sally.write(170, 50);
    delay(200);
    Linus.write(160, 50);
    delay(200);
    CharlieBrown.write(160, 50);
    delay(200);
    Lucy.write(160, 50);
    delay(400);

    for (int i=0; i <= 3; i++){
      CharlieBrown.write(20, 50);
      Lucy.write(20, 50);
      Linus.write(20, 50);
      Sally.write(20, 50);
      Schroeder.write(20, 50);
      Franklin.write(20, 50);
      PigPen.write(20, 50);
      delay(1000);
      PigPen.write(160, 50);
      Franklin.write(160, 50);
      Schroeder.write(160, 50);
      Sally.write(160, 50);
      Linus.write(160, 50);
      CharlieBrown.write(160, 50);
      Lucy.write(160, 50);
      delay(1000);
      
    }
       

    counter2 = counter2 + 1; 
    if (counter2 >= 6)  counter2 = 0;

}



      The site owner is not and cannot be held liable for fire, electrical shock, property damage, bodily injury, loss of life, or accident of any kind caused by electrical circuits or any ideas, projects, techniques, or information contained on this site. The visitor assumes all risk and responsibility for any loss, injury, accident or damage arising from the use of information, ideas, techniques, projects, concepts, components, products, and circuits on this site.

      Please refer to hobby reference materials for correct and safe use information regarding these and all electronic circuits.  These diagrams are intended to explain how things were accomplished in theory, but it is the responsibility of the individual to locate precise information regarding electrical circuits, materials, ratings of components, etc.  Do not attempt these hobby projects, or any electrical project, if you don't have the necessary skills and experience.

[back to main page]