fmattiussi
Published © CERN-OHL

Arduino LEG

I built a leg with Arduino and with ice cream sticks!

BeginnerShowcase (no instructions)2,371
Arduino LEG

Things used in this project

Hardware components

Servos (Tower Pro MG996R)
×4
Ice Cream Sticks
A lot of sticks
×1
Arduino UNO
Arduino UNO
×1

Story

Read more

Code

The Code

C/C++
#include <Servo.h>

Servo S1;
Servo S2;
Servo S3;
Servo S4;

int baud = 9600;
int ledpin = 7;

void setup() {
 Serial.begin(baud);

 S1.attach(3);
 S2.attach(5);
 S3.attach(6);
 S4.attach(9);

 pinMode(ledpin, OUTPUT);

     for (int pos = 0; pos <= 30; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    S1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (int pos = 30; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
   S1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }              
  for (int pos = 0; pos <= 30; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    S2.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (int pos = 30; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
   S2.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }              
  for (int pos = 0; pos <= 30; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    S3.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (int pos = 30; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
   S3.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }              
  for (int pos = 0; pos <= 30; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    S4.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (int pos = 30; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
   S4.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }  
}

void loop() {

    //in this code the movments are looped for 1 time
}

Credits

fmattiussi
5 projects • 2 followers

Comments