Introduction: RobotArmValgfag_EAL

Vi har fået til opgave at lave en Robot arm som bliver styret af en Arduino Uno der er bygget ind i en kontroller fra en gammel fjernstyret helikopter.

Step 1:

Vi startede med at splitte helikopter og fjernbetjening, modificeret så der var plads til et Arduino Uno board, og 2 joystick.

Step 2:

Vi har forbundet fjernbetjeningen med robot armen via to patch

kabler.

Step 3: Forbindelses Diagram

forbindelses diagrammet viser hvordan ledningerne er forbundet, mellem Arduino og robotarmens 4 motorer, ultralydssensor og de andre ting.

Step 4: Programmet

/*

 Controlling a servo position using a potentiometer (variable resistor)
 by Michal Rinott 
 modified on 8 Nov 2013
 by Scott Fitzgerald
  http://www.arduino.cc/en/Tutorial/Knob
modified on 20 May 2016
by Troels & Jonas, students from Erhvervsakademiet Lillebælt
*/
#include 
Servo myservo;  // create servo object to control a servo
Servo myservo1;  // create servo object to control a servo
Servo myservo2;  // create servo object to control a servo
Servo myservo3;  // create servo object to control a servo
int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin
int valop=90;
int potpin1 = 1;  // analog pin used to connect the potentiometer
int val1;    // variable to read the value from the analog pin
int valop1=90; 
int potpin2 = 2;  // analog pin used to connect the potentiometer
int val2;    // variable to read the value from the analog pin
int valop2=90;
int potpin3 = 3;  // analog pin used to connect the potentiometer
int val3;    // variable to read the value from the analog pin
int valop3=90;
#define trigPin 13
#define echoPin 12
#define led 10
#define led2 11
void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo1.attach(3);  // attaches the servo on pin 10 to the servo object
   myservo2.attach(5);  // attaches the servo on pin 5 to the servo object
  myservo3.attach(6);  // attaches the servo on pin 6 to the servo object
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
 
 
 Serial.begin(9600);
}
void loop() {
  
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
 // val = map(val, 0, 1023, 0, 1023);
     
 
 
  //Serial.print("valop_");
    //Serial.println(valop);
                        // waits for the servo to get there
if (val<600&&val>300){
myservo.write (valop=valop);
delay(10);
 //Serial.print("val_");
 //Serial.println(val);
 
}
if (val>600&&val<1200){
myservo.write (valop=valop +3);
delay(10);
}
if (val<300&&val>1){
myservo.write (valop=valop -3);
delay(10);
}
 val1 = analogRead(potpin1);            // reads the value of the potentiometer (value between 0 and 1023)
 //val = map(val, 0, 1023, 0, 1023);
 
if (val1<600&&val1>400){
myservo1.write (valop1=valop1);
delay(20);
//Serial.print("val1_");
 //Serial.println(val1);
 delay (10);
}
if (val1>600&&val1<1200){
myservo1.write (valop1=valop1 +3);
delay(10);
}
if (val1<300&&val1>1){
myservo1.write (valop1=valop1 -3);
delay(10);
 
}
//Serial.print("valop1_");
 //Serial.println(valop1);
                  
val2 = analogRead(potpin2);            // reads the value of the potentiometer (value between 0 and 1023)
 //val = map(val, 0, 1023, 0, 1023);
 
if (val2<600&&val2>400){
myservo2.write (valop2=valop2);
delay(20);
//Serial.print("val2_");
// Serial.println(val2);
 
}
if (val2>600&&val2<1200){
myservo2.write (valop2=valop2 +3);
delay(10);
}
if (val2<300&&val2>1){
myservo2.write (valop2=valop2 -3);
delay(10);
 
}
 //Serial.print("valop2_");
 //Serial.println(valop2);
                    
val3 = analogRead(potpin3);            // reads the value of the potentiometer (value between 0 and 1023)
 //val = map(val, 0, 1023, 0, 1023);
 
if (val3<600&&val3>400){
myservo3.write (valop3=valop3);
delay(20);
Serial.print("val3_");
 Serial.println(val3);
 
}
if (val3>600&&val3<1200){
myservo3.write (valop3=valop3 +3);
delay(10);
}
if (val3<300&&val3>1){
myservo3.write (valop3=valop3 -3);
delay(10);
 
}
 Serial.print("valop3_");
 Serial.println(valop3);
                   
  long duration, distance;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
//  delayMicroseconds(1000); - Removed this line
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  if (distance < 4) {  // This is where the LED On/Off happens
    digitalWrite(led,HIGH); // When the Red condition is met, the Green LED should turn off
  digitalWrite(led2,LOW);
}
  else {
    digitalWrite(led,LOW);
    digitalWrite(led2,HIGH);
  }
  if (distance >= 200 || distance <= 0){
    Serial.println("Out of range");
  }
  else {
    Serial.print(distance);
    Serial.println(" cm");
  }
  delay(500);
}

Step 5: Video Af Maskineriet