jegatheesan
Published

Cute Drawing Buddy V1, SCARA Robot - Arduino

I want to make a robo arm with less cost which draw cute pictures. That robot want to make my Daughter happy and it can able to dance. I ...

AdvancedFull instructions provided2 days7,132
Cute Drawing Buddy V1, SCARA Robot - Arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Tower Pro Micro servo
×3
Capacitor 1000 µF
Capacitor 1000 µF
×1
Plain PCB
×1

Software apps and online services

Arduino IDE
Arduino IDE
vb.net

Hand tools and fabrication machines

Drilling machine
Hot glue gun (generic)
Hot glue gun (generic)
hacksaw Blade
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Arm Lengths

Code

Servo.ino

Arduino
#include <Servo.h>  
Servo myservo3;   //M2d Top servo
Servo myservo5;  //M1d bottom servo
Servo myservo6;  //Pen updown
int pos = 0;
boolean recstr=false;
boolean stringComplete;
int stp = 1;
String inputString = "";
int i,j;

int M1d;
int M2d;
int Pen;


int PM1d;
int PM2d;
int ppen;

int PM1dhome=10;
int PM2dhome=170;

int tdelay;

boolean compstatus;

void setup() 
{ 
  myservo3.attach(3); 
  myservo5.attach(5); 
  myservo6.attach(6); 
  Serial.begin(9600);
  recstr=true;
  compstatus=true;
  ppen=0;
 
  myservo3.write(170);
  myservo5.write(10);
  myservo6.write(45);      
  delay(100);     
  
  inputString.reserve(200);
} 
 
void loop() 
{
  if (stringComplete) {
    if(inputString.substring(0, 3) == "END")
    {
      compstatus=true;
        Pen = 0;
        myservo6.write(45);      
        delay(15);    
    
      M2d = PM2dhome;
      M1d = PM1dhome;      
      myservo3.write(PM2dhome);
      myservo5.write(PM1dhome);
      delay(15);       
      Serial.println("Cool");
    }
    else
    {
      if (compstatus==true)
      {
        M2d = PM2dhome;
        M1d = PM1dhome;
        Pen = 0;
        PM2d = PM2dhome;
        PM1d = PM1dhome;
        delay(200);
      }
      i = inputString.indexOf(',');
      j = i+1;
      j = inputString.indexOf(',',j);    
    
      M1d = inputString.substring(0, i).toInt();
      M2d = inputString.substring(i+1, j).toInt();
      Pen = inputString.substring(j+ 1,j+2).toInt();    
      
      
      
      if(M1d<10 || M1d > 170 || M2d<10 || M2d > 170 )
      {
      }
      else
      {
        if (compstatus==true || ppen!=Pen)
        {          
          if(PM2d < M2d) 
          {
            for(i=PM2d;i<=M2d;i++)
            {
              if(i>5 || i<170)
              {
                myservo3.write(i);    
                delay(15);                                    
              }
            }
          }
          else
          {
            for(i=PM2d;i>=M2d;i--)
            {
              if(i>5 || i<170)
              {
                myservo3.write(i);    
                delay(15);                                    
              }
            }            
          }
          
          if(PM1d < M1d) 
          {
            for(i=PM1d;i<=M1d;i++)
            {
              if(i>5 || i<170)
              {
                myservo5.write(i);    
                delay(15);                                    
              }
            }
          }
          else
          {
            for(i=PM1d;i>=M1d;i--)
            {
              if(i>5 || i<170)
              {
                myservo5.write(i);    
                delay(15);                                    
              }
            }            
          }
          
        }
        else
        {
          if(abs(PM1d-M1d)>abs(PM2d-M2d))
          {
            tdelay=abs(PM1d-M1d)*10;
          }
          else
          {
            tdelay=abs(PM2d-M2d)*10;            
          }
          
          myservo3.write(M2d);
          myservo5.write(M1d);
          delay(tdelay);                    
        }  
      }
      
     if (ppen!=Pen)
      {
        if(Pen==0)
        {
          myservo6.write(45);      
          delay(300);
        }
        else
        {
          myservo6.write(150);            
          delay(300);
        }    
        ppen=Pen;
      }
  
      compstatus=false;
      if(M1d<5 || M1d > 170 || M2d<5 || M2d > 170 )
      {
        Serial.println("out of bounds");                
      }
      else
      {
        Serial.println("OK");
      }
      
      PM1d=M1d;
      PM2d=M2d;
    }
    
    inputString="";
    
    stringComplete = false;
  }
}

void serialEvent() {
  while (Serial.available()) {
    char inChar = (char)Serial.read();
    inputString += inChar;
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}

Credits

jegatheesan

jegatheesan

18 projects • 67 followers
Simply A Mechatronics Lover.

Comments