Devices & Components
Arduino Mega 2560 Rev3
Jumper wires (generic)
Pushbutton switch 12mm
SG90 Micro-servo motor
Rotary potentiometer (generic)
Breadboard (generic)
Software & Tools
Arduino IDE
Project description
Code
Moving code
c_cpp
When you have servo values run this code and place values there
1#include <Servo.h> 2Servo first;//first arm segment 3Servo second;//second arm segment 4 5void setup() { 6 //servos 7 first.attach(3); 8 second.attach(4); 9} 10 11void loop() { 12 moveHand(90,90);//insert values - (first,second) 13 delay(1000); 14 moveHand(120,90); 15 delay(1000); 16 moveHand(80,80); 17 delay(1000); 18} 19void moveHand(int f,int s) { 20 first.write(f); 21 second.write(s); 22} 23
Calibrating code
c_cpp
Code for getting servo pos values
1#include <Servo.h> 2Servo first;//first arm segment 3Servo second;//second arm segment 4 5//pots for controling the arm 6int firstpot = A8; 7int secondpot = A9; 8 9//button to fix position 10int btt = 2; 11 12void setup() { 13 pinMode(btt, INPUT); //button pinMode 14 Serial.begin(9600);//start serial 15 //servos 16 first.attach(3); 17 second.attach(4); 18} 19 20void loop() { 21 first.write(map(analogRead(firstpot), 0, 1023, 50, 120)); //first servo turned by pot using map() servo protection by borders of servo turning options 22 second.write(map(analogRead(secondpot), 0, 1023, 0, 100)); //second servo turned by pot using map() servo protection by borders of servo turning options 23 delay(10);//delay for stability 24 25 if (digitalRead(btt) == 1) {//if botton pressed 26 Serial.print("first -->"); 27 Serial.println(map(analogRead(firstpot), 0, 1023, 50, 150)); 28 Serial.print("second -->"); 29 Serial.println(map(analogRead(secondpot), 0, 1023, 0, 100)); 30 delay(1000); 31 } 32 33}
Moving code
c_cpp
When you have servo values run this code and place values there
1#include <Servo.h> 2Servo first;//first arm segment 3Servo second;//second arm segment 4 5void setup() { 6 //servos 7 first.attach(3); 8 second.attach(4); 9} 10 11void loop() { 12 moveHand(90,90);//insert values - (first,second) 13 delay(1000); 14 moveHand(120,90); 15 delay(1000); 16 moveHand(80,80); 17 delay(1000); 18} 19void moveHand(int f,int s) { 20 first.write(f); 21 second.write(s); 22} 23
Calibrating code
c_cpp
Code for getting servo pos values
1#include <Servo.h> 2Servo first;//first arm segment 3Servo second;//second arm segment 4 5//pots for controling the arm 6int firstpot = A8; 7int secondpot = A9; 8 9//button to fix position 10int btt = 2; 11 12void setup() { 13 pinMode(btt, INPUT); //button pinMode 14 Serial.begin(9600);//start serial 15 //servos 16 first.attach(3); 17 second.attach(4); 18} 19 20void loop() { 21 first.write(map(analogRead(firstpot), 0, 1023, 50, 120)); //first servo turned by pot using map() servo protection by borders of servo turning options 22 second.write(map(analogRead(secondpot), 0, 1023, 0, 100)); //second servo turned by pot using map() servo protection by borders of servo turning options 23 delay(10);//delay for stability 24 25 if (digitalRead(btt) == 1) {//if botton pressed 26 Serial.print("first -->"); 27 Serial.println(map(analogRead(firstpot), 0, 1023, 50, 150)); 28 Serial.print("second -->"); 29 Serial.println(map(analogRead(secondpot), 0, 1023, 0, 100)); 30 delay(1000); 31 } 32 33}
Downloadable files
schematics image
schematics image

Fritzing schematics
Fritzing schematics
schematics image
schematics image

Fritzing schematics
Fritzing schematics
schematics
schematics
Comments
Only logged in users can leave comments