SHARE
TWEET

robotarm

a guest Apr 26th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Servo.h>
  2.  
  3. boolean drej1 = true;
  4. boolean object = false;
  5. Servo led1;
  6. Servo led2;
  7. Servo led3;
  8.  
  9. long duration1, cm1;
  10. const int trigPin1 = 5; // Trigger Pin på Ultrasonic Sensor
  11. const int echoPin1 = 4; // Echo Pin på Ultrasonic Sensor
  12.  
  13. int dstep = +5;
  14. int step = 0;
  15. int dstep1 = +5;
  16. int step1 = 0;
  17.  
  18. void setup() {
  19.   Serial.begin(9600);
  20.   led1.attach(9);
  21.   led2.attach(10);
  22.   led3.attach(8);
  23.  
  24. }
  25.  
  26. void loop() {
  27.   sensor1();
  28.  
  29.   if(drej1 == true){
  30.     drej();
  31.   }
  32.  if(objectdetect() < 14 && objectdetect() > 3){
  33.   drej1 = false;
  34.   lift();
  35.  }else{
  36.   drej1 = true;
  37.  }
  38.  if(objectdetect() < 2){
  39.   led2.write(90);
  40.  
  41.  }
  42.  
  43.   //Serial.println("Hello World \n");
  44.  
  45. }
  46.  
  47.    long microsecondsToCentimeters(long microseconds) {
  48.    return microseconds / 29 / 2;
  49.    }
  50. void sensor1(){
  51.    pinMode(trigPin1, OUTPUT);
  52.    digitalWrite(trigPin1, LOW);
  53.    delayMicroseconds(2);
  54.    digitalWrite(trigPin1, HIGH);
  55.    delayMicroseconds(10);
  56.    digitalWrite(trigPin1, LOW);
  57.    pinMode(echoPin1, INPUT);
  58.    duration1 = pulseIn(echoPin1, HIGH);
  59.    cm1 = microsecondsToCentimeters(duration1);
  60.    Serial.print(cm1);
  61.    Serial.print("cm sensor1");
  62.    Serial.println();
  63.    delay(100);
  64. }
  65.  
  66. void drej(){
  67.   step = step + dstep;
  68.   if(step > 175 || step < 5){
  69.     dstep = -dstep;
  70.   }
  71.     led3.write(step);  
  72.     delay(120);
  73. }
  74.  
  75. void lift(){
  76.   step1 = step1 + dstep1;
  77.   if(step1 > 175 || step1 < 5){
  78.     dstep1 = -dstep1;
  79.   }
  80.   led1.write(step1);
  81.   delay(120);
  82. }
  83.  
  84.  
  85. int objectdetect(){
  86.   return cm1;
  87. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top