0% found this document useful (0 votes)
8 views1 page

Documento 7

The document contains Arduino code for controlling a stepper motor with four pins (IN1 to IN4). It defines a total of 2048 steps to complete a 360-degree rotation, with a delay to control speed. The setup function initializes the pins as outputs, and the loop function executes the motor steps in sequence.

Uploaded by

arpufo64
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Documento 7

The document contains Arduino code for controlling a stepper motor with four pins (IN1 to IN4). It defines a total of 2048 steps to complete a 360-degree rotation, with a delay to control speed. The setup function initializes the pins as outputs, and the loop function executes the motor steps in sequence.

Uploaded by

arpufo64
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

int pinA = 8; // IN1 (Fase A)

int pinB = 9; // IN2 (Fase B)


int pinC = 10; // IN3 (Fase C)
int pinD = 11; // IN4 (Fase D)
#define totalPasos 2048
void setup() {
pinMode(pinA, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(pinC, OUTPUT);
pinMode(pinD, OUTPUT);
}
void loop() {
// Girar 360 grados (2048 pasos)
for (int i = 0; i < totalPasos; i++) {
// Secuencia para un paso
stepMotor(i % 4);
delay(2); // Pausa para controlar la velocidad
}
delay(1000); // Esperar 1 segundo
}
void stepMotor(int step) {
switch (step) {
case 0:
digitalWrite(pinA, HIGH);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
break;
case 1:
digitalWrite(pinA, LOW);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
break;
case 2:
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, LOW);
break;
case 3:
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, HIGH);
break;
}
}

You might also like