0% found this document useful (0 votes)
311 views

Current Code

This Arduino code defines pins to control a stepper motor and measure the current through its coils. It sets the pins as outputs, initializes serial communication, then enters a loop to set the coil polarities, read the analog current readings, convert them to milliamps, print the values and loop counter to the serial monitor, and shut down the coils between loops.

Uploaded by

api-525392370
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
311 views

Current Code

This Arduino code defines pins to control a stepper motor and measure the current through its coils. It sets the pins as outputs, initializes serial communication, then enters a loop to set the coil polarities, read the analog current readings, convert them to milliamps, print the values and loop counter to the serial monitor, and shut down the coils between loops.

Uploaded by

api-525392370
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

9/27/2020 Code.

html

//David Rak ME460 Design Project 1


//Stepper Motor Current Measurement

//Define Pin Names for readability


#define A 12
#define A2 3
#define B 13
#define B2 11
#define A_current 0
#define B_current 1

void setup() {
// put your setup code here, to run once:
//tell which pins we'll use
pinMode(A,OUTPUT); //Coil A
pinMode(A2,OUTPUT);

pinMode(B,OUTPUT); //Coil B
pinMode(B2,OUTPUT);

//Turn off coils


shutdown();

//Begin Serial Monitor


Serial.begin(9600);
}

//emergency shutdown function


void shutdown() {
//apply LOW V to everything
digitalWrite(A,LOW);
digitalWrite(A2,LOW);
digitalWrite(B,LOW);
digitalWrite(B2,LOW);
}

//Variables for Current & Loop


float iA=0, iB=0;
int ct=0;
void loop() {
//Set polarity of coil
digitalWrite(A,HIGH); //Turn on A
digitalWrite(A2,HIGH);

digitalWrite(B,HIGH); //Turn on B
digitalWrite(B2,HIGH);

for (ct=0; ct<25; ct++){ //Set number of loops with ct


iA=float(analogRead(A_current)) /1023.0*5.0 / 1.65 *1000.0; //convert to miliAmps
iB= float(analogRead(B_current)) /1023.0*5.0 / 1.65 *1000.0; //convert to miliAmps
Serial.print(iA);
Serial.print(" ");
Serial.print(iB);
Serial.print(" ");
Serial.println(ct);
}

shutdown(); //make sure it turns off when program finishes


while(1); //infinite loop to stop

file:///C:/Users/david/Documents/Señor/ME460- Senior Design/Homeworks/Design HW01- Project 01 - Open Loop/Code.html 1/1

You might also like