yrao1991
Published © GPL3+

Automated Knitting Machine

We leveraged the power of Arduino and a Nema 34 motor to automate a hand knitting machine.

IntermediateShowcase (no instructions)8,141
Automated Knitting Machine

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Stepper Motor, Mini Step
Stepper Motor, Mini Step
×1
Motor Driver/Controller, H-Bridge
Motor Driver/Controller, H-Bridge
×1
SMPS Controller, 8V-35V supply
SMPS Controller, 8V-35V supply
×1

Story

Read more

Code

Code for Arduino

Arduino
int pulPin = 4;
int dirPin = 3;
int enblPin = 2;
int ledPin = 13;
int pushButton = 6;
int speed =0;
int pushButton1 = 5;
void setup() {
  // put your setup code here, to run once:
  pinMode(pulPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(enblPin, OUTPUT);
  pinMode(ledPin, OUTPUT);

  digitalWrite(pulPin, LOW);
  digitalWrite(ledPin, LOW);
  digitalWrite(enblPin, LOW);
  digitalWrite(dirPin, LOW);


  pinMode(pushButton, INPUT);
  pinMode(pushButton1, INPUT);
  Serial.begin(9600);
  Serial.println("init");

  digitalWrite(enblPin, HIGH);
  delay(100);
  digitalWrite(enblPin, LOW);
}

void loop() {
  int buttonState = digitalRead(pushButton);
  int buttonState1 = digitalRead(pushButton1);
  Serial.print(buttonState);
  Serial.print("  ");
  Serial.println(buttonState1);
  int sensorValue = analogRead(A0);
   int sensorValue1 = analogRead(A1);

  // apply the calibration to the sensor reading
  speed = map(sensorValue1, 0, 1022, 100, 1000);
 Serial.print(speed);
  Serial.print("  ");
 
  if ((sensorValue <  900) && (sensorValue >  100))  {
    Serial.print("center");
  }
  if (sensorValue >  900) {
    Serial.print("right");
    cw();
  }
  if (sensorValue <  100) {
    Serial.print("left");
    cc();
  }


}


void cw() {
  while (1) {
    int buttonState = digitalRead(pushButton);
    int buttonState1 = digitalRead(pushButton1);
    digitalWrite(dirPin, HIGH);
    digitalWrite(pulPin, HIGH);
    digitalWrite(pulPin, LOW);
    delayMicroseconds(speed);
     int sensorValue = analogRead(A0);
    if ((sensorValue <  900) && (sensorValue >  100))  {
    Serial.print("center");
    break;
  }
    if (buttonState ==  LOW) {
      break;
    }
  }
}
void cc() {
  while (1) {
    int buttonState = digitalRead(pushButton);
    int buttonState1 = digitalRead(pushButton1);
    digitalWrite(dirPin, LOW);
    digitalWrite(pulPin, HIGH);
    digitalWrite(pulPin, LOW);
    delayMicroseconds(speed);
     int sensorValue = analogRead(A0);
     if ((sensorValue <  900) && (sensorValue >  100))  {
    Serial.print("center");
    break;
  }
    if (buttonState1 ==  LOW) {
      break;
    }
  }
}

Credits

yrao1991

yrao1991

1 project • 5 followers

Comments