I am trying to add needle sweep to my car speedo and rev counter. I have used an arduino uno and managed to use the following code to get the needle to move. My problem is when i edit the code for 2 ouputs to control speedo and rev needles it does not work. Im not very experienced in writing code so im asking if anyone would be able to help me edit the code so i can add 2 needle sweeps and to only sweep back and forth once then stop till power is disconnected
/*
Stepper Motor Control - one revolution
This program drives a bipolar stepper motor.
The motor is attached to digital pins 3 - 6 of the Arduino.
The motor should revolve one revolution in one direction, then
one revolution in the other direction.
*/
#include
const int stepsPerRevolution = 420; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins3 through 6:
Stepper myStepper(stepsPerRevolution, 6, 5, 4,3);
void setup() {
// set the speed at 65 rpm:
myStepper.setSpeed(65);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}
Ok so iv done some code and it all works except motor one starts first and seems to move faster than motor 2 when i need them both to move at same time.
#include
int start = 0;
const int stepsPerRevolution = 420; // change this to fit the number of steps per revolution motor 1
const int stepsPerRevolution2 = 420;// change this to fit the number of steps per revolution motor 2
// initialize the stepper library on pins 1.2.3.4//5.6.7.8
Stepper myStepper(stepsPerRevolution, 4, 3, 2,1); //motor 1
Stepper myStepper2(stepsPerRevolution, 8, 7, 6,5); //motor 2
void setup() {
// set the speed at 65 rpm:
myStepper.setSpeed(65);
myStepper2.setSpeed(65);
pinMode(13, OUTPUT);
}
void swip()
{
//farward direction motor 1 & 2
myStepper.step(stepsPerRevolution);
delay(100);
myStepper2.step(stepsPerRevolution2);
delay(100);
//reverse direction motor 1 & 2
myStepper.step(-stepsPerRevolution);
delay(100) ;
myStepper2.step(-stepsPerRevolution2);
delay(100) ;
start++;
}
void loop() {
if(start==0)
swip();
digitalWrite(13, HIGH);
}
Aswinth Raj
PermalinkI can see many mistakes in your program including missing a header file. If you really want to understand how things work and how to write your program you can read the following two links
https://circuitdigest.com/tutorial/what-is-stepper-motor-and-how-it-works
https://circuitdigest.com/microcontroller-projects/arduino-stepper-motor-control-tutorial
Instead, if you just want things to work and get away with it you can try the following program
Make sure you have connected the first motor to pins 8,9,10 and 11 ... The 2nd motor to pins 2,3,4and5. I cannot guarantee this program to work without knowing what motor you are using and the circuit circuit diagram of your project
Hope this helps you in some way
- Log in or register to post comments
Joined August 16, 2016 1000Tuesday at 12:29 AM