Project tutorial
Arduino Drawing Robot (Open Source Turtle Robot)

Arduino Drawing Robot (Open Source Turtle Robot) © GPL3+

Contains Arduino Nano, two step motors and motor drivers, and one servo.

  • 695 views
  • 0 comments
  • 4 respects

Components and supplies

Ard nano
Arduino Nano R3
×1
28BYJ-48 DC 5V Reduction Step Motor Gear Stepper Motor
×2
uln2003 stepper motor driver
×2
Sg90 servo motor 180 degrees sg90 micro
SG90 Micro-servo motor
×1
Adafruit industries ada258 image 75px
Li-Ion Battery 1000mAh
×2
Stmicroelectronics l7805cv image
Linear Regulator (7805)
×1
E switch eg1218 image 75px
Slide Switch
×1

Necessary tools and machines

3drag
3D Printer (generic)
09507 01
Soldering iron (generic)

Apps and online services

About this project

Code

codeArduino
// 

#include <Servo.h>

// setup servo
int servoPin = 8;
int PEN_DOWN = 15; // angle of servo when pen is down
int PEN_UP = 80;   // angle of servo when pen is up
Servo penServo;

float wheel_dia=63.2; //    # mm (increase = spiral out)
float wheel_base=108; //    # mm (increase = spiral in, ccw) 
int steps_rev=512; //        # 512 for 64x gearbox, 128 for 16x gearbox
int delay_time=2; //         # time between steps in ms

// Stepper sequence org->pink->blue->yel
int L_stepper_pins[] = {12, 10, 9, 11};
int R_stepper_pins[] = {4, 6, 7, 5};

int fwd_mask[][4] =  {{1, 0, 1, 0},
                      {0, 1, 1, 0},
                      {0, 1, 0, 1},
                      {1, 0, 0, 1}};

int rev_mask[][4] =  {{1, 0, 0, 1},
                      {0, 1, 0, 1},
                      {0, 1, 1, 0},
                      {1, 0, 1, 0}};


void setup() {
  randomSeed(analogRead(1)); 
  Serial.begin(9600);
  for(int pin=0; pin<4; pin++){
    pinMode(L_stepper_pins[pin], OUTPUT);
    digitalWrite(L_stepper_pins[pin], LOW);
    pinMode(R_stepper_pins[pin], OUTPUT);
    digitalWrite(R_stepper_pins[pin], LOW);
  }
  penServo.attach(servoPin);
  Serial.println("setup");
  
  penup();
  
  delay(1000);
}


void loop(){ // draw a calibration box 4 times
  pendown();
  forward(50);
right(135);
forward(25);
left(90);
forward(25);
right(135);
forward(50); 
penup();
left(90);
forward(10); 
left(90); 
pendown();

forward(50);
penup();
right(180);
forward(50);
left(90); 
forward(10);
left(90);
pendown();

forward(50);
right(90);
forward(25);
right(90);
forward(25);
right(90);
forward(25);
left(45);
left(90);
forward(35);
  penup();
  
  left(45);
  forward(10);
  pendown();
  left(90);
  forward(50);
right(90);
forward(25);
penup();
right(90);
forward(50);
pendown();
right(90);
forward(25);
penup();
left(180);
forward(35);
left(90);
pendown();

forward(50);
right(90); 
forward(25);
penup();
right(90);
forward(25);
pendown();
right(90);
forward(25);
penup();
left(90);
forward(25);
pendown();
left(90);
pendown();
forward(25);
penup();
forward(10);
left(90);
pendown();

 forward(50);
right(135);
forward(25);
left(90);
forward(25);
right(135);
forward(50); 
penup();
left(90);
forward(10); 
left(90); 
pendown();

forward(50);
penup();
right(180);
forward(50);
pendown();
left(140);
pendown();
forward(60);
right(180);
penup();
forward(30);
pendown();
left(90);
forward(30);
penup();
left(40);
forward(20);
right(90);
forward(150);



  done();      // releases stepper motor
  while(1);    // wait for reset
}


