tryiing to get a stepper motor to work on ardiuno

hi
i have a bipolar stepper motor what i need to controlon my ardiuno im trying to control it with a 10k temperaturometer so basically the stepper motor reanacts what the pot is doing but i need to be able to set a amount of degrees the motor will rotate eg 180 degrees
i have no idea how to program this so any help would be appreciated

thanks Joe

What don't you know how to do?

How to read the temperature sensor? How to convert the temperature sensor value to a stepper position? How to make the stepper motor step the required number of steps? All of the above?

sorry my bad spelling i meant potentiomenter theres no temperature sensor
basically how to do the programming for all of it i find it hard to get the programming round my head lol

thanks Joe

#define potPin 1 // Change to whatever pin the 
// potentiometer is connected to

void setup()
{
}

void loop()
{
    int potVal = analogRead(potPin);
    int stpPos = map(potVal, 0, 1023, 0 180);
}

This code will read the potentiometer setting, and map that value from a range of 0 to 1023 to a range of 0 to 180.

Without knowing anything about your stepper motor, and how it is connected, I can't help you with any more code.

The range that you are talking about (0 to 180) makes me think that you are talking about a servo, rather than a stepper motor.

Tell us more about the actual hardware, and we can move on.

her is a picture of my setup
digital pins 8,9,10, 11 are connected to the motor
and analog pin 0 is connected to the centre of the potentiomenter

hope this is some help

thanks Joe

Still not quite enough information...

How many steps per revolution?

There is a Stepper library that can easily be use to drive the stepper motor. You tell it haw many steps in a complete revolution. Then, tell it to step the motor.

Since you want the stepper motor to act like a servo, you will need to keep track of where it is, and whether the motor should step forwards or backwards to get from the old position to the new position.

soz if im being a bit thick how do you count the steps is it as simple as counting the clicks at you rotate the shaft?

how do you count the steps

You look at the data sheet for your stepper motor. It will tell you that.

Also, the design of the driver will determine whether half steps, quarter steps, or eighth steps are possible.

Or, you experiment...

i have no info for it unfortunatly

Ok, so we have no information; lets try and get some.

  1. What is the chip in the picture?

  2. Can you make the motor do anything?

  3. are there any numbers on the motor?

If you can give me the chip number and/or the numbers on the motor I might be able to help you.

Chris

Closer inspection of your picture leads me to think that you have a L239D H bridge chip.
Assuming you have then try running the MotorKnob example bundled with the Arduino IDE, you might need to change some of the pin bindings. If this works then replace the code in setup() and loop() with this:

void setup()
{
    stepper.setSpeed(30);
}

loop()
{
    stepper.step(100);
}

watch your motor turn, if it goes more than one turn, then reduce the number of steps set by #define STEPS on line 13. If it goes less then a turn then increase the number of steps. Once you have found the number of steps per turn then you can follow the code suggested by PaulS

Chris

I just recently built a controller to work with bi-polar stepper motors myself. You can find more details here: A Simple Dual H-Bridge – Kerry D. Wong

Hope it helps!

the chip in the picture is H-bridge sn764410NE
Can you make the motor do anything?
yes I have had it working on the arduino with the coding on the arduino software under stepper what makes the motor rotate backwards and forwards but cannot control it. It does what it wants to do
are there any numbers on the motor?
16hy0417n
Date 03 01 23

hope that is some help

Can you make the motor do anything?

yes I have had it working on the arduino with the coding on the arduino software under stepper what makes the motor rotate backwards and forwards but cannot control it. It does what it wants to do

It does not do what it wants to do. It does what you told it to do.

Apparently, what you told it to do, and what you wanted it to do, are not the same thing.

Post that code that does something, and describe what it does, and what you want it to do instead.

Something else to keep in mind, which PaulS hinted about...

Even if you are counting steps to get to the angle you want, those will ONLY be referenced to the starting position of the motor. Should the motor slip or mis-step, or should something force the shaft to rotate (or stop it from rotating), the count the system has for the position will not be the same as the rotational position of the shaft.

In order to obtain the positional information of the shaft, you need to implement an absolute position encoder scheme; if you are limited to only a certain set of angles less than 360 degrees, you can use a potentiometer (multi-turn if you can get by with a few full rotations or need 360 degrees). If you need full and continuous rotation, then you will need a binary encoder of some sort (works like any optical encoder, except that it outputs a binary number indicating its position - and typically does not have rotational limits - but they don't tend to be cheap, either, depending on the required resolution).

Either of these options will give you the ability to monitor the shaft of the motor for positional information to a fixed angle.

this is the code im am using:

/*

#include <Stepper.h>

// change this to the number of steps on your motor
#define STEPS 100

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 8, 9, 10, 11);

// the previous reading from the analog input
int previous = 0;

void setup()
{
// set the speed of the motor to 30 RPMs
stepper.setSpeed(30);
}

void loop()
{
// get the sensor value
int val = analogRead(0);

// move a number of steps equal to the change in the
// sensor reading
stepper.step(val - previous);

// remember the previous value of the sensor
previous = val;
}

when using this code it will rotate but it rotates even when your not touching the pot and it will randomly change direction on its own.it will sometimes shudder backwards and forwards.If you rotate the pot it may sometimes change direction heading in the opposite direction but if you wind the pot from one end to the other you can hear the motor change the tone as well

thanks for that information cr0sh the motor is opperatinga spring loaded device so when power is lost it should return back to the same position as started but trail and error will prove that fact lol

thanks Joe

hi been tring to have a bit of a play with my arduino and it woat let me down lode to it, it some's up with this:
avrdude: stk500_paged_write() : (a) protocol error, expect=0x14, resp=0x64
avrdude: failed to write flash memory, rc=4
avrdude: stk500_disable () :protocol error, expect=0x14, resp=0x51

any one no what's going on???
thanks Joe

help lol

i guess im at the give up stage now lol