help with motor project

Hello Everyone
I’m working on a project and I need help writing code and connections
I’m very new to the field and decided to use by Arduino to build a prototype
I use - Arduino Uno
Stepper motor 28byj-48
uln2003a

What I need is a rotary switch to do some operations

  1. Rotating the motor X steps every X seconds
  2. Rotating the motor at a constant speed
  3. Rotating the motor X steps forward or back with two touch buttons
  4. Lighting Led

The LED have to start in the first mode and remain turned on all modes

I am attaching diagram

I would appreciate very much those who could help me

1_1.jpg

There are many other Threads about the same issue and some are bound to have code examples. Google should be able to find them for you. I am not familiar with the uln2003 myself.

...R

What questions do you have? Show your code. How do you plan to wire it up? Show a schematic. You could do this with just one potentiometer. When the pot is in the center, the motor is stationary. As you twist the pot off center the motor will spin faster one way or the other.

tnx for the replay

I have no code to begin with. I’m new in the field
I need help writing code
I am now going through the library of codes
I attach sketch of the project

i would say start by doing some homework.
1)make sure you know how stepper motors work and what type yours is exactly.
2) look up the datasheet for the uln2803 and make sure it can handle the current drawn by the motor. the datasheet will usually provide you with enough info to connect it up.
3) learn to use the arduino. work through the examples in the IDE under Basics, Digital, analog, control and stepper. "stepper" should have most of the code you need, the rest you can probably just cut and paste .

OP said ULN2003, not ULN2803, but they are basically the same except ULN2803 has
8 channels rather than 7, so it can drive two 28byj-48’s if you want.

Yes it can handle the current, those motors are very low power unipolar steppers,
5V 0.15A I believe.

Remember to connect the positive motor supply to the COM pin of the ULN2003
so that the freewheel diodes are in the circuit, otherwise you risk blowing the chip.
Freewheel diodes are always required when inductive loads are involved, any relay
solenoid or motor, basically.

The ULN2003 has base resistors already so its inputs are directly logic compatible.

You didn't understand me correctly at all
I know how the engine works and what I bought, Ihave already turned it on with simple code
My problem is how to build such a code that has ports for switches
i Have not yet writing my own code
And I thought someone could help me write the code or refer me to a guide similar to what I need

I did understand, and yes you did ask how to connect it. No, i wont write your code for you, (but someone else might). However, everything you need to know is in the arduino IDE, and any specific questions you might have we would be happy to answer for you. Yes, someone will help you with your code, but you first have to post whatever code you have even if it is just the example sketch and be specific with your questions. 1)Start with the example sketch and get your motor moving, 2) once you know the example code works, add a button input. 3) if you run into problems report back here and post your code.

I would say go through all the example sketches, pick all the ones that might
be relevant (use switchs/buttons/potentiometers to control things) and read
and run them and see how its done… Many lines of useful code that you can
steal and modify, that’s what examples are for!

tnx for all the replays

Can anyone refer me to a code of stepper motor with switches
I didn't find such a code

You need to realize that controlling a motor and reading some switches are
two separate problems - get each sussed first, then putting them together will
be obvious. Its not hard to look at examples of sensing and debouncing button
presses, reading analog potentiometer, and so forth.

You already have code to drive the motor? Post it, someone might suggest modifications
for one of more of your 4 desired behaviours. Don't post it, noone can suggest modifications, or guess which pins are used to drive the motor, etc etc.

Can anyone refer me to a code of stepper motor with switches
I didn't find such a code

I get "About 438,000 results (0.37 seconds) "

ok I got up here
Two functions work correctly
Now how do I continue with buttons
This is my code

#include <Stepper.h>
const int buttonPin = 2;
const int ledPin = 13;
const int stepsPerRevolution = 300;

int buttonState = 0;

Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {

myStepper.setSpeed(30);

Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}

void loop() {

Serial.println(“clockwise”);
myStepper.step(stepsPerRevolution);
delay(10000);
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
}
else {

digitalWrite(ledPin, LOW);
}
}

you might do something like: digitalread ForwardButtonPin. if it is high, analogread PotPin and map the analogvalue to functional rpm speed of your motor, and set the stepper stepping. Repeat for ReverseButtonPin. This approach might look something like this:

byte forward = digitalRead(ForwardButton);
if (forward == HIGH)
{
 // read the analog in value:
  sensorValue = analogRead(PotPin);            
  // map it to the range of the motor speed:
  rpm = map(sensorValue, 0, 1023, 0, 255);  // change 255 to the top speed of your mootr
  
  myStepper.setSpeed(rpm); //set the rpm speed
  myStepper.step(stepsPerRevolution/100); //move a few steps forward
}
byte reverse = digitalRead(ReverseButton);
if (reverse == HIGH)
{
 // read the analog in value:
  sensorValue = analogRead(PotPin);            
  // map it to the range of the motor speed:
  rpm = map(sensorValue, 0, 1023, 0, 255);  // change 255 to the top speed of your motor
  // change the analog out value:
  myStepper.setSpeed(rpm); //set the rpm speed
  myStepper.step(-stepsPerRevolution/100); //move a few steps backward
}

i'll let you define the appropriate variables as you see fit