Smartphone/TAB Controlled Robot-ARM
Make a robot arm and Control With a FREE Android App Easily.
Components and supplies
4
Servos (Tower Pro MG996R)
1
IOIO-OTG - V2.2
1
Arduino UNO
1
UTSOURCE Electronic Parts
Project description
Code
android controlled robot arm.c
c_cpp
1 2# include <Servo.h> 3//PWM OUTPUT VARIABLES 4Servo pin2; 5Servo pin3; 6Servo pin4; 7Servo pin5; 8Servo pin6; 9//SERIAL USB BUFFER 10char inData[ 65 ]; // Allocate some space for the string 11char inChar; // Where to store the character read 12byte index = 0 ; // Index into array; where to store the character 13void setup () { 14//START PIN OUTPUT 15pin2. attach ( 2); // attaches the servo on pin 9 to the servo object 16pin3. attach ( 3); 17pin4. attach ( 4); 18pin5. attach ( 5); 19pin6. attach ( 6); 20//SEND MINIMAL VAUE 1000, REGUIRED FOR ESC TO ARM (max is 2000) 21pin2. writeMicroseconds (1000 ); 22pin3. writeMicroseconds (1000 ); 23pin4. writeMicroseconds (1000 ); 24pin5. writeMicroseconds (1000 ); 25pin6. writeMicroseconds (1000 ); 26//INIT SERIAL COMMUNICATION WITH ANDROID 27Serial. begin (115200 ); 28} 29void loop () { 30if (Serial. available () > 0 ){ 31//WAIT FOR INCOMMING DATA BUFFER TO FILL 32if (index < 24){ 33inChar = Serial. read (); // Read a character 34inData[ index ] = inChar; // Store it 35index ++; // Increment where to write next 36if (inChar == 'X' ) 37index = 0 ; 38inData[ index ] = '\\0' ; // Null terminate the string 39} 40} 41if (index ==24 ){ 42index = 0; 43//STRING LOOKS LIKE "A100B96C20D0E" WHERE LETTERS ACT AS DELIMINATOR 44//STRING CAN CONTAIN SINGLE VALUE LIKE "B96C" 45String buf = String (inData); 46int ia = buf. indexOf ( "A", 0); 47int ib = buf. indexOf ( "B", 0); 48int ic = buf. indexOf ( "C", 0); 49int id = buf. indexOf ( "D", 0); 50int ie = buf. indexOf ( "E", 0); 51int iff = buf. indexOf ("F" , 0 ); 52Serial. print ("|" ); 53//A?B 54if (ia!=- 1 && ib!=- 1){ 55//1. CONVERT VALUE TO INTEGER 56//2. CONVERT 0-100 TO 1000 - 2000 57//3. WRITE TO ARDUINO PIN NUMBER 2 58pin2. writeMicroseconds (map (buf. substring (ia+ 1, ib). toInt (), 1, 100 , 1000 , 2000 )); 59//SEND RESPONSE TO ANDROID 60Serial. print ( "RESPONSE:OK" ); 61} 62//B?C 63if (ib!=- 1 && ic!=- 1){ 64pin3. writeMicroseconds (map (buf. substring (ib+ 1, ic). toInt (), 1, 100 , 1000 , 2000 )); 65//Serial.print("PIN3 OK"); 66} 67//C?D 68if (ic!=- 1 && id!=- 1){ 69pin4. writeMicroseconds (map (buf. substring (ic+ 1, id). toInt (), 1, 100 , 1000 , 2000 )); 70//Serial.print("PIN4 OK"); 71} 72//D?E 73if (id!=- 1 && ie!=- 1){ 74pin5. writeMicroseconds (map (buf. substring (id+ 1, ie). toInt (), 1, 100 , 1000 , 2000 )); 75//Serial.print("PIN5 OK"); 76} 77//E?F 78if (ie!=- 1 && iff!=- 1){ 79pin5. writeMicroseconds (map (buf. substring (ie+ 1, iff). toInt (), 1 , 100 , 1000 , 2000 )); 80//Serial.print("PIN6 OK"); 81} 82Serial. print ("|00" ); 83Serial. print ("\ 84" ); 85} 86} 87void logg (){ 88}
android controlled robot arm.c
c_cpp
1 2# include <Servo.h> 3//PWM OUTPUT VARIABLES 4Servo pin2; 5Servo pin3; 6Servo pin4; 7Servo pin5; 8Servo pin6; 9//SERIAL USB BUFFER 10char inData[ 65 ]; // Allocate some space for the string 11char inChar; // Where to store the character read 12byte index = 0 ; // Index into array; where to store the character 13void setup () { 14//START PIN OUTPUT 15pin2. attach ( 2); // attaches the servo on pin 9 to the servo object 16pin3. attach ( 3); 17pin4. attach ( 4); 18pin5. attach ( 5); 19pin6. attach ( 6); 20//SEND MINIMAL VAUE 1000, REGUIRED FOR ESC TO ARM (max is 2000) 21pin2. writeMicroseconds (1000 ); 22pin3. writeMicroseconds (1000 ); 23pin4. writeMicroseconds (1000 ); 24pin5. writeMicroseconds (1000 ); 25pin6. writeMicroseconds (1000 ); 26//INIT SERIAL COMMUNICATION WITH ANDROID 27Serial. begin (115200 ); 28} 29void loop () { 30if (Serial. available () > 0 ){ 31//WAIT FOR INCOMMING DATA BUFFER TO FILL 32if (index < 24){ 33inChar = Serial. read (); // Read a character 34inData[ index ] = inChar; // Store it 35index ++; // Increment where to write next 36if (inChar == 'X' ) 37index = 0 ; 38inData[ index ] = '\\0' ; // Null terminate the string 39} 40} 41if (index ==24 ){ 42index = 0; 43//STRING LOOKS LIKE "A100B96C20D0E" WHERE LETTERS ACT AS DELIMINATOR 44//STRING CAN CONTAIN SINGLE VALUE LIKE "B96C" 45String buf = String (inData); 46int ia = buf. indexOf ( "A", 0); 47int ib = buf. indexOf ( "B", 0); 48int ic = buf. indexOf ( "C", 0); 49int id = buf. indexOf ( "D", 0); 50int ie = buf. indexOf ( "E", 0); 51int iff = buf. indexOf ("F" , 0 ); 52Serial. print ("|" ); 53//A?B 54if (ia!=- 1 && ib!=- 1){ 55//1. CONVERT VALUE TO INTEGER 56//2. CONVERT 0-100 TO 1000 - 2000 57//3. WRITE TO ARDUINO PIN NUMBER 2 58pin2. writeMicroseconds (map (buf. substring (ia+ 1, ib). toInt (), 1, 100 , 1000 , 2000 )); 59//SEND RESPONSE TO ANDROID 60Serial. print ( "RESPONSE:OK" ); 61} 62//B?C 63if (ib!=- 1 && ic!=- 1){ 64pin3. writeMicroseconds (map (buf. substring (ib+ 1, ic). toInt (), 1, 100 , 1000 , 2000 )); 65//Serial.print("PIN3 OK"); 66} 67//C?D 68if (ic!=- 1 && id!=- 1){ 69pin4. writeMicroseconds (map (buf. substring (ic+ 1, id). toInt (), 1, 100 , 1000 , 2000 )); 70//Serial.print("PIN4 OK"); 71} 72//D?E 73if (id!=- 1 && ie!=- 1){ 74pin5. writeMicroseconds (map (buf. substring (id+ 1, ie). toInt (), 1, 100 , 1000 , 2000 )); 75//Serial.print("PIN5 OK"); 76} 77//E?F 78if (ie!=- 1 && iff!=- 1){ 79pin5. writeMicroseconds (map (buf. substring (ie+ 1, iff). toInt (), 1 , 100 , 1000 , 2000 )); 80//Serial.print("PIN6 OK"); 81} 82Serial. print ("|00" ); 83Serial. print ("\ 84" ); 85} 86} 87void logg (){ 88}
Downloadable files
robot arm
robot arm
Comments
Only logged in users can leave comments