Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Adam Mansour
Created October 19, 2015

Drawing Machine, Soldering an Arduino shield

Showcase (no instructions)39
Drawing Machine, Soldering an Arduino shield

Story

Read more

Code

Stepper motor Arduino code

C/C++
//
// Licensing:
// This program is in the public domain 
//
// for the stepper motors with wires
// coming directly out of the motor,
// connect the wires like this:
// grey: OUT1
// green: OUT2
// yellow: OUT3
// red: OUT4

// for the stepper motors with small
// plastic connectors on the side,
// connect the wires like this:
// red: OUT1
// grey: OUT2
// yellow: OUT3
// green: OUT4

// these four Arduino outputs connect to the 
// L298 inputs which correspond to the L298
// outputs attached to the motor wires as 
// above 
const int OUT1 = 4;
const int OUT2 = 5;
const int OUT3 = 6;
const int OUT4 = 7;

void setup()  {
  pinMode(OUT1, OUTPUT);
  pinMode(OUT2, OUTPUT);
  pinMode(OUT3, OUTPUT);
  pinMode(OUT4, OUTPUT);
}

void loop() {
    digitalWrite(OUT1, LOW);
    digitalWrite(OUT2, HIGH);
    digitalWrite(OUT3, LOW);
    digitalWrite(OUT4, HIGH);
    delay(10);
    
    digitalWrite(OUT1, LOW);
    digitalWrite(OUT2, HIGH);
    digitalWrite(OUT3, HIGH);
    digitalWrite(OUT4, LOW);
    delay(10);
    
    digitalWrite(OUT1, HIGH);
    digitalWrite(OUT2, LOW);
    digitalWrite(OUT3, HIGH);
    digitalWrite(OUT4, LOW);
    delay(10);
    
    digitalWrite(OUT1, HIGH);
    digitalWrite(OUT2, LOW);
    digitalWrite(OUT3, LOW);
    digitalWrite(OUT4, HIGH);
    delay(10);
}

Arduino shield code

C/C++
/* Sweep
 by BARRAGAN <http://barraganstudio.com> 
 This example code is in the public domain.

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Sweep
*/ 

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // twelve servo objects can be created on most boards
 
int pos = 0;    // variable to store the servo position 
 
void setup() 
{ 
  myservo.attach(7);  // attaches the servo on pin 9 to the servo object 
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  digitalWrite(3, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
} 
 
void loop() 
{ 
for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(10);                       // waits 15ms for the servo to reach the position 
  } 
  for(pos = 180; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(10);                       // waits 15ms for the servo to reach the position 
  } 
//  myservo.detach();
} 

Credits

Adam Mansour

Adam Mansour

10 projects • 1 follower

Comments