// ----- HELPER FUNCTIONS -----------
int step(float distance){
  int steps = distance * steps_rev / (wheel_dia * 3.1412); //24.61
  /*
  Serial.print(distance);
  Serial.print(" ");
  Serial.print(steps_rev);
  Serial.print(" ");  
  Serial.print(wheel_dia);
  Serial.print(" ");  
  Serial.println(steps);
  delay(1000);*/
  return steps;  
}


void forward(float distance){
  int steps = step(distance);
  Serial.println(steps);
  for(int step=0; step<steps; step++){
    for(int mask=0; mask<4; mask++){
      for(int pin=0; pin<4; pin++){
        digitalWrite(L_stepper_pins[pin], rev_mask[mask][pin]);
        digitalWrite(R_stepper_pins[pin], fwd_mask[mask][pin]);
      }
      delay(delay_time);
    } 
  }
}


void backward(float distance){
  int steps = step(distance);
  for(int step=0; step<steps; step++){
    for(int mask=0; mask<4; mask++){
      for(int pin=0; pin<4; pin++){
        digitalWrite(L_stepper_pins[pin], fwd_mask[mask][pin]);
        digitalWrite(R_stepper_pins[pin], rev_mask[mask][pin]);
      }
      delay(delay_time);
    } 
  }
}


void right(float degrees){
  float rotation = degrees / 360.0;
  float distance = wheel_base * 3.1412 * rotation;
  int steps = step(distance);
  for(int step=0; step<steps; step++){
    for(int mask=0; mask<4; mask++){
      for(int pin=0; pin<4; pin++){
        digitalWrite(R_stepper_pins[pin], rev_mask[mask][pin]);
        digitalWrite(L_stepper_pins[pin], rev_mask[mask][pin]);
      }
      delay(delay_time);
    } 
  }   
}


void left(float degrees){
  float rotation = degrees / 360.0;
  float distance = wheel_base * 3.1412 * rotation;
  int steps = step(distance);
  for(int step=0; step<steps; step++){
    for(int mask=0; mask<4; mask++){
      for(int pin=0; pin<4; pin++){
        digitalWrite(R_stepper_pins[pin], fwd_mask[mask][pin]);
        digitalWrite(L_stepper_pins[pin], fwd_mask[mask][pin]);
      }
      delay(delay_time);
    } 
  }   
}


void done(){ // unlock stepper to save battery
  for(int mask=0; mask<4; mask++){
    for(int pin=0; pin<4; pin++){
      digitalWrite(R_stepper_pins[pin], LOW);
      digitalWrite(L_stepper_pins[pin], LOW);
    }
    delay(delay_time);
  }
}


void penup(){
  delay(250);
  Serial.println("PEN_UP()");
  penServo.write(PEN_UP);
  delay(250);
}


void pendown(){
  delay(250);  
  Serial.println("PEN_DOWN()");
  penServo.write(PEN_DOWN);
  delay(250);
}

Schematics

schematic
Schematic tgu4xryrpn

Comments

Similar projects you might like

Otto DIY+ Arduino Bluetooth Robot Easy to 3D Print

Project tutorial by Team Otto builders

  • 48,318 views
  • 117 comments
  • 163 respects

OttoDIY Build Your Own Robot in One Hour!

Project tutorial by Camilo Parra Palacio

  • 104,245 views
  • 128 comments
  • 296 respects

KjellFa Robot: A Replica Of The Trallfa Robot

Project showcase by Team Kjell Jaeger

  • 946 views
  • 0 comments
  • 2 respects

Tito - Arduino UNO 3D-printed robot

Project tutorial by Camilo Parra Palacio

  • 10,642 views
  • 10 comments
  • 39 respects

Obstacles Avoiding Robot With Servo Motor

Project tutorial by Sora JY

  • 6,606 views
  • 3 comments
  • 20 respects

DIY Portable Distance Detection Device

Project tutorial by Viktor S

  • 5,901 views
  • 5 comments
  • 16 respects
Add projectSign up / Login