Pages: [1]   Go Down
Author Topic: checking stepper motor resistance using the arduino  (Read 485 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 2
Posts: 219
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i'm not sure how a stepper motor is wired, and without having a volt meter.
I wondered why not use the anolog read for it.

But i'm not sure if it is safe to do, might it damage the arduino ?.
i want to use the +5 volt of the arduino put the stepper in between and use a simple program to read out the anolog, the wires inside should give  resistance and that would give me an indication of how it is wired after some conection tests with the wiring.

i however have doubts of damaging the arduino itself, as for this i wont use a motor driving board but directly put current/voltage trough it

note that i wont try to do a running motor test but just try to figure out what wire is used for what.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8706
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As long as the power source is 5V you don't have to worry about it.

Put a known resistance (N Ohms) between the analog input pin and +5V.  Use something around 100 ohms.  If you have ten 1000 Ohm resistors you can put them all in parallel to get better accuracy.

Connect the stepper coil between analog input and Ground.  The voltage across the coil will be in the same ratio as the resistance.  For example if you read 512 (2.5v) then the drop across both resistors is the same and the coil is 100 Ohms (same as the fixed resistor).  If you read 256 (1.25v) then the drop across the coil is 1/4 and across the resistor is 3/4.  That means that the coil resistance is 1/3 the resistor or 33.3 Ohms.

Take the reading, divide it by (1024 - the reading) and multiply by the known resistance:

512 / (1024.0-512) = 1.0
256 / (1024.0-256) = 0.333
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11718
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Don't do that, its an inductive load and will kick back hard (100's of volts is possible) when disconnected.

You can do something similar but you will need to protect the input pin from over voltage - using a 4v7 zener between pin and ground and a 10k series resistor between pin and the test circuit perhaps.
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Full Member
***
Karma: 2
Posts: 219
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ehm its a tiny stepper motor not a large one, so would the kickback really be hundreds of volt ??,
 it's a bit hard to imagine for me that i will create lightning sparks here smiley

but it is what i wondered ..
i'm not sure what to now, do it or not (both of you are respected people here who know a lot of electronics, more then me)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You nEEd a multimeter, it will make understanding ohms law a lot easier.

MarkT is right about the spike in voltage from the coil in the motor, though short in time and low in current it has an extremely high voltage compared to the voltage you charged it with.

http://wiki.answers.com/Q/What_is_the_formula_for_transient_spike_computation_in_an_inductive_load

Also note that resistance in a coil changes under load.
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 219
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well this is my setup,
I measured values  24 and 48, so i found and notated the wiring (as in the sketch below it).

And some fun, i often make use of my office stapler and its staples to make small connectors on the breadboard smiley


Above sketch is like this, from the 5 volt pin a resistor 1000 ohm to analog pin 0  (i didnt had a 100 ohm)
From analog pin 0, i go to a wire of the stepper motor.
While with another wire connected to ground i check if there is a connection with one of the other stepper motor wires.
Then if there is connection, i read the analog value (the magnet wires will have some resistance, as they are long)

Below is my simple code it requires serial monitor to be active.
Code:
const int analog0 = A0;
const int led05   = 5;
void setup()
  {
  pinMode(led05, OUTPUT);
  //Initialize serial
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only,
      //i use an arduino demineuve so strictly i dont need this
     }
  Serial.println("start");
  }

int thisByte = 0;

void loop()
  {
  delay(600); // some delay, not to overload the serial comunication
  digitalWrite(led05,HIGH);
  thisByte = analogRead(analog0);
  Serial.println(thisByte);     
  digitalWrite(led05,LOW);
  delay(600);
  }


I am not sure about the resistor value calculation here of the stepper motor
It wasnt my first goal (wanted to know its inner wiring) but now i am curious
John Wasser could you please explain how these values relate (24 and 48), my main resistor was 1000 ohm
1000 = brown black red (gold tpye)
Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 78
Posts: 1719
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It will be a unipolar stepper motor. If you sum two 24's you get the 48.

Coil1
o---CCCC---o---CCCC---o
W             O1              R

Coil 2
o---CCCC---o---CCCC---o
Y              O2              B

Where
--CCCC-- is a 24Ohm coil.
Logged

~Tom~

Offline Offline
Full Member
***
Karma: 2
Posts: 219
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes i found its uni-polar (dough i forgot how it was named), thanks.
as i'm not into electronics, rather into programming.
but i doubt its resistance is 24 ohm.. john showed a somewhat different calculation.

(also a side note all these extra wires go to a ledbank IC, i only use led 5), the led 5 blink is not even required, but rather i check for myself (wait for blink then notate the value)
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 30
Posts: 887
Old, decrepit curmugeon
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

    5V
     |
   1000 ohms
     |
     + -- > Analog pin
     |
  stepper coil
     |
   ground

Analog reading 1: 24 / 1024 * 5V = 0.1172V
Analog reading 2: 48 / 1024 * 5V = 0.2344V

So first use ohms law with the 1000 ohm resistor to determine the current flowing through it..

E = I * R

(5 - 0.1172) = I * 1000 ohms
I = 4.8828/1000 = 0.0049 A

Then use ohms law again to solve for the unknown resistance of the stepper coil

So across the coil, the resistance is

E = I * R
R = E/I
R = 0.1172V / 0.0049A ~ 23.9 ohms for the coil that gave you a measurement of 24 on analogRead

Repeat for other coil

P.S.  Even with low voltages and small coils, the voltage spike mentioned above can still be hundreds of volts.  Do a search of diode protection for such circuits, your Arduino will thank you.

EDITED to correct math error!
« Last Edit: August 01, 2012, 03:58:19 pm by wanderson » Logged

New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 1.0.1

Offline Offline
Full Member
***
Karma: 2
Posts: 219
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Analog reading 1: 24 / 2048 * 5V = 0.0586V
Analog reading 2: 48 / 2048 * 5V = 0.1172V

ehm why 2048 ?,the arduino Anolog digital coder ACD?DCA has 1024 as a max value..
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 30
Posts: 887
Old, decrepit curmugeon
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Analog reading 1: 24 / 2048 * 5V = 0.0586V
Analog reading 2: 48 / 2048 * 5V = 0.1172V

ehm why 2048 ?,the arduino Anolog digital coder ACD?DCA has 1024 as a max value..

It should be 1024 (10 bit, but I wasn't paying enough attention...)
Logged

New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 1.0.1

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8706
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is how you would print out the resistance:
Code:
int thisByte = 0;

void loop()
  {
  delay(600); // some delay, not to overload the serial comunication
  digitalWrite(led05,HIGH);
  thisByte = analogRead(analog0);
  Serial.println(1000.0 * (thisByte / (1024.0-thisByte)));     
  digitalWrite(led05,LOW);
  delay(600);
  }
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pages: [1]   Go Up
Jump to: