when I use
#include <AFMotor.h>
it doesn't work
I used it from this videos description
I got the code from this
https://drive.google.com/drive/folders/1yrxMWt89B1cXgT3YPp83pRh4Lho36o2S
motor shield control
I am making a robot for my school project
Hi,
Please post YOUR code in code tags, not an external link.
Please attach a schematic of YOUR circuit, not the tutorial.
Most likely you haven't downloaded the library, but what do you mean by "it doesn't work" Is there an error when you compile? Or does the code not run as expected?
this code
#include <Servo.h>
#include <AFMotor.h>
Servo servo1;
AF_DCMotor M1(1);
AF_DCMotor M2(2);
AF_Stepper motor1(48, 2);
void setup() {
M1.setSpeed(150);
M2.setSpeed(150);
servo1.attach(10);
motor1.setSpeed(10);
}
void loop() {
servo();
//gearmotor();
//stepper();
}
void gearmotor() {
M1.run(FORWARD);
M2.run(FORWARD);
delay(2000);
M1.run(BACKWARD);
M2.run(BACKWARD);
delay(2000);
M1.run(RELEASE);
M2.run(RELEASE);
delay(500);
}
void servo() {
for (int a = 0; a <= 180; a++ ) {
servo1.write(a);
delay(20);
}
for (int b = 179; b > 0; b--) {
servo1.write(b);
delay(20);
}
}
void stepper() {
motor1.step(100, FORWARD, SINGLE);
motor1.step(100, BACKWARD, SINGLE);
motor1.step(100, FORWARD, DOUBLE);
motor1.step(100, BACKWARD, DOUBLE);
motor1.step(100, FORWARD, INTERLEAVE);
motor1.step(100, BACKWARD, INTERLEAVE);
motor1.step(100, FORWARD, MICROSTEP);
motor1.step(100, BACKWARD, MICROSTEP);
}
I asked you to post it in code tags. Please do so.
See also FAQ - Arduino Forum for general rules on forum behavior and etiquette.
Hello,
Welcome to the Arduino Forum.
This guide explains how to get the best out of this forum. Please read and follow the instructions below.
Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is frus…
#include <Servo.h>
#include <AFMotor.h>
Servo servo1;
AF_DCMotor M1(1);
AF_DCMotor M2(2);
AF_Stepper motor1(48, 2);
void setup() {
M1.setSpeed(150);
M2.setSpeed(150);
servo1.attach(10);
motor1.setSpeed(10);
}
void loop() {
servo();
//gearmotor();
//stepper();
}
void gearmotor() {
M1.run(FORWARD);
M2.run(FORWARD);
delay(2000);
M1.run(BACKWARD);
M2.run(BACKWARD);
delay(2000);
M1.run(RELEASE);
M2.run(RELEASE);
delay(500);
}
void servo() {
for (int a = 0; a <= 180; a++ ) {
servo1.write(a);
delay(20);
}
for (int b = 179; b > 0; b--) {
servo1.write(b);
delay(20);
}
}
void stepper() {
motor1.step(100, FORWARD, SINGLE);
motor1.step(100, BACKWARD, SINGLE);
motor1.step(100, FORWARD, DOUBLE);
motor1.step(100, BACKWARD, DOUBLE);
motor1.step(100, FORWARD, INTERLEAVE);
motor1.step(100, BACKWARD, INTERLEAVE);
motor1.step(100, FORWARD, MICROSTEP);
motor1.step(100, BACKWARD, MICROSTEP);
}
2 Likes
Awesome. Thank you.
outbackhut:
Please attach a schematic of YOUR circuit, not the tutorial.
Most likely you haven't downloaded the library, but what do you mean by "it doesn't work" Is there an error when you compile? Or does the code not run as expected?
Just waiting for these now.
KiCAD is great for schematics, Fritzing works at a pinch.
Both what? Please elaborate. If you have an error on compilation, please post in code tags
I looked at the drawings you posted, and the square 9V PP3 battery won’t do much for very long.
Suggest a real power supply, or battery pack to supply the required voltage & current.
1 Like
acodechess-legend_123:
I have an error
Than In that case post that error; use code tags again.
Did you install the AFMotor library?
1 Like
xfpd
October 10, 2024, 7:56pm
13
@acodechess-legend_123
Download the master ZIP file in your link in Post #1 .
IDE >> SKETCH >> INCLUDE LIBRARY >> ADD ZIP LIBRARY >> (find AFMotor ZIP file) >> OPEN
Try again to compile and run your program.
system
Closed
April 8, 2025, 7:56pm
14
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.