greetings. had quick question trying arduino car move. running code
and when plug battery pack it, wheels move in 1 direction. stranger thing 1 wheel powered, while 1 powered sporadically. code or wiring. have 2 stepper motors connected l298n dual h-bridge curious. thank help.
code: [select]
// turn on sensor begin finding location turn
// on servo motor determine position
// turn on stepper motors begin having car move
#include <servo.h>;
#include <stepper.h>;
const int pingpin = 12;
const int ledpin = 13;
servo myservo; //create servo object control servo
//int angle = 0; //variable store servo position
const int stepsperrevolution = 200; //change fit number of steps per revolution
int cm;
stepper mystepper(stepsperrevolution, 3, 4);
stepper mystepper2(stepsperrevolution, 5, 6);
void setup()
{
serial.begin(9600);
pinmode(ledpin, output);
myservo.attach(7);
mystepper.setspeed(40);
}
void loop()
{
//declare main loop of entire program
//turn on servo motor determine location
//servo myservo; //create servo object control servo
int angle = 0;
//myservo.attach(7);
//serial.begin(9600);
serial.println("senda");
(angle = 0; angle < 180; angle += 1);
{
myservo.write(angle);
delay(10);
}
(angle = 180; angle >= 1; angle -= 1)
{
myservo.write(angle);
delay(10);
}
serial.println("you have succeeded point");
serial.println("now on sensor");
int cm = ping(12);
serial.println(cm);
digitalwrite(13, high);
delay(cm * 10 ); //each centimeter adds 10 milliseconds delay
digitalwrite(ledpin, low);
delay( cm * 10);
//return cm;
// activate stepper motors move foward
// begin looping if else statements
if (cm <= 50) {
serial.println("counterclockwise");
mystepper.step(-stepsperrevolution);
mystepper2.step(-stepsperrevolution);
delay(3000);
}
else
{
serial.println("clockwise");
mystepper.step(stepsperrevolution);
mystepper2.step(stepsperrevolution);
delay(3000);
}
}
int ping(int pingpin)
{
long duration, cm;
pinmode(ledpin, output);
digitalwrite(ledpin, low);
delaymicroseconds(2);
digitalwrite(ledpin, high);
delaymicroseconds(5);
digitalwrite(ledpin, low);
pinmode(pingpin, input);
duration = pulsein(pingpin, high);
//convert time distance
cm = microsecondstocentimeters(duration);
return cm;
}
long microsecondstocentimeters(long microseconds)
{
return microseconds / 29 / 2;
}
and when plug battery pack it, wheels move in 1 direction. stranger thing 1 wheel powered, while 1 powered sporadically. code or wiring. have 2 stepper motors connected l298n dual h-bridge curious. thank help.
have @ stepper motor basics. l298 poor choice driving stepper motors.
post link datasheet steppers using.
what sort of battery using?
have separate power supplies arduino , motors?
...r
post link datasheet steppers using.
what sort of battery using?
have separate power supplies arduino , motors?
...r
Arduino Forum > Using Arduino > Motors, Mechanics, and Power (Moderator: fabioc84) > Confusion about wheel movement.
arduino
Comments
Post a Comment