Components and supplies
Arduino UNO
Tools and machines
Soldering iron (generic)
BRAIN aka DIMAAG...
Multitool, Screwdriver
Hot glue gun (generic)
Solder Wire, Lead Free
Project description
Code
servo_arm_code.ino
c_cpp
Paste it, arrange the hardware according to schematics and then u can see the 1032498274TH wonder of world
1// it is pretty inefficient, but gets the job done, I challenge you to make it more efficient! 2 3//*IMPORTANT CHANGES IN VERSION 2: LEDs 4 and 5 have been moved to pins 7 and 8 respectively; Buttons 1 and 2 have been moved to pins 12 and 13 respectively. This is to make wiring easier. 4 5#include <Servo.h> 6 7Servo servo1; //Servos 8Servo servo2; 9Servo servo3; 10 11const int LED1 = 2; //LEDs 12const int LED2 = 3; 13const int LED3 = 4; 14const int LED4 = 7; 15const int LED5 = 8; 16 17const int button1 = 12; //Buttons 18const int button2 = 13; 19 20int button1Presses = 0; //Button values 21boolean button2Pressed = false; 22 23const int pot1 = A0; //Potentimeters 24const int pot2 = A1; 25const int pot3 = A2; 26 27int pot1Val; //Potentimeter values 28int pot2Val; 29int pot3Val; 30int pot1Angle; 31int pot2Angle; 32int pot3Angle; 33 34int servo1PosSaves[] = {1,1,1,1,1}; //position saves 35int servo2PosSaves[] = {1,1,1,1,1}; 36int servo3PosSaves[] = {1,1,1,1,1}; 37 38void setup() { 39 servo1.attach(5); // Set up everything and will run once; attach servos and define the pin modes 40 servo2.attach(6); 41 servo3.attach(9); 42 43 pinMode(LED1, OUTPUT); 44 pinMode(LED2, OUTPUT); 45 pinMode(LED3, OUTPUT); 46 pinMode(LED4, OUTPUT); 47 pinMode(LED5, OUTPUT); 48 pinMode(button1, INPUT); 49 pinMode(button2, INPUT); 50 51 Serial.begin(9600); 52} 53 54void loop() { 55 // put your main code here, to run repeatedly: 56 pot1Val = analogRead(pot1); // This will read the values from the potentimeters and store it... 57 pot1Angle = map(pot1Val, 0, 1023, 0, 179); // ... and this will map the values from the potentiometers to values the servos can use and store it for later use 58 pot2Val = analogRead(pot2); 59 pot2Angle = map(pot2Val, 0, 1023, 0, 179); 60 pot3Val = analogRead(pot3); 61 pot3Angle = map(pot3Val, 0, 1023, 0, 179); 62 63 servo1.write(pot1Angle); // These will make the servos move to the mapped angles 64 servo2.write(pot2Angle); 65 servo3.write(pot3Angle); 66 67 if(digitalRead(button1) == HIGH){ // This will check how many times button1 is pressed and save the positions to an array depending on how many times it is pressed; switch/case works like a if statement 68 button1Presses++; 69 switch(button1Presses){ 70 case 1: 71 servo1PosSaves[0] = pot1Angle; 72 servo2PosSaves[0] = pot2Angle; 73 servo3PosSaves[0] = pot3Angle; 74 digitalWrite(LED1, HIGH); 75 Serial.println("Pos 1 Saved"); 76 break; 77 case 2: 78 servo1PosSaves[1] = pot1Angle; 79 servo2PosSaves[1] = pot2Angle; 80 servo3PosSaves[1] = pot3Angle; 81 digitalWrite(LED2, HIGH); 82 Serial.println("Pos 2 Saved"); 83 break; 84 case 3: 85 servo1PosSaves[2] = pot1Angle; 86 servo2PosSaves[2] = pot2Angle; 87 servo3PosSaves[2] = pot3Angle; 88 digitalWrite(LED3, HIGH); 89 Serial.println("Pos 3 Saved"); 90 break; 91 case 4: 92 servo1PosSaves[3] = pot1Angle; 93 servo2PosSaves[3] = pot2Angle; 94 servo3PosSaves[3] = pot3Angle; 95 digitalWrite(LED4, HIGH); 96 Serial.println("Pos 4 Saved"); 97 break; 98 case 5: 99 servo1PosSaves[4] = pot1Angle; 100 servo2PosSaves[4] = pot2Angle; 101 servo3PosSaves[4] = pot3Angle; 102 digitalWrite(LED5, HIGH); 103 Serial.println("Pos 5 Saved"); 104 break; 105 } 106 } 107 108 if(digitalRead(button2) == HIGH){ // Pretty self-explnatory here 109 button2Pressed = true; 110 } 111 112 if(button2Pressed){ // if the boolean button2Press is true, then the servos will run though all their saved positions 113 for(int i = 0; i < 5; i++){ 114 servo1.write(servo1PosSaves[i]); 115 servo2.write(servo2PosSaves[i]); 116 servo3.write(servo3PosSaves[i]); 117 Serial.println(" potentimeter Angles: "); 118 Serial.println(servo1PosSaves[i]); 119 Serial.println(servo2PosSaves[i]); 120 Serial.println(servo3PosSaves[i]); 121 delay(1050); 122 } 123 } 124 delay(300); 125}
servo_arm_code.ino
c_cpp
Paste it, arrange the hardware according to schematics and then u can see the 1032498274TH wonder of world
1// it is pretty inefficient, but gets the job done, I challenge you to make it more efficient! 2 3//*IMPORTANT CHANGES IN VERSION 2: LEDs 4 and 5 have been moved to pins 7 and 8 respectively; Buttons 1 and 2 have been moved to pins 12 and 13 respectively. This is to make wiring easier. 4 5#include <Servo.h> 6 7Servo servo1; //Servos 8Servo servo2; 9Servo servo3; 10 11const int LED1 = 2; //LEDs 12const int LED2 = 3; 13const int LED3 = 4; 14const int LED4 = 7; 15const int LED5 = 8; 16 17const int button1 = 12; //Buttons 18const int button2 = 13; 19 20int button1Presses = 0; //Button values 21boolean button2Pressed = false; 22 23const int pot1 = A0; //Potentimeters 24const int pot2 = A1; 25const int pot3 = A2; 26 27int pot1Val; //Potentimeter values 28int pot2Val; 29int pot3Val; 30int pot1Angle; 31int pot2Angle; 32int pot3Angle; 33 34int servo1PosSaves[] = {1,1,1,1,1}; //position saves 35int servo2PosSaves[] = {1,1,1,1,1}; 36int servo3PosSaves[] = {1,1,1,1,1}; 37 38void setup() { 39 servo1.attach(5); // Set up everything and will run once; attach servos and define the pin modes 40 servo2.attach(6); 41 servo3.attach(9); 42 43 pinMode(LED1, OUTPUT); 44 pinMode(LED2, OUTPUT); 45 pinMode(LED3, OUTPUT); 46 pinMode(LED4, OUTPUT); 47 pinMode(LED5, OUTPUT); 48 pinMode(button1, INPUT); 49 pinMode(button2, INPUT); 50 51 Serial.begin(9600); 52} 53 54void loop() { 55 // put your main code here, to run repeatedly: 56 pot1Val = analogRead(pot1); // This will read the values from the potentimeters and store it... 57 pot1Angle = map(pot1Val, 0, 1023, 0, 179); // ... and this will map the values from the potentiometers to values the servos can use and store it for later use 58 pot2Val = analogRead(pot2); 59 pot2Angle = map(pot2Val, 0, 1023, 0, 179); 60 pot3Val = analogRead(pot3); 61 pot3Angle = map(pot3Val, 0, 1023, 0, 179); 62 63 servo1.write(pot1Angle); // These will make the servos move to the mapped angles 64 servo2.write(pot2Angle); 65 servo3.write(pot3Angle); 66 67 if(digitalRead(button1) == HIGH){ // This will check how many times button1 is pressed and save the positions to an array depending on how many times it is pressed; switch/case works like a if statement 68 button1Presses++; 69 switch(button1Presses){ 70 case 1: 71 servo1PosSaves[0] = pot1Angle; 72 servo2PosSaves[0] = pot2Angle; 73 servo3PosSaves[0] = pot3Angle; 74 digitalWrite(LED1, HIGH); 75 Serial.println("Pos 1 Saved"); 76 break; 77 case 2: 78 servo1PosSaves[1] = pot1Angle; 79 servo2PosSaves[1] = pot2Angle; 80 servo3PosSaves[1] = pot3Angle; 81 digitalWrite(LED2, HIGH); 82 Serial.println("Pos 2 Saved"); 83 break; 84 case 3: 85 servo1PosSaves[2] = pot1Angle; 86 servo2PosSaves[2] = pot2Angle; 87 servo3PosSaves[2] = pot3Angle; 88 digitalWrite(LED3, HIGH); 89 Serial.println("Pos 3 Saved"); 90 break; 91 case 4: 92 servo1PosSaves[3] = pot1Angle; 93 servo2PosSaves[3] = pot2Angle; 94 servo3PosSaves[3] = pot3Angle; 95 digitalWrite(LED4, HIGH); 96 Serial.println("Pos 4 Saved"); 97 break; 98 case 5: 99 servo1PosSaves[4] = pot1Angle; 100 servo2PosSaves[4] = pot2Angle; 101 servo3PosSaves[4] = pot3Angle; 102 digitalWrite(LED5, HIGH); 103 Serial.println("Pos 5 Saved"); 104 break; 105 } 106 } 107 108 if(digitalRead(button2) == HIGH){ // Pretty self-explnatory here 109 button2Pressed = true; 110 } 111 112 if(button2Pressed){ // if the boolean button2Press is true, then the servos will run though all their saved positions 113 for(int i = 0; i < 5; i++){ 114 servo1.write(servo1PosSaves[i]); 115 servo2.write(servo2PosSaves[i]); 116 servo3.write(servo3PosSaves[i]); 117 Serial.println(" potentimeter Angles: "); 118 Serial.println(servo1PosSaves[i]); 119 Serial.println(servo2PosSaves[i]); 120 Serial.println(servo3PosSaves[i]); 121 delay(1050); 122 } 123 } 124 delay(300); 125}
Downloadable files
1st step
just see and don't get confused!
1st step
Documentation
2nd step
if u have done it successfully its a easy task to do the final one!
2nd step
2nd step
if u have done it successfully its a easy task to do the final one!
2nd step
Comments
Only logged in users can leave comments
SuperGENERAL
0 Followers
•0 Projects
Table of contents
Intro
0
0