maged_alex
Published © GPL3+

Arduino Servo Controller App

Mobile phone application that controls up to six servos

IntermediateProtip1 hour176
Arduino Servo Controller App

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Arduino sensor shield
×1
Biped Robot Kit
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

1_kWwAbYjdW3.jpg

2_T4ImJ32Jw2.jpg

3_WVhrUZo1Uh.jpg

4_0fPe7DYCAL.jpg

5_zFXXrCkBwF.jpg

Code

control_6_servos.ino

Arduino
String readString;
#include <Servo.h> 
Servo servoA;
Servo servoB;
Servo servoC;
Servo servoD;
Servo servoE;
Servo servoF;
 

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

  

  servoA.attach(3);  //the pin for the servoa control
  servoB.attach(5);  //the pin for the servob control
  servoC.attach(6);  //the pin for the servoc control
  servoD.attach(9);  //the pin for the servod control 
  servoE.attach(10);  //the pin for the servoc control
  servoF.attach(11);  //the pin for the servod control
  servoA.write(90);
  servoB.write(90);
  servoC.write(90);
  servoD.write(90);
  servoE.write(90);
  servoF.write(90);
  
}

void loop() {



  if (Serial.available())  {
    char c = Serial.read();  
    if (c == ',') {
    if (readString.length() >1) {
        Serial.println(readString); 

        int n = readString.toInt();  

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
        {
          Serial.print("writing Microseconds: ");
          Serial.println(n);
          if(readString.indexOf('A') >0) servoA.writeMicroseconds(n);
          if(readString.indexOf('B') >0) servoB.writeMicroseconds(n);
          if(readString.indexOf('C') >0) servoC.writeMicroseconds(n);
          if(readString.indexOf('D') >0) servoD.writeMicroseconds(n);
          if(readString.indexOf('E') >0) servoE.writeMicroseconds(n);
          if(readString.indexOf('F') >0) servoF.writeMicroseconds(n);
        }
        else
        {   
          Serial.print("writing Angle: ");
          Serial.println(n);
          if(readString.indexOf('A') >0) servoA.write(n);
          if(readString.indexOf('B') >0) servoB.write(n);
          if(readString.indexOf('C') >0) servoC.write(n);
          if(readString.indexOf('D') >0) servoD.write(n);
          if(readString.indexOf('E') >0) servoE.write(n);
          if(readString.indexOf('F') >0) servoF.write(n);
        }
         readString=""; 
      }
    }  
    else {     
      readString += c; 
    }
  }
}

Credits

maged_alex
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